Skip to content

Commit 252531f

Browse files
committed
inspector: implement ensure default context
1 parent 821da4f commit 252531f

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,8 @@ pub const Inspector = struct {
22992299

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

2302+
context: ?*const C_Context = null,
2303+
23022304
const RndGen = std.rand.DefaultPrng;
23032305

23042306
const contextGroupId = 1;
@@ -2344,12 +2346,13 @@ pub const Inspector = struct {
23442346
}
23452347

23462348
pub fn contextCreated(
2347-
self: Inspector,
2349+
self: *Inspector,
23482350
ctx: Context,
23492351
name: []const u8,
23502352
origin: []const u8,
23512353
auxData: ?[]const u8,
23522354
) void {
2355+
std.log.debug("Inspector contextCreated called", .{});
23532356
var auxData_ptr: [*c]const u8 = undefined;
23542357
var auxData_len: usize = undefined;
23552358
if (auxData) |data| {
@@ -2370,6 +2373,7 @@ pub const Inspector = struct {
23702373
contextGroupId,
23712374
ctx.handle,
23722375
);
2376+
self.context = ctx.handle;
23732377
}
23742378
};
23752379

@@ -2452,6 +2456,15 @@ pub export fn v8_inspector__Client__IMPL__consoleAPIMessage(
24522456
// TODO
24532457
}
24542458

2459+
pub export fn v8_inspector__Client__IMPL__ensureDefaultContextInGroup(
2460+
_: *c.InspectorClientImpl,
2461+
data: *anyopaque,
2462+
) callconv(.C) ?*const C_Context {
2463+
std.log.debug("InspectorClient ensureDefaultContextInGroup called", .{});
2464+
const inspector = Inspector.fromData(data);
2465+
return inspector.context;
2466+
}
2467+
24552468
// InspectorChannel
24562469

24572470
pub const InspectorChannel = struct {

0 commit comments

Comments
 (0)