Skip to content

Commit 7d46232

Browse files
inspector: add origin and auxData in Inspector.contextCreated method
Signed-off-by: Francis Bouvier <[email protected]>
1 parent 0a120e5 commit 7d46232

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

src/binding.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,11 +1554,29 @@ v8_inspector::V8InspectorSession *v8_inspector__Inspector__Connect(
15541554
return u.release();
15551555
}
15561556
void v8_inspector__Inspector__ContextCreated(v8_inspector::V8Inspector *self,
1557+
const char *name, int name_len,
1558+
const char *origin, int origin_len,
1559+
const char *auxData, int auxData_len,
15571560
int contextGroupId,
15581561
const v8::Context &ctx) {
1559-
v8_inspector::StringView ctxView(toStringView("inspector"));
1562+
// create context info
1563+
std::string name_str;
1564+
name_str.assign(name, name_len);
1565+
v8_inspector::StringView name_view(toStringView(name_str));
15601566
auto context = ptr_to_local(&ctx);
1561-
v8_inspector::V8ContextInfo info(context, contextGroupId, ctxView);
1567+
v8_inspector::V8ContextInfo info(context, contextGroupId, name_view);
1568+
1569+
// add origin to context info
1570+
std::string origin_str;
1571+
origin_str.assign(origin, origin_len);
1572+
info.origin = toStringView(origin_str);
1573+
1574+
// add auxData to context info
1575+
std::string auxData_str;
1576+
auxData_str.assign(auxData, auxData_len);
1577+
info.auxData = toStringView(auxData_str);
1578+
1579+
// call contextCreated
15621580
self->contextCreated(info);
15631581
}
15641582

@@ -1575,7 +1593,7 @@ void v8_inspector__Session__dispatchProtocolMessage(
15751593

15761594
// InspectorChannel
15771595

1578-
v8_inspector__Channel__IMPL * v8_inspector__Channel__IMPL__CREATE(v8::Isolate *isolate) {
1596+
v8_inspector__Channel__IMPL * v8_inspector__Channel__IMPL__CREATE(v8::Isolate *isolate) {
15791597
auto channel = new v8_inspector__Channel__IMPL();
15801598
channel->isolate = isolate;
15811599
return channel;

src/binding.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,9 @@ InspectorSession* v8_inspector__Inspector__Connect(
961961
Inspector *self, int contextGroupId,
962962
InspectorChannelImpl *channel,
963963
ClientTrustLevel level);
964-
void v8_inspector__Inspector__ContextCreated(
965-
Inspector *self,
966-
int contextGroupId,
964+
void v8_inspector__Inspector__ContextCreated(Inspector *self, const char *name,
965+
usize name_len, const char *origin,
966+
usize origin_len,
967+
const char *auxData, const usize auxData_len,
968+
int contextGroupId,
967969
const Context* context);

src/v8.zig

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,8 +2343,33 @@ pub const Inspector = struct {
23432343
return InspectorSession{ .handle = session };
23442344
}
23452345

2346-
pub fn contextCreated(self: Inspector, ctx: Context) void {
2347-
c.v8_inspector__Inspector__ContextCreated(self.handle, contextGroupId, ctx.handle);
2346+
pub fn contextCreated(
2347+
self: Inspector,
2348+
ctx: Context,
2349+
name: []const u8,
2350+
origin: []const u8,
2351+
auxData: ?[]const u8,
2352+
) void {
2353+
var auxData_ptr: [*c]const u8 = undefined;
2354+
var auxData_len: usize = undefined;
2355+
if (auxData) |data| {
2356+
auxData_ptr = data.ptr;
2357+
auxData_len = data.len;
2358+
} else {
2359+
auxData_ptr = null;
2360+
auxData_len = 0;
2361+
}
2362+
c.v8_inspector__Inspector__ContextCreated(
2363+
self.handle,
2364+
name.ptr,
2365+
name.len,
2366+
origin.ptr,
2367+
origin.len,
2368+
auxData_ptr,
2369+
auxData_len,
2370+
contextGroupId,
2371+
ctx.handle,
2372+
);
23482373
}
23492374
};
23502375

0 commit comments

Comments
 (0)