Example #1
0
        internal void Init(bool enableDebug)
        {
            isDebug       = enableDebug;
            contextSwitch = new ContextSwitchService(jsContext, syncHandle);
            ServiceNode.PushService <IContextSwitchService>(contextSwitch);
            ServiceNode.PushService <IGCSyncService>(new GCSyncService());
            Enter();
            promiseContinuationCallback = delegate(JavaScriptValue task, IntPtr callbackState)
            {
                promiseTaskQueue.Add(task);
            };

            if (Native.JsSetPromiseContinuationCallback(promiseContinuationCallback, IntPtr.Zero) != JavaScriptErrorCode.NoError)
            {
                throw new InvalidOperationException("failed to setup callback for ES6 Promise");
            }
            StartPromiseTaskLoop(shutdownCTS.Token);



            JSGlobalObject = JavaScriptValue.GlobalObject;
            GlobalObject   = new JSValue(ServiceNode, JSGlobalObject);
            Leave();


            contextService = new ContextService(shutdownCTS);
            ServiceNode.PushService <IContextService>(contextService);
            timerService = GlobalObject.InitTimer();
        }
Example #2
0
        public JSValue(IServiceNode parentNode, JavaScriptValue value) : base(parentNode, "JSValue")
        {
            ReferenceValue = value;
            ServiceNode.PushService <ICallContextService>(new CallContextService(value));
            //inject service
            Binding = new JSValueBinding(ServiceNode, value);//binding will create a branch of current service node to persistent hold all delegates created by binding function

            //add my own one time delegate handler for method/function call
            ServiceNode.PushService <INativeFunctionHolderService>(new NativeFunctionHolderService(true));
        }
 private ChakraRuntime(JavaScriptRuntime runtime, IServiceNode service, EventWaitHandle syncHandler) : base(service, "ChakraRuntime")
 {
     this.runtime   = runtime;
     SyncHandler    = syncHandler;
     runtimeService = new RuntimeService(runtime);
     //inject service
     ServiceNode.PushService(runtimeService);
     ServiceNode.PushService <IJSValueConverterService>(converter);
     ServiceNode.PushService <IJSValueService>(new JSValueService());
     ServiceNode.InjectShareMemoryObjects();
     ServiceNode.InjecTimerService();
     converter.RegisterTask();
 }
Example #4
0
 /// <summary>
 /// Parses a script and returns a function representing the script.
 /// </summary>
 /// <remarks>The script will be wrapped into a javascript function, then return to the caller. Useful for support moduling in javascript
 /// </remarks>
 /// <param name="script">Script text</param>
 /// <returns>A javascript function in <see cref="JavaScriptValue"/></returns>
 public JavaScriptValue ParseScript(string script)
 {
     return(ServiceNode.GetService <IContextService>().ParseScript(script));
 }
Example #5
0
 /// <summary>
 /// Execute a ES6 module
 /// </summary>
 /// <param name="script">script content</param>
 /// <param name="loadModuleCallback">callback to load imported script content</param>
 public void RunModule(string script, Func <string, string> loadModuleCallback)
 {
     ServiceNode.GetService <IContextService>().RunModule(script, loadModuleCallback);
 }
Example #6
0
 /// <summary>
 /// Execute a javascript and returns the script result in string
 /// </summary>
 /// <param name="script">Script text</param>
 /// <returns>Script running result</returns>
 public string RunScript(string script)
 {
     return(ServiceNode.GetService <IContextService>().RunScript(script));
 }
Example #7
0
 /// <summary>
 /// Release the context from current thread, this method should be called before you call <see cref="Enter"/> on another thread
 /// </summary>
 public void Leave()
 {
     ServiceNode.GetService <IContextSwitchService>().Leave();
 }
Example #8
0
 /// <summary>
 /// Try switch context to current thread
 /// </summary>
 /// <returns>true if release is required, false if context already running at current thread(no release call required)</returns>
 public bool Enter()
 {
     return(ServiceNode.GetService <IContextSwitchService>().Enter());
 }
Example #9
0
 public JSValueBinding(IServiceNode parentNode, JavaScriptValue value) : base(parentNode, "JSValueBinding")
 {
     jsValue = value;
     ServiceNode.PushService <INativeFunctionHolderService>(new NativeFunctionHolderService(false));
 }
Example #10
0
 /// <summary>
 /// Execute a ES6 module
 /// </summary>
 /// <param name="script">script content</param>
 /// <param name="loadModuleCallback">callback to load imported script content</param>
 public void RunModule(string script, LoadModuleDelegate loadModuleCallback)
 {
     ServiceNode.GetService <IContextService>().RunModule(script, loadModuleCallback);
 }