Skip to content

Commit f4f09f2

Browse files
Merge pull request #33 from lightpanda-io/inspector-cli-ensure-default-ctx
inspector: implement ensure default context
2 parents c3534fc + 63e6fb3 commit f4f09f2

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/binding.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,8 @@ void v8_inspector__Client__IMPL__consoleAPIMessage(
16811681
const v8_inspector::StringView &message,
16821682
const v8_inspector::StringView &url, unsigned lineNumber,
16831683
unsigned columnNumber, v8_inspector::V8StackTrace *stackTrace);
1684+
const v8::Context* v8_inspector__Client__IMPL__ensureDefaultContextInGroup(
1685+
v8_inspector__Client__IMPL* self, void* data, int contextGroupId);
16841686

16851687
// c++ implementation (just wrappers around the c/zig functions)
16861688
} // extern "C"
@@ -1705,6 +1707,9 @@ void v8_inspector__Client__IMPL::consoleAPIMessage(
17051707
this, this->data, contextGroupId, level, message, url, lineNumber,
17061708
columnNumber, stackTrace);
17071709
}
1710+
v8::Local<v8::Context> v8_inspector__Client__IMPL::ensureDefaultContextInGroup(int contextGroupId) {
1711+
return ptr_to_local(v8_inspector__Client__IMPL__ensureDefaultContextInGroup(this, this->data, contextGroupId));
1712+
}
17081713

17091714
extern "C" {
17101715

src/binding.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,8 @@ void v8_inspector__Client__IMPL__consoleAPIMessage(
946946
InspectorClientImpl *self, int contextGroupId, MessageErrorLevel level,
947947
StringView *message, StringView *url, unsigned lineNumber,
948948
unsigned columnNumber, StackTrace *StackTrace);
949+
const Context* v8_inspector__Client__IMPL__ensureDefaultContextInGroup(
950+
InspectorClientImpl* self, void* data, int contextGroupId);
949951

950952
// InspectorSession
951953

src/inspector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class v8_inspector__Client__IMPL
3838
const v8_inspector::StringView& url,
3939
unsigned lineNumber, unsigned columnNumber,
4040
v8_inspector::V8StackTrace* stackTrace) override;
41+
v8::Local<v8::Context> ensureDefaultContextInGroup(int contextGroupId) override;
4142
};
4243

4344
#endif // V8INSPECTORIMPL_H

src/v8.zig

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,10 @@ pub const Inspector = struct {
23002300

23012301
rnd: RndGen = RndGen.init(0),
23022302

2303+
// The default JS context handle.
2304+
// Set when a context is created.
2305+
ctx_handle: ?*const C_Context = null,
2306+
23032307
const RndGen = std.rand.DefaultPrng;
23042308

23052309
const contextGroupId = 1;
@@ -2345,12 +2349,13 @@ pub const Inspector = struct {
23452349
}
23462350

23472351
pub fn contextCreated(
2348-
self: Inspector,
2352+
self: *Inspector,
23492353
ctx: Context,
23502354
name: []const u8,
23512355
origin: []const u8,
23522356
auxData: ?[]const u8,
23532357
) void {
2358+
std.log.debug("Inspector contextCreated called", .{});
23542359
var auxData_ptr: [*c]const u8 = undefined;
23552360
var auxData_len: usize = undefined;
23562361
if (auxData) |data| {
@@ -2371,6 +2376,7 @@ pub const Inspector = struct {
23712376
contextGroupId,
23722377
ctx.handle,
23732378
);
2379+
self.ctx_handle = ctx.handle;
23742380
}
23752381
};
23762382

@@ -2453,6 +2459,15 @@ pub export fn v8_inspector__Client__IMPL__consoleAPIMessage(
24532459
// TODO
24542460
}
24552461

2462+
pub export fn v8_inspector__Client__IMPL__ensureDefaultContextInGroup(
2463+
_: *c.InspectorClientImpl,
2464+
data: *anyopaque,
2465+
) callconv(.C) ?*const C_Context {
2466+
std.log.debug("InspectorClient ensureDefaultContextInGroup called", .{});
2467+
const inspector = Inspector.fromData(data);
2468+
return inspector.ctx_handle;
2469+
}
2470+
24562471
// InspectorChannel
24572472

24582473
pub const InspectorChannel = struct {

0 commit comments

Comments
 (0)