Beispiel #1
0
        /// <summary>
        /// Creates a compiled script with an associated document name, consuming previously generated cache data.
        /// </summary>
        /// <param name="documentName">A document name for the compiled script. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
        /// <param name="code">The script code to compile.</param>
        /// <param name="cacheKind">The kind of cache data to be consumed.</param>
        /// <param name="cacheBytes">Cache data for accelerated compilation.</param>
        /// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
        /// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
        /// <remarks>
        /// To be accepted, the cache data must have been generated for identical script code by
        /// the same V8 build. V8 runtimes with debugging enabled cannot consume cache data.
        /// </remarks>
        /// <seealso cref="Compile(string, string, V8CacheKind, out byte[])"/>
        public V8Script Compile(string documentName, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
        {
            VerifyNotDisposed();
            var uniqueName = name + ":" + documentNameManager.GetUniqueName(documentName, "Script Document");

            return(proxy.Compile(uniqueName, FormatCode ? MiscHelpers.FormatCode(code) : code, cacheKind, cacheBytes, out cacheAccepted));
        }
        /// <summary>
        /// Creates a compiled script with an associated document name, consuming previously generated cache data.
        /// </summary>
        /// <param name="documentName">A document name for the compiled script. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
        /// <param name="code">The script code to compile.</param>
        /// <param name="cacheKind">The kind of cache data to be consumed.</param>
        /// <param name="cacheBytes">Cache data for accelerated compilation.</param>
        /// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
        /// <returns>A compiled script that can be executed multiple times without recompilation.</returns>
        /// <remarks>
        /// To be accepted, the cache data must have been generated for identical script code by
        /// the same V8 build. V8 script engines with debugging enabled cannot consume cache data.
        /// </remarks>
        /// <seealso cref="Compile(string, string, V8CacheKind, out byte[])"/>
        public V8Script Compile(string documentName, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
        {
            VerifyNotDisposed();

            V8Script tempScript = null;

            cacheAccepted = ScriptInvoke(() =>
            {
                bool tempCacheAccepted;
                var uniqueName = documentNameManager.GetUniqueName(documentName, "Script Document");
                tempScript     = proxy.Compile(uniqueName, FormatCode ? MiscHelpers.FormatCode(code) : code, cacheKind, cacheBytes, out tempCacheAccepted);
                return(tempCacheAccepted);
            });

            return(tempScript);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a compiled script with the specified document information, generating cache data for accelerated recompilation.
        /// </summary>
        /// <param name="documentInfo">A structure containing information about the script document.</param>
        /// <param name="code">The script code to compile.</param>
        /// <param name="cacheKind">The kind of cache data to be generated.</param>
        /// <param name="cacheBytes">Cache data for accelerated recompilation.</param>
        /// <returns>A compiled script that can be executed multiple times without recompilation.</returns>
        /// <remarks>
        /// The generated cache data can be stored externally and is usable in other V8 script
        /// engines and application processes. V8 script engines with debugging enabled cannot
        /// generate cache data.
        /// </remarks>
        /// <seealso cref="Compile(DocumentInfo, string, V8CacheKind, byte[], out bool)"/>
        public V8Script Compile(DocumentInfo documentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes)
        {
            VerifyNotDisposed();

            V8Script tempScript = null;

            cacheBytes = ScriptInvoke(() =>
            {
                byte[] tempCacheBytes;
                documentInfo.UniqueName = documentNameManager.GetUniqueName(documentInfo.Name, DocumentInfo.DefaultName);
                tempScript = proxy.Compile(documentInfo, FormatCode ? MiscHelpers.FormatCode(code) : code, cacheKind, out tempCacheBytes);
                return(tempCacheBytes);
            });

            return(tempScript);
        }
 /// <summary>
 /// Creates a compiled script, consuming previously generated cache data.
 /// </summary>
 /// <param name="code">The script code to compile.</param>
 /// <param name="cacheKind">The kind of cache data to be consumed.</param>
 /// <param name="cacheBytes">Cache data for accelerated compilation.</param>
 /// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
 /// <returns>A compiled script that can be executed multiple times without recompilation.</returns>
 /// <remarks>
 /// To be accepted, the cache data must have been generated for identical script code by
 /// the same V8 build. V8 script engines with debugging enabled cannot consume cache data.
 /// </remarks>
 /// <seealso cref="Compile(string, V8CacheKind, out byte[])"/>
 public V8Script Compile(string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
 {
     return(Compile(null, code, cacheKind, cacheBytes, out cacheAccepted));
 }
 /// <summary>
 /// Creates a compiled script, generating cache data for accelerated recompilation.
 /// </summary>
 /// <param name="code">The script code to compile.</param>
 /// <param name="cacheKind">The kind of cache data to be generated.</param>
 /// <param name="cacheBytes">Cache data for accelerated recompilation.</param>
 /// <returns>A compiled script that can be executed multiple times without recompilation.</returns>
 /// <remarks>
 /// The generated cache data can be stored externally and is usable in other V8 script
 /// engines and application processes. V8 script engines with debugging enabled cannot
 /// generate cache data.
 /// </remarks>
 /// <seealso cref="Compile(string, V8CacheKind, byte[], out bool)"/>
 public V8Script Compile(string code, V8CacheKind cacheKind, out byte[] cacheBytes)
 {
     return(Compile(null, code, cacheKind, out cacheBytes));
 }
Beispiel #6
0
 public abstract V8Script Compile(UniqueDocumentInfo documentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted);
Beispiel #7
0
 public abstract V8Script Compile(UniqueDocumentInfo documentInfo, string code, V8CacheKind cacheKind, out byte[] cacheBytes);
Beispiel #8
0
 /// <summary>
 /// Creates a compiled script with the specified document information, consuming previously generated cache data.
 /// </summary>
 /// <param name="documentInfo">A structure containing information about the script document.</param>
 /// <param name="code">The script code to compile.</param>
 /// <param name="cacheKind">The kind of cache data to be consumed.</param>
 /// <param name="cacheBytes">Cache data for accelerated compilation.</param>
 /// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
 /// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
 /// <remarks>
 /// To be accepted, the cache data must have been generated for identical script code by
 /// the same V8 build. V8 runtimes with debugging enabled cannot consume cache data.
 /// </remarks>
 /// <seealso cref="Compile(DocumentInfo, string, V8CacheKind, out byte[])"/>
 public V8Script Compile(DocumentInfo documentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
 {
     VerifyNotDisposed();
     documentInfo.UniqueName = name + ":" + documentNameManager.GetUniqueName(documentInfo.Name, DocumentInfo.DefaultName);
     return(proxy.Compile(documentInfo, FormatCode ? MiscHelpers.FormatCode(code) : code, cacheKind, cacheBytes, out cacheAccepted));
 }
Beispiel #9
0
 /// <summary>
 /// Creates a compiled script with an associated document name, consuming previously generated cache data.
 /// </summary>
 /// <param name="documentName">A document name for the compiled script. Currently this name is used only as a label in presentation contexts such as debugger user interfaces.</param>
 /// <param name="code">The script code to compile.</param>
 /// <param name="cacheKind">The kind of cache data to be consumed.</param>
 /// <param name="cacheBytes">Cache data for accelerated compilation.</param>
 /// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
 /// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
 /// <remarks>
 /// To be accepted, the cache data must have been generated for identical script code by
 /// the same V8 build. V8 runtimes with debugging enabled cannot consume cache data.
 /// </remarks>
 /// <seealso cref="Compile(string, string, V8CacheKind, out byte[])"/>
 public V8Script Compile(string documentName, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
 {
     return(Compile(new DocumentInfo(documentName), code, cacheKind, cacheBytes, out cacheAccepted));
 }
Beispiel #10
0
 public abstract V8Script Compile(string documentName, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted);
Beispiel #11
0
 public abstract V8Script Compile(string documentName, string code, V8CacheKind cacheKind, out byte[] cacheBytes);
        private V8Script CompileInternal(UniqueDocumentInfo documentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
        {
            if (FormatCode)
            {
                code = MiscHelpers.FormatCode(code);
            }

            if (documentInfo.Category == ModuleCategory.CommonJS)
            {
                code = CommonJSManager.Module.GetAugmentedCode(code);
            }

            return(proxy.Compile(documentInfo, code, cacheKind, cacheBytes, out cacheAccepted));
        }
        /// <summary>
        /// Loads and compiles a document with the specified category and context callback, consuming previously generated cache data.
        /// </summary>
        /// <param name="specifier">A string specifying the document to be loaded and compiled.</param>
        /// <param name="category">An optional category for the requested document.</param>
        /// <param name="contextCallback">An optional context callback for the requested document.</param>
        /// <param name="cacheKind">The kind of cache data to be consumed.</param>
        /// <param name="cacheBytes">Cache data for accelerated compilation.</param>
        /// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
        /// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
        /// <remarks>
        /// To be accepted, the cache data must have been generated for identical script code by
        /// the same V8 build.
        /// </remarks>
        public V8Script CompileDocument(string specifier, DocumentCategory category, DocumentContextCallback contextCallback, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
        {
            MiscHelpers.VerifyNonBlankArgument(specifier, "specifier", "Invalid document specifier");
            var document = DocumentSettings.LoadDocument(null, specifier, category, contextCallback);

            return(Compile(document.Info, document.GetTextContents(), cacheKind, cacheBytes, out cacheAccepted));
        }
 /// <summary>
 /// Loads and compiles a document with the specified category, consuming previously generated cache data.
 /// </summary>
 /// <param name="specifier">A string specifying the document to be loaded and compiled.</param>
 /// <param name="category">An optional category for the requested document.</param>
 /// <param name="cacheKind">The kind of cache data to be consumed.</param>
 /// <param name="cacheBytes">Cache data for accelerated compilation.</param>
 /// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
 /// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
 /// <remarks>
 /// To be accepted, the cache data must have been generated for identical script code by
 /// the same V8 build.
 /// </remarks>
 public V8Script CompileDocument(string specifier, DocumentCategory category, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
 {
     return(CompileDocument(specifier, category, null, cacheKind, cacheBytes, out cacheAccepted));
 }
 /// <summary>
 /// Loads and compiles a script document, generating cache data for accelerated recompilation.
 /// </summary>
 /// <param name="specifier">A string specifying the document to be loaded and compiled.</param>
 /// <param name="cacheKind">The kind of cache data to be generated.</param>
 /// <param name="cacheBytes">Cache data for accelerated recompilation.</param>
 /// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
 /// <remarks>
 /// The generated cache data can be stored externally and is usable in other V8 runtimes
 /// and application processes.
 /// </remarks>
 public V8Script CompileDocument(string specifier, V8CacheKind cacheKind, out byte[] cacheBytes)
 {
     return(CompileDocument(specifier, null, cacheKind, out cacheBytes));
 }
 /// <summary>
 /// Creates a compiled script with the specified document meta-information, consuming previously generated cache data.
 /// </summary>
 /// <param name="documentInfo">A structure containing meta-information for the script document.</param>
 /// <param name="code">The script code to compile.</param>
 /// <param name="cacheKind">The kind of cache data to be consumed.</param>
 /// <param name="cacheBytes">Cache data for accelerated compilation.</param>
 /// <param name="cacheAccepted"><c>True</c> if <paramref name="cacheBytes"/> was accepted, <c>false</c> otherwise.</param>
 /// <returns>A compiled script that can be executed by multiple V8 script engine instances.</returns>
 /// <remarks>
 /// To be accepted, the cache data must have been generated for identical script code by
 /// the same V8 build.
 /// </remarks>
 /// <seealso cref="Compile(DocumentInfo, string, V8CacheKind, out byte[])"/>
 public V8Script Compile(DocumentInfo documentInfo, string code, V8CacheKind cacheKind, byte[] cacheBytes, out bool cacheAccepted)
 {
     VerifyNotDisposed();
     return(CompileInternal(documentInfo.MakeUnique(documentNameManager), code, cacheKind, cacheBytes, out cacheAccepted));
 }