Exemple #1
0
        /// <summary>
        /// Creates a new runtime
        /// </summary>
        /// <param name="attributes">The attributes 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 JsRuntime Create(JsRuntimeAttributes attributes, JsThreadServiceCallback threadServiceCallback)
        {
            JsRuntime handle;

            JsErrorHelpers.ThrowIfError(NativeMethods.JsCreateRuntime(attributes, threadServiceCallback, out handle));

            return(handle);
        }
        /// <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 IeJsRuntime Create(JsRuntimeAttributes attributes, JsRuntimeVersion version, JsThreadServiceCallback threadServiceCallback)
        {
            IeJsRuntime handle;

            IeJsErrorHelpers.ThrowIfError(IeNativeMethods.JsCreateRuntime(attributes, version, threadServiceCallback, out handle));

            return(handle);
        }
Exemple #3
0
        /// <summary>
        /// Constructs an instance of adapter for the ChakraCore JS engine
        /// </summary>
        /// <param name="settings">Settings of the ChakraCore JS engine</param>
        public ChakraCoreJsEngine(ChakraCoreSettings settings)
        {
            ChakraCoreSettings chakraCoreSettings = settings ?? new ChakraCoreSettings();

            JsRuntimeAttributes attributes = JsRuntimeAttributes.None;

            if (chakraCoreSettings.DisableBackgroundWork)
            {
                attributes |= JsRuntimeAttributes.DisableBackgroundWork;
            }
            if (chakraCoreSettings.DisableNativeCodeGeneration)
            {
                attributes |= JsRuntimeAttributes.DisableNativeCodeGeneration;
            }
            if (chakraCoreSettings.DisableEval)
            {
                attributes |= JsRuntimeAttributes.DisableEval;
            }
            if (chakraCoreSettings.EnableExperimentalFeatures)
            {
                attributes |= JsRuntimeAttributes.EnableExperimentalFeatures;
            }

            _externalObjectFinalizeCallback = ExternalObjectFinalizeCallback;

            _dispatcher.Invoke(() =>
            {
                try
                {
                    _jsRuntime = JsRuntime.Create(attributes, null);
                    _jsContext = _jsRuntime.CreateContext();
                    _jsContext.AddRef();
                }
                catch (Exception e)
                {
                    throw new JsEngineLoadException(
                        string.Format(CoreStrings.Runtime_JsEngineNotLoaded,
                                      EngineName, e.Message), EngineName, EngineVersion, e);
                }
            });
        }
Exemple #4
0
 internal static extern JsErrorCode JsCreateRuntime(JsRuntimeAttributes attributes,
                                                    JsThreadServiceCallback threadService, out JsRuntime runtime);
 /// <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 JsRuntime Create(JsRuntimeAttributes attributes, JsRuntimeVersion version)
 {
     return Create(attributes, version, null);
 }
        /// <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 JsRuntime Create(JsRuntimeAttributes attributes, JsRuntimeVersion version, JsThreadServiceCallback threadServiceCallback)
        {
            JsRuntime handle;
            JsErrorHelpers.ThrowIfError(NativeMethods.JsCreateRuntime(attributes, threadServiceCallback, out handle));

            return handle;
        }
 /// <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 IeJsRuntime Create(JsRuntimeAttributes attributes, JsRuntimeVersion version)
 {
     return(Create(attributes, version, null));
 }
		internal static extern JsErrorCode JsCreateRuntime(JsRuntimeAttributes attributes, JsThreadServiceCallback threadService, out EdgeJsRuntime runtime);
Exemple #9
0
        /// <summary>
        /// Constructs an instance of adapter for the ChakraCore JS engine
        /// </summary>
        /// <param name="settings">Settings of the ChakraCore JS engine</param>
        public ChakraCoreJsEngine(ChakraCoreSettings settings)
        {
#if NETFULL
            Initialize();
#endif
            ChakraCoreSettings chakraCoreSettings = settings ?? new ChakraCoreSettings();

            JsRuntimeAttributes attributes = JsRuntimeAttributes.AllowScriptInterrupt;
            if (chakraCoreSettings.DisableBackgroundWork)
            {
                attributes |= JsRuntimeAttributes.DisableBackgroundWork;
            }
            if (chakraCoreSettings.DisableEval)
            {
                attributes |= JsRuntimeAttributes.DisableEval;
            }
            if (chakraCoreSettings.DisableExecutablePageAllocation)
            {
                attributes |= JsRuntimeAttributes.DisableExecutablePageAllocation;
            }
            if (chakraCoreSettings.DisableFatalOnOOM)
            {
                attributes |= JsRuntimeAttributes.DisableFatalOnOOM;
            }
            if (chakraCoreSettings.DisableNativeCodeGeneration)
            {
                attributes |= JsRuntimeAttributes.DisableNativeCodeGeneration;
            }
            if (chakraCoreSettings.EnableExperimentalFeatures)
            {
                attributes |= JsRuntimeAttributes.EnableExperimentalFeatures;
            }

#if NETSTANDARD1_3
            _dispatcher = new ScriptDispatcher();
#else
            _dispatcher = new ScriptDispatcher(chakraCoreSettings.MaxStackSize);
#endif
            _promiseContinuationCallback = PromiseContinuationCallback;

            try
            {
                _dispatcher.Invoke(() =>
                {
                    _jsRuntime             = JsRuntime.Create(attributes, null);
                    _jsRuntime.MemoryLimit = settings.MemoryLimit;

                    _jsContext = _jsRuntime.CreateContext();
                    if (_jsContext.IsValid)
                    {
                        _jsContext.AddRef();
                    }
                });
            }
            catch (DllNotFoundException e)
            {
                throw WrapDllNotFoundException(e);
            }
            catch (Exception e)
            {
                throw CoreErrorHelpers.WrapEngineLoadException(e, EngineName, EngineVersion, true);
            }
            finally
            {
                if (!_jsContext.IsValid)
                {
                    Dispose();
                }
            }
        }
Exemple #10
0
 /// <summary>
 ///     Creates a new runtime.
 /// </summary>
 /// <param name="attributes">The attributes 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 JsRuntime Create(JsRuntimeAttributes attributes, JsThreadServiceCallback threadServiceCallback)
 {
     Native.ThrowIfError(Native.JsCreateRuntime(attributes, threadServiceCallback, out JsRuntime handle));
     return(handle);
 }
Exemple #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>
 /// <returns>The runtime created.</returns>
 public static JsRuntime Create(JsRuntimeAttributes attributes)
 {
     return(Create(attributes, null));
 }
 /// <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 EdgeJsRuntime Create(JsRuntimeAttributes attributes)
 {
     return Create(attributes, null);
 }