コード例 #1
0
        /// <summary>
        ///     Creates a new runtime.
        /// </summary>
        /// <param name="attributes">The attributes of the runtime to be created.</param>
        /// <param name="version">The version of the runtime to be created.</param>
        /// <param name="threadServiceCallback">The thread service for the runtime. Can be null.</param>
        /// <returns>The runtime created.</returns>
        public static JavaScriptRuntime Create(JavaScriptRuntimeAttributes attributes, JavaScriptRuntimeVersion version, JavaScriptThreadServiceCallback threadServiceCallback)
        {
            JavaScriptRuntime handle;

            Native.ThrowIfError(Native.JsCreateRuntime(attributes, threadServiceCallback, out handle));
            return(handle);
        }
コード例 #2
0
        public string Init(JavaScriptRuntimeAttributes jsrt = JavaScriptRuntimeAttributes.None)
        {
            JavaScriptContext context;

            Native.ThrowIfError(Native.JsCreateRuntime(jsrt, null, out runtime));
            Native.ThrowIfError(Native.JsCreateContext(runtime, out context));
            ResetContext(context);

            // ES6 Promise callback
            JavaScriptPromiseContinuationCallback promiseContinuationCallback = delegate(JavaScriptValue task, IntPtr callbackState)
            {
                taskQueue.Enqueue(task);
            };

            if (Native.JsSetPromiseContinuationCallback(promiseContinuationCallback, IntPtr.Zero) != JavaScriptErrorCode.NoError)
            {
                return("failed to setup callback for ES6 Promise");
            }

            foreach (var one in AllowNameSpace)
            {
                Native.ThrowIfError(Native.JsProjectWinRTNamespace(one));
            }

            if (Native.JsStartDebugging() != JavaScriptErrorCode.NoError)
            {
                return("failed to start debugging.");
            }

            return("NoError");
        }
コード例 #3
0
        private JavaScriptRuntime CreateRuntime(JavaScriptRuntimeAttributes attributes)
        {
            JavaScriptRuntime runtime;

            try
            {
                // Create a runtime.
                JavaScriptErrorCode errorCode = Native.JsCreateRuntime(attributes, null, out runtime);

                if (errorCode != JavaScriptErrorCode.NoError)
                {
                    string errorMessage = string.Format("Failed to create javascript runtime with error [{0}]", errorCode);

                    System.Diagnostics.Debug.WriteLine(errorMessage);

                    throw new Exception(errorMessage);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("An exception occurred when creating the javascript runtime with error [{0}]", ex.Message);

                throw;
            }

            return(runtime);
        }
コード例 #4
0
        /// <summary>
        ///     TTD API -- may change in future versions:
        ///     Creates a new runtime in Debug Mode.
        /// </summary>
        /// <param name="attributes">The attributes of the runtime to be created.</param>
        /// <param name="infoUri">The uri where the recorded Time-Travel data should be loaded from.</param>
        /// <param name="enableDebugging">A flag to enable additional debugging operation support during replay.</param>
        /// <param name="openResourceStream">The <c>TTDOpenResourceStreamCallback</c> function for generating a JsTTDStreamHandle to read/write serialized data.</param>
        /// <param name="readBytesFromStream">The <c>JsTTDReadBytesFromStreamCallback</c> function for reading bytes from a JsTTDStreamHandle.</param>
        /// <param name="flushAndCloseStream">The <c>JsTTDFlushAndCloseStreamCallback</c> function for flushing and closing a JsTTDStreamHandle as needed.</param>
        /// <param name="threadService">The thread service for the runtime. Can be null.</param>
        /// <remarks>
        ///     <para>See <c>JsCreateRuntime</c> for additional information.</para>
        /// </remarks>
        /// <returns>
        ///     The runtime created.
        /// </returns>
        public static JavaScriptRuntime TTDCreateReplayRuntime(
            JavaScriptRuntimeAttributes attributes,
            string infoUri,
            UIntPtr infoUriCount,
            bool enableDebugging,
            TTDOpenResourceStreamCallback openResourceStream,
            JavaScriptTTDReadBytesFromStreamCallback readBytesFromStream,
            JavaScriptTTDFlushAndCloseStreamCallback flushAndCloseStream,
            JavaScriptThreadServiceCallback threadService
            )
        {
            JavaScriptRuntime runtime;

            Native.ThrowIfError(
                Native.JsTTDCreateReplayRuntime(
                    attributes,
                    infoUri,
                    infoUriCount,
                    enableDebugging,
                    openResourceStream,
                    readBytesFromStream,
                    flushAndCloseStream,
                    threadService,
                    out runtime
                    )
                );
            return(runtime);
        }
コード例 #5
0
        // Time Travel Debugging

        /// <summary>
        ///     TTD API -- may change in future versions:
        ///     Creates a new runtime in Record Mode.
        /// </summary>
        /// <param name="attributes">The attributes of the runtime to be created.</param>
        /// <param name="enableDebugging">A flag to enable debugging during record.</param>
        /// <param name="snapInterval">The interval to wait between snapshots (measured in millis).</param>
        /// <param name="snapHistoryLength">The amount of history to maintain before discarding -- measured in number of snapshots and controls how far back in time a trace can be reversed.</param>
        /// <param name="openResourceStream">The <c>TTDOpenResourceStreamCallback</c> function for generating a JsTTDStreamHandle to read/write serialized data.</param>
        /// <param name="writeBytesToStream">The <c>JsTTDWriteBytesToStreamCallback</c> function for writing bytes to a JsTTDStreamHandle.</param>
        /// <param name="flushAndCloseStream">The <c>JsTTDFlushAndCloseStreamCallback</c> function for flushing and closing a JsTTDStreamHandle as needed.</param>
        /// <param name="threadService">The thread service for the runtime. Can be null.</param>
        /// <remarks>
        ///     <para>See <c>JsCreateRuntime</c> for additional information.</para>
        /// </remarks>
        /// <returns>
        ///     The runtime created.
        /// </returns>
        public static JavaScriptRuntime TTDCreateRecordRuntime(
            JavaScriptRuntimeAttributes attributes,
            bool enableDebugging,
            UIntPtr snapInterval,
            UIntPtr snapHistoryLength,
            TTDOpenResourceStreamCallback openResourceStream,
            JavaScriptTTDWriteBytesToStreamCallback writeBytesToStream,
            JavaScriptTTDFlushAndCloseStreamCallback flushAndCloseStream,
            JavaScriptThreadServiceCallback threadService
            )
        {
            JavaScriptRuntime runtime;

            Native.ThrowIfError(
                Native.JsTTDCreateRecordRuntime(
                    attributes,
                    enableDebugging,
                    snapInterval,
                    snapHistoryLength,
                    openResourceStream,
                    writeBytesToStream,
                    flushAndCloseStream,
                    threadService,
                    out runtime
                    )
                );
            return(runtime);
        }
コード例 #6
0
        /// <summary>
        /// Creates a new JavaScript Runtime.
        /// </summary>
        /// <param name="attributes"></param>
        /// <returns></returns>
        public BaristaRuntime CreateRuntime(JavaScriptRuntimeAttributes attributes = JavaScriptRuntimeAttributes.None)
        {
            var contextService = m_serviceProvider.GetRequiredService <IBaristaContextFactory>();

            var runtimeHandle = m_engine.JsCreateRuntime(attributes, null);
            var result        = m_runtimePool.GetOrAdd(runtimeHandle, () => {
                var rt = new BaristaRuntime(m_engine, contextService, runtimeHandle);
                //Do not wire up a runtime's BeforeCollect handler with the factory as this will
                //remove and dispose of the runtime on ANY garbage collect, which will eventually
                //crash the engine.

                //After a runtime handle is disposed, remove the handle from the pool.
                void afterDispose(object sender, EventArgs args)
                {
                    rt.AfterDispose -= afterDispose;
                    m_runtimePool.RemoveHandle(runtimeHandle);
                }

                rt.AfterDispose += afterDispose;
                return(rt);
            });

            if (result == null)
            {
                throw new InvalidOperationException("Unable to create or retrieve a new Barista Runtime.");
            }

            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Create a ChakraRuntime
        /// </summary>
        /// <param name="attributes">Runtime creation attributes</param>
        /// <param name="service">Parent serviceNode, default is null</param>
        /// <param name="syncHandle">Runtime thread sync hanlder, default is null</param>
        /// <param name="memoryLimit">Memory limit for the runtime in bytes, default is ulong.MaxValue</param>
        /// <returns></returns>
        public static ChakraRuntime Create(JavaScriptRuntimeAttributes attributes = JavaScriptRuntimeAttributes.None, IServiceNode service = null, EventWaitHandle syncHandle = null, ulong memoryLimit = ulong.MaxValue)
        {
            JavaScriptRuntime result = JavaScriptRuntime.Create(attributes, JavaScriptRuntimeVersion.VersionEdge);

            if (service == null)
            {
                service = ChakraCore.NET.ServiceNode.CreateRoot();
            }
            if (syncHandle == null)
            {
                syncHandle = new AutoResetEvent(true);
            }
            if (memoryLimit != ulong.MaxValue)
            {
                result.MemoryLimit = new UIntPtr(memoryLimit);
            }
            return(new ChakraRuntime(result, service, syncHandle));
        }
コード例 #8
0
 /// <summary>
 ///     Creates a new runtime.
 /// </summary>
 /// <param name="attributes">The attributes of the runtime to be created.</param>
 /// <param name="version">The version of the runtime to be created.</param>
 /// <returns>The runtime created.</returns>
 public static JavaScriptRuntime Create(JavaScriptRuntimeAttributes attributes, JavaScriptRuntimeVersion version)
 {
     return(Create(attributes, version, null));
 }
コード例 #9
0
 internal static extern JavaScriptErrorCode JsCreateRuntime(JavaScriptRuntimeAttributes attributes, JavaScriptThreadServiceCallback threadService, out JavaScriptRuntime runtime);
コード例 #10
0
 /// <summary>
 /// Creates a new runtime.
 /// </summary>
 /// <param name="attributes">The attributes of the runtime to be created.</param>
 /// <param name="version">The version of the runtime to be created.</param>
 /// <returns>The runtime created.</returns>
 public static JavaScriptRuntime Create(JavaScriptRuntimeAttributes attributes, JavaScriptRuntimeVersion version)
 {
     return Create(attributes, version, null);
 }
コード例 #11
0
 /// <summary>
 /// Creates a new runtime.
 /// </summary>
 /// <param name="attributes">The attributes of the runtime to be created.</param>
 /// <param name="version">The version of the runtime to be created.</param>
 /// <param name="threadServiceCallback">The thread service for the runtime. Can be null.</param>
 /// <returns>The runtime created.</returns>
 public static JavaScriptRuntime Create(JavaScriptRuntimeAttributes attributes, JavaScriptRuntimeVersion version, JavaScriptThreadServiceCallback threadServiceCallback)
 {
     JavaScriptRuntime handle;
     Native.ThrowIfError(Native.JsCreateRuntime(attributes, version, threadServiceCallback, out handle));
     return handle;
 }
コード例 #12
0
 /// <summary>
 ///     Creates a new runtime.
 /// </summary>
 /// <param name="attributes">The attributes of the runtime to be created.</param>
 /// <returns>The runtime created.</returns>
 public static JavaScriptRuntime Create(JavaScriptRuntimeAttributes attributes)
 {
     return(Create(attributes, null));
 }
コード例 #13
0
ファイル: Native.cs プロジェクト: psluja/ChakraCore.NET
 public static extern JavaScriptErrorCode JsRun(JavaScriptValue script, JavaScriptSourceContext sourceContext, JavaScriptValue sourceUrl, JavaScriptRuntimeAttributes parseAttributes, out JavaScriptValue result);
コード例 #14
0
 public JavaScriptEngine(JavaScriptRuntimeAttributes attributes)
 {
     runtime = this.CreateRuntime(attributes);
     context = this.CreateContext(runtime);
 }
コード例 #15
0
 internal static extern JavaScriptErrorCode JsCreateRuntime(JavaScriptRuntimeAttributes attributes, JavaScriptThreadServiceCallback threadService, out JavaScriptRuntime runtime);
コード例 #16
0
 /// <summary>
 ///     Creates a new runtime.
 /// </summary>
 /// <param name="attributes">The attributes of the runtime to be created.</param>
 /// <returns>The runtime created.</returns>
 public static JavaScriptRuntime Create(JavaScriptRuntimeAttributes attributes)
 {
     return Create(attributes, null);
 }
コード例 #17
0
 /// <summary>
 /// Creates a new runtime.
 /// </summary>
 /// <param name="attributes">The attributes of the runtime to be created.</param>
 /// <returns>The runtime created.</returns>
 public static JavaScriptRuntime Create(JavaScriptRuntimeAttributes attributes)
 {
     NativeMethods.JsCreateRuntime(attributes, null, out JavaScriptRuntime handle).ThrowIfError();
     return(handle);
 }