public void Init(IRuntimeDebuggingService debuggingService)
 {
     this.debuggingService            = debuggingService;
     debuggingService.OnAsyncBreak   += DebuggingService_OnAsyncBreak;
     debuggingService.OnBreakPoint   += DebuggingService_OnBreakPoint;
     debuggingService.OnDebugEvent   += DebuggingService_OnDebugEvent;
     debuggingService.OnEngineReady  += DebuggingService_OnEngineReady;
     debuggingService.OnException    += DebuggingService_OnException;
     debuggingService.OnScriptLoad   += DebuggingService_OnScriptLoad;
     debuggingService.OnStepComplete += DebuggingService_OnStepComplete;
     debuggingService.StartDebug();
 }
Exemple #2
0
 public void Init(IRuntimeDebuggingService debuggingService)
 {
     debuggingService.OnException += (sender, exception) =>
     {
         Logger.LogCritical(
             $"Javascript side raise an uncaught exception.\n${JsonConvert.SerializeObject(exception)}\n");
     };
     debuggingService.OnAsyncBreak   += (sender, point) => { };
     debuggingService.OnBreakPoint   += (sender, point) => { };
     debuggingService.OnDebugEvent   += (sender, arguments) => { };
     debuggingService.OnEngineReady  += (sender, args) => { };
     debuggingService.OnScriptLoad   += (sender, code) => { };
     debuggingService.OnStepComplete += (sender, point) => { };
     debuggingService.StartDebug();
 }
Exemple #3
0
        private JavaScriptModuleRecord createModule(JavaScriptModuleRecord?parent, string name, Func <string, string> loadModuleCallback)
        {
            bool isCreateFromSourceCode = string.IsNullOrEmpty(name);

            //if module is cached, return cached value
            if (!isCreateFromSourceCode && moduleCache.ContainsKey(name))
            {
                return(moduleCache[name]);
            }

            IRuntimeDebuggingService debugService = CurrentNode.GetService <IRuntimeDebuggingService>();
            var result = JavaScriptModuleRecord.Create(parent, name);

            #region init moudle callback delegates
            FetchImportedModuleDelegate fetchImported = (JavaScriptModuleRecord reference, JavaScriptValue scriptName, out JavaScriptModuleRecord output) =>
            {
                output = createModule(reference, scriptName.ToString(), loadModuleCallback);

                return(JavaScriptErrorCode.NoError);
            };

            FetchImportedModuleFromScriptDelegate fetchImportedFromScript = (JavaScriptSourceContext sourceContext, JavaScriptValue scriptName, out JavaScriptModuleRecord output) =>
            {
                output = createModule(null, scriptName.ToString(), loadModuleCallback);
                return(JavaScriptErrorCode.NoError);
            };

            NotifyModuleReadyCallbackDelegate notifyReady = (module, jsvalue) =>
            {
                moduleReadyEvent.Set();
                if (jsvalue.IsValid)
                {
                    var valueService = CurrentNode.GetService <IJSValueService>();
                    valueService.ThrowIfErrorValue(jsvalue);
                }
                debugService.NotifyScriptReady();
                return(JavaScriptErrorCode.NoError);
            };
            #endregion


            Action parseModule = () =>
            {
                string script = loadModuleCallback(name);
                JavaScriptModuleRecord.ParseScript(result, script, debugService.GetScriptContext(name, script));
                //debugService.AddScriptSource(name, script);
                System.Diagnostics.Debug.WriteLine($"module {name} Parsed");
            };

            JavaScriptModuleRecord.SetFetchModuleCallback(result, fetchImported);
            JavaScriptModuleRecord.SetFetchModuleScriptCallback(result, fetchImportedFromScript);
            JavaScriptModuleRecord.SetNotifyReady(result, notifyReady);
            if (!string.IsNullOrEmpty(name))
            {
                JavaScriptModuleRecord.SetHostUrl(result, name);
            }
            else
            {
                JavaScriptModuleRecord.SetHostUrl(result, "<Generated_ModuleRoot>");
            }


            moduleParseQueue.Add(new moduleItem(
                                     parseModule,
                                     fetchImported,
                                     fetchImportedFromScript,
                                     notifyReady));

            if (!isCreateFromSourceCode)
            {
                moduleCache.Add(name, result);//cache the module if it's not directly from RunModule function
            }


            System.Diagnostics.Debug.WriteLine($"{name} module created");
            return(result);
        }