/// <summary> /// Register custom variables and functions as the object 'reko' in the global context /// </summary> public void RegisterGlobals() { context.Acquire(() => { var global = context.GetGlobal(); var rekoObj = CefV8Value.CreateObject(); var dumpBytesFn = new Proto_DumpBytes(decompiler); var procListRenderer = new ProcedureListRenderer(decompiler); global.SetValue("reko", rekoObj); RegisterAsyncFunction(rekoObj, "OpenFile", new OpenFileHandler(promiseFactory, pendingPromises)); RegisterAsyncFunction(rekoObj, "Proto_DisassembleRandomBytes", new Func <string, string, string>(Proto_DisassembleRandomBytes.Execute)); RegisterAsyncFunction(rekoObj, "Proto_GeneratePng", new Func <int, byte[]>(Proto_GeneratePng.Execute)); RegisterAsyncFunction(rekoObj, "LoadFile", new Func <string, string?, Address?, bool>(decompiler.Load)); RegisterAsyncFunction(rekoObj, "Scan", new Action(decompiler.ScanPrograms)); RegisterAsyncFunction(rekoObj, "DumpBytes", new Func <string, string, long, string>(dumpBytesFn.Execute)); RegisterAsyncFunction(rekoObj, "GetProcedureList", new Func <string, string>(procListRenderer.Render)); RegisterFunction(rekoObj, "TestListener", new Action(() => { var listener = services.RequireService <DecompilerEventListener>(); listener.Info(new NullCodeLocation("web"), "Hello World"); })); RegisterFunction(rekoObj, "RegisterEventListener", new Proto_RegisterEventListener(eventListeners)); RegisterFunction(rekoObj, "RenderProjectView", new Func <string>(() => ProjectViewRenderer.RenderToHtml(decompiler))); RegisterFunction(rekoObj, "RenderProcedure", new Func <CefV8Value, CefV8Value>((CefV8Value key) => { var iKey = key.GetIntValue(); var proc = new ProcedureViewModel(iKey); var obj = CefV8Value.CreateObject(); obj.SetValue("name", CefV8Value.CreateString(proc.Name)); obj.SetValue("body", CefV8Value.CreateString(proc.Body)); return(obj); })); }); }
protected override void Execute() { ctx.Acquire(() => { //$TODO: smx-smx call back to the JS side, passing a blob of html }); }
protected override void Execute() { ctx.Acquire(() => { eventListeners.Invoke(sinkName, new CefV8Value[] { CefV8Value.CreateString(message) }); }); }
protected override void Execute() { ctx.Acquire(() => { // We just got called from the JS runtime task runner. We are in a JS context, // so it's safe to create JS values. var result = ValueConverter.ConvertToJsValue(this.result); // Now we can call the resolve JS function with our converted value. this.toRun.ExecuteFunction(null, new CefV8Value[] { result }); }); }