Ejemplo n.º 1
0
        // ReSharper disable ParameterHidesMember

        private object Execute(V8Script script, bool evaluate)
        {
            MiscHelpers.VerifyNonNullArgument(script, "script");
            VerifyNotDisposed();

            return(MarshalToHost(ScriptInvoke(() =>
            {
                if (inContinuationTimerScope || (ContinuationCallback == null))
                {
                    return proxy.Execute(script, evaluate);
                }

                var state = new Timer[] { null };
                using (state[0] = new Timer(unused => OnContinuationTimer(state[0]), null, Timeout.Infinite, Timeout.Infinite))
                {
                    inContinuationTimerScope = true;
                    try
                    {
                        state[0].Change(continuationInterval, Timeout.Infinite);
                        return proxy.Execute(script, evaluate);
                    }
                    finally
                    {
                        inContinuationTimerScope = false;
                    }
                }
            }), false));
        }
        /// <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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        // ReSharper disable ParameterHidesMember

        /// <summary>
        /// Evaluates a compiled script.
        /// </summary>
        /// <param name="script">The compiled script to evaluate.</param>
        /// <returns>The result value.</returns>
        /// <remarks>
        /// For information about the types of result values that script code can return, see
        /// <see cref="ScriptEngine.Evaluate(string, bool, string)"/>.
        /// </remarks>
        public object Evaluate(V8Script script)
        {
            MiscHelpers.VerifyNonNullArgument(script, "script");
            VerifyNotDisposed();

            return(MarshalToHost(ScriptInvoke(() =>
            {
                var stateObjects = new object[2];
                using (var timer = new Timer(OnContinuationTimer, stateObjects, Timeout.Infinite, Timeout.Infinite))
                {
                    stateObjects[0] = new WeakReference(this);
                    stateObjects[1] = timer;
                    timer.Change(continuationInterval, Timeout.Infinite);
                    return proxy.Execute(script);
                }
            }), false));
        }
Ejemplo n.º 5
0
 public abstract object Execute(V8Script script, bool evaluate);
 /// <summary>
 /// Executes a compiled script.
 /// </summary>
 /// <param name="script">The compiled script to execute.</param>
 /// <remarks>
 /// This method is similar to <see cref="Evaluate(V8Script)"/> with the exception that it
 /// does not marshal a result value to the host. It can provide a performance advantage
 /// when the result value is not needed.
 /// </remarks>
 public void Execute(V8Script script)
 {
     Execute(script, false);
 }
        // ReSharper disable ParameterHidesMember

        /// <summary>
        /// Evaluates a compiled script.
        /// </summary>
        /// <param name="script">The compiled script to evaluate.</param>
        /// <returns>The result value.</returns>
        /// <remarks>
        /// For information about the types of result values that script code can return, see
        /// <see cref="ScriptEngine.Evaluate(string, bool, string)"/>.
        /// </remarks>
        public object Evaluate(V8Script script)
        {
            return(Execute(script, true));
        }
Ejemplo n.º 8
0
 public abstract object Execute(V8Script script);
Ejemplo n.º 9
0
 public abstract object Execute(V8Script script, bool evaluate);
 public CachedV8Script(V8Script script, int expirationSeconds = ManagerSettings.DefaultScriptTimeoutMilliSeconds)
 {
     CreatedOn = DateTime.UtcNow;
     ExpiresOn = CreatedOn.AddSeconds(expirationSeconds);
     Script = script;
 }
 public abstract object Execute(V8Script script);