From b1d9a29cf7913d1c1efdd3b29337b35954d8d022 Mon Sep 17 00:00:00 2001 From: Marcel Laverdet Date: Tue, 4 Jun 2024 15:55:05 -0500 Subject: [PATCH] Fix inspector sessions --- inspector-example.js | 8 +++++++- src/isolate/class_handle.h | 9 +++++---- src/isolate/generic/callbacks.h | 12 ++++++------ src/isolate/generic/extract_params.h | 4 ++-- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/inspector-example.js b/inspector-example.js index 96e48680..e5d98a43 100644 --- a/inspector-example.js +++ b/inspector-example.js @@ -11,7 +11,11 @@ let ivm = require('./isolated-vm'); let isolate = new ivm.Isolate({ inspector: true }); (async function() { let context = await isolate.createContext({ inspector: true }); - let script = await isolate.compileScript('for(;;)debugger;', { filename: 'example.js' }); + const inspector = isolate.createInspectorSession(); + inspector.dispatchProtocolMessage('{"id":1,"method":"Debugger.enable"}'); + await context.eval('/* break on script start */debugger;'); + inspector.dispose(); + let script = await isolate.compileScript('console.log("hello world")', { filename: 'example.js' }); await script.run(context); }()).catch(console.error); @@ -31,6 +35,7 @@ wss.on('connection', function(ws) { // Relay messages from frontend to backend ws.on('message', function(message) { + console.log('<', message.toString()) try { channel.dispatchProtocolMessage(String(message)); } catch (err) { @@ -41,6 +46,7 @@ wss.on('connection', function(ws) { // Relay messages from backend to frontend function send(message) { + console.log('>', message.toString()) try { ws.send(message); } catch (err) { diff --git a/src/isolate/class_handle.h b/src/isolate/class_handle.h index 3ffa7ee6..0b5efd2e 100644 --- a/src/isolate/class_handle.h +++ b/src/isolate/class_handle.h @@ -7,6 +7,7 @@ #include "generic/extract_params.h" #include "generic/handle_cast.h" #include "generic/read_option.h" +#include "v8-function-callback.h" #include #include @@ -67,7 +68,7 @@ class ClassHandle { template void Add(const char* name, detail::MemberFunctionHolder impl, Args... args) { v8::Local name_handle = v8_symbol(name); - proto->Set(name_handle, v8::FunctionTemplate::New(isolate, impl.callback, name_handle, sig, impl.length)); + proto->Set(name_handle, v8::FunctionTemplate::New(isolate, impl.callback, {}, sig, impl.length)); Add(args...); } @@ -83,7 +84,7 @@ class ClassHandle { template void Add(const char* name, detail::FreeFunctionHolder impl, Args... args) { v8::Local name_handle = v8_symbol(name); - tmpl->Set(name_handle, v8::FunctionTemplate::New(isolate, impl.callback, name_handle, v8::Local(), impl.length)); + tmpl->Set(name_handle, v8::FunctionTemplate::New(isolate, impl.callback, {}, v8::Local(), impl.length)); Add(args...); } @@ -91,7 +92,7 @@ class ClassHandle { template void Add(const char* name, detail::MemberAccessorHolder impl, Args... args) { v8::Local name_handle = v8_symbol(name); - proto->SetNativeDataProperty(name_handle, impl.getter.callback, impl.setter.callback, name_handle, v8::PropertyAttribute::None, v8::AccessControl::DEFAULT); + proto->SetAccessor(name_handle, impl.getter.callback, impl.setter.callback); Add(args...); } @@ -103,7 +104,7 @@ class ClassHandle { if (impl.setter.callback != nullptr) { setter = v8::FunctionTemplate::New(isolate, impl.setter.callback, name_handle); } - tmpl->SetAccessorProperty(name_handle, v8::FunctionTemplate::New(isolate, impl.getter.callback, name_handle), setter); + tmpl->SetAccessorProperty(name_handle, v8::FunctionTemplate::New(isolate, impl.getter.callback, {}), setter); Add(args...); } diff --git a/src/isolate/generic/callbacks.h b/src/isolate/generic/callbacks.h index 6bbfd0aa..7798173b 100644 --- a/src/isolate/generic/callbacks.h +++ b/src/isolate/generic/callbacks.h @@ -78,13 +78,13 @@ inline void Returner(Type return_value, const v8::FunctionCallbackInfo -inline void Returner(Type return_value, v8::Local /*name*/, const v8::PropertyCallbackInfo& info) { +inline void Returner(Type return_value, v8::Local /*name*/, const v8::PropertyCallbackInfo& info) { info.GetReturnValue().Set(HandleCast>(return_value, info)); } inline void Returner( VoidReturn /*return_value*/, - v8::Local /*name*/, + v8::Local /*name*/, v8::Local /*value*/, const v8::PropertyCallbackInfo& /*info*/ ) {} @@ -157,13 +157,13 @@ struct MemberFunctionHolder : FunctionCallbackImpl { }; // Member getters and setters -struct MemberGetterHolder : GenericCallback, const v8::PropertyCallbackInfo&> { +struct MemberGetterHolder : GenericCallback, const v8::PropertyCallbackInfo&> { using GenericCallback::GenericCallback; }; -struct MemberSetterHolder : GenericCallback, v8::Local, const v8::PropertyCallbackInfo&> { +struct MemberSetterHolder : GenericCallback, v8::Local, const v8::PropertyCallbackInfo&> { using GenericCallback::GenericCallback; }; diff --git a/src/isolate/generic/extract_params.h b/src/isolate/generic/extract_params.h index 3b3ef3f9..038c405b 100644 --- a/src/isolate/generic/extract_params.h +++ b/src/isolate/generic/extract_params.h @@ -66,13 +66,13 @@ inline auto ExtractParamImpl(const v8::FunctionCallbackInfo& info) -> } template -inline auto ExtractParamImpl(v8::Local /*name*/, const v8::PropertyCallbackInfo& info) -> v8::Local { +inline auto ExtractParamImpl(v8::Local /*name*/, const v8::PropertyCallbackInfo& info) -> v8::Local { static_assert(Index == 0, "Getter callback should have no parameters"); return info.This(); } template -inline auto ExtractParamImpl(v8::Local /*name*/, v8::Local value, const v8::PropertyCallbackInfo& info) -> v8::Local { +inline auto ExtractParamImpl(v8::Local /*name*/, v8::Local value, const v8::PropertyCallbackInfo& info) -> v8::Local { static_assert(Index < 2, "Setter callback should have exactly 1 parameter"); if (Index == 0) { return info.This();