Skip to content

Commit b1d9a29

Browse files
committed
Fix inspector sessions
1 parent f7948b2 commit b1d9a29

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

inspector-example.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ let ivm = require('./isolated-vm');
1111
let isolate = new ivm.Isolate({ inspector: true });
1212
(async function() {
1313
let context = await isolate.createContext({ inspector: true });
14-
let script = await isolate.compileScript('for(;;)debugger;', { filename: 'example.js' });
14+
const inspector = isolate.createInspectorSession();
15+
inspector.dispatchProtocolMessage('{"id":1,"method":"Debugger.enable"}');
16+
await context.eval('/* break on script start */debugger;');
17+
inspector.dispose();
18+
let script = await isolate.compileScript('console.log("hello world")', { filename: 'example.js' });
1519
await script.run(context);
1620
}()).catch(console.error);
1721

@@ -31,6 +35,7 @@ wss.on('connection', function(ws) {
3135

3236
// Relay messages from frontend to backend
3337
ws.on('message', function(message) {
38+
console.log('<', message.toString())
3439
try {
3540
channel.dispatchProtocolMessage(String(message));
3641
} catch (err) {
@@ -41,6 +46,7 @@ wss.on('connection', function(ws) {
4146

4247
// Relay messages from backend to frontend
4348
function send(message) {
49+
console.log('>', message.toString())
4450
try {
4551
ws.send(message);
4652
} catch (err) {

src/isolate/class_handle.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "generic/extract_params.h"
88
#include "generic/handle_cast.h"
99
#include "generic/read_option.h"
10+
#include "v8-function-callback.h"
1011

1112
#include <cassert>
1213
#include <cstddef>
@@ -67,7 +68,7 @@ class ClassHandle {
6768
template <typename... Args>
6869
void Add(const char* name, detail::MemberFunctionHolder impl, Args... args) {
6970
v8::Local<v8::String> name_handle = v8_symbol(name);
70-
proto->Set(name_handle, v8::FunctionTemplate::New(isolate, impl.callback, name_handle, sig, impl.length));
71+
proto->Set(name_handle, v8::FunctionTemplate::New(isolate, impl.callback, {}, sig, impl.length));
7172
Add(args...);
7273
}
7374

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

9091
// This adds accessors
9192
template <typename... Args>
9293
void Add(const char* name, detail::MemberAccessorHolder impl, Args... args) {
9394
v8::Local<v8::String> name_handle = v8_symbol(name);
94-
proto->SetNativeDataProperty(name_handle, impl.getter.callback, impl.setter.callback, name_handle, v8::PropertyAttribute::None, v8::AccessControl::DEFAULT);
95+
proto->SetAccessor(name_handle, impl.getter.callback, impl.setter.callback);
9596
Add(args...);
9697
}
9798

@@ -103,7 +104,7 @@ class ClassHandle {
103104
if (impl.setter.callback != nullptr) {
104105
setter = v8::FunctionTemplate::New(isolate, impl.setter.callback, name_handle);
105106
}
106-
tmpl->SetAccessorProperty(name_handle, v8::FunctionTemplate::New(isolate, impl.getter.callback, name_handle), setter);
107+
tmpl->SetAccessorProperty(name_handle, v8::FunctionTemplate::New(isolate, impl.getter.callback, {}), setter);
107108
Add(args...);
108109
}
109110

src/isolate/generic/callbacks.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ inline void Returner(Type return_value, const v8::FunctionCallbackInfo<v8::Value
7878
}
7979

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

8585
inline void Returner(
8686
VoidReturn /*return_value*/,
87-
v8::Local<v8::String> /*name*/,
87+
v8::Local<v8::Name> /*name*/,
8888
v8::Local<v8::Value> /*value*/,
8989
const v8::PropertyCallbackInfo<void>& /*info*/
9090
) {}
@@ -157,13 +157,13 @@ struct MemberFunctionHolder : FunctionCallbackImpl {
157157
};
158158

159159
// Member getters and setters
160-
struct MemberGetterHolder : GenericCallback<v8::AccessorGetterCallback,
161-
v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>&> {
160+
struct MemberGetterHolder : GenericCallback<v8::AccessorNameGetterCallback,
161+
v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>&> {
162162
using GenericCallback::GenericCallback;
163163
};
164164

165-
struct MemberSetterHolder : GenericCallback<v8::AccessorSetterCallback,
166-
v8::Local<v8::String>, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<void>&> {
165+
struct MemberSetterHolder : GenericCallback<v8::AccessorNameSetterCallback,
166+
v8::Local<v8::Name>, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<void>&> {
167167
using GenericCallback::GenericCallback;
168168
};
169169

src/isolate/generic/extract_params.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ inline auto ExtractParamImpl(const v8::FunctionCallbackInfo<v8::Value>& info) ->
6666
}
6767

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

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

0 commit comments

Comments
 (0)