Skip to content

Commit

Permalink
Fix inspector sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
laverdet committed Jun 4, 2024
1 parent f7948b2 commit b1d9a29
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
8 changes: 7 additions & 1 deletion inspector-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions src/isolate/class_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cassert>
#include <cstddef>
Expand Down Expand Up @@ -67,7 +68,7 @@ class ClassHandle {
template <typename... Args>
void Add(const char* name, detail::MemberFunctionHolder impl, Args... args) {
v8::Local<v8::String> 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...);
}

Expand All @@ -83,15 +84,15 @@ class ClassHandle {
template <typename... Args>
void Add(const char* name, detail::FreeFunctionHolder impl, Args... args) {
v8::Local<v8::String> name_handle = v8_symbol(name);
tmpl->Set(name_handle, v8::FunctionTemplate::New(isolate, impl.callback, name_handle, v8::Local<v8::Signature>(), impl.length));
tmpl->Set(name_handle, v8::FunctionTemplate::New(isolate, impl.callback, {}, v8::Local<v8::Signature>(), impl.length));
Add(args...);
}

// This adds accessors
template <typename... Args>
void Add(const char* name, detail::MemberAccessorHolder impl, Args... args) {
v8::Local<v8::String> 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...);
}

Expand All @@ -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...);
}

Expand Down
12 changes: 6 additions & 6 deletions src/isolate/generic/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ inline void Returner(Type return_value, const v8::FunctionCallbackInfo<v8::Value
}

template <class Type>
inline void Returner(Type return_value, v8::Local<v8::String> /*name*/, const v8::PropertyCallbackInfo<v8::Value>& info) {
inline void Returner(Type return_value, v8::Local<v8::Name> /*name*/, const v8::PropertyCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(HandleCast<v8::Local<v8::Value>>(return_value, info));
}

inline void Returner(
VoidReturn /*return_value*/,
v8::Local<v8::String> /*name*/,
v8::Local<v8::Name> /*name*/,
v8::Local<v8::Value> /*value*/,
const v8::PropertyCallbackInfo<void>& /*info*/
) {}
Expand Down Expand Up @@ -157,13 +157,13 @@ struct MemberFunctionHolder : FunctionCallbackImpl {
};

// Member getters and setters
struct MemberGetterHolder : GenericCallback<v8::AccessorGetterCallback,
v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>&> {
struct MemberGetterHolder : GenericCallback<v8::AccessorNameGetterCallback,
v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>&> {
using GenericCallback::GenericCallback;
};

struct MemberSetterHolder : GenericCallback<v8::AccessorSetterCallback,
v8::Local<v8::String>, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<void>&> {
struct MemberSetterHolder : GenericCallback<v8::AccessorNameSetterCallback,
v8::Local<v8::Name>, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<void>&> {
using GenericCallback::GenericCallback;
};

Expand Down
4 changes: 2 additions & 2 deletions src/isolate/generic/extract_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ inline auto ExtractParamImpl(const v8::FunctionCallbackInfo<v8::Value>& info) ->
}

template <int Index>
inline auto ExtractParamImpl(v8::Local<v8::String> /*name*/, const v8::PropertyCallbackInfo<v8::Value>& info) -> v8::Local<v8::Value> {
inline auto ExtractParamImpl(v8::Local<v8::Name> /*name*/, const v8::PropertyCallbackInfo<v8::Value>& info) -> v8::Local<v8::Value> {
static_assert(Index == 0, "Getter callback should have no parameters");
return info.This();
}

template <int Index>
inline auto ExtractParamImpl(v8::Local<v8::String> /*name*/, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) -> v8::Local<v8::Value> {
inline auto ExtractParamImpl(v8::Local<v8::Name> /*name*/, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) -> v8::Local<v8::Value> {
static_assert(Index < 2, "Setter callback should have exactly 1 parameter");
if (Index == 0) {
return info.This();
Expand Down

0 comments on commit b1d9a29

Please sign in to comment.