remove remaining direct v8 references

This commit is contained in:
Karl Seguin
2026-01-02 16:07:23 +08:00
parent 18c846757b
commit 8438b7d561
8 changed files with 152 additions and 148 deletions

View File

@@ -42,9 +42,10 @@ page: *Page,
isolate: js.Isolate, isolate: js.Isolate,
// This context is a persistent object. The persistent needs to be recovered and reset. // This context is a persistent object. The persistent needs to be recovered and reset.
handle: *const v8.c.Context, handle: *const v8.c.Context,
handle_scope: ?js.HandleScope, handle_scope: ?js.HandleScope,
cpu_profiler: ?v8.CpuProfiler = null, cpu_profiler: ?*v8.c.CpuProfiler = null,
// references Env.templates // references Env.templates
templates: []*const v8.c.FunctionTemplate, templates: []*const v8.c.FunctionTemplate,
@@ -114,7 +115,7 @@ const ModuleEntry = struct {
resolver_promise: ?js.Promise = null, resolver_promise: ?js.Promise = null,
}; };
pub fn fromC(c_context: *const v8.C_Context) *Context { pub fn fromC(c_context: *const v8.c.Context) *Context {
const data = v8.c.v8__Context__GetEmbedderData(c_context, 1).?; const data = v8.c.v8__Context__GetEmbedderData(c_context, 1).?;
const big_int = js.BigInt{ .handle = @ptrCast(data) }; const big_int = js.BigInt{ .handle = @ptrCast(data) };
return @ptrFromInt(big_int.getUint64()); return @ptrFromInt(big_int.getUint64());
@@ -168,9 +169,6 @@ pub fn deinit(self: *Context) void {
scope.deinit(); scope.deinit();
v8.c.v8__Context__Exit(self.handle); v8.c.v8__Context__Exit(self.handle);
} }
const v8_context = v8.Context{ .handle = self.handle };
var presistent_context = v8.Persistent(v8.Context).recoverCast(v8_context);
presistent_context.deinit();
} }
// == Executors == // == Executors ==
@@ -372,6 +370,10 @@ pub fn throw(self: *Context, err: []const u8) js.Exception {
}; };
} }
pub fn debugContextId(self: *const Context) i32 {
return v8.c.v8__Context__DebugContextId(self.handle);
}
pub fn zigValueToJs(self: *Context, value: anytype, comptime opts: Caller.CallOpts) !js.Value { pub fn zigValueToJs(self: *Context, value: anytype, comptime opts: Caller.CallOpts) !js.Value {
const isolate = self.isolate; const isolate = self.isolate;
@@ -611,7 +613,6 @@ pub fn mapZigInstanceToJs(self: *Context, js_obj_handle: ?*const v8.c.Object, va
} }
pub fn jsValueToZig(self: *Context, comptime T: type, js_value: js.Value) !T { pub fn jsValueToZig(self: *Context, comptime T: type, js_value: js.Value) !T {
const v8_context = v8.Context{ .handle = self.handle };
switch (@typeInfo(T)) { switch (@typeInfo(T)) {
.optional => |o| { .optional => |o| {
// If type type is a ?js.Value or a ?js.Object, then we want to pass // If type type is a ?js.Value or a ?js.Object, then we want to pass
@@ -757,7 +758,7 @@ pub fn jsValueToZig(self: *Context, comptime T: type, js_value: js.Value) !T {
return std.meta.stringToEnum(T, try self.valueToString(js_value, .{})) orelse return error.InvalidArgument; return std.meta.stringToEnum(T, try self.valueToString(js_value, .{})) orelse return error.InvalidArgument;
} }
switch (@typeInfo(e.tag_type)) { switch (@typeInfo(e.tag_type)) {
.int => return std.meta.intToEnum(T, try jsIntToZig(e.tag_type, js_value, v8_context)), .int => return std.meta.intToEnum(T, try jsIntToZig(e.tag_type, js_value)),
else => @compileError("unsupported enum parameter type: " ++ @typeName(T)), else => @compileError("unsupported enum parameter type: " ++ @typeName(T)),
} }
}, },
@@ -1151,11 +1152,11 @@ pub fn createPromiseResolver(self: *Context) js.PromiseResolver {
// Callback from V8, asking us to load a module. The "specifier" is // Callback from V8, asking us to load a module. The "specifier" is
// the src of the module to load. // the src of the module to load.
fn resolveModuleCallback( fn resolveModuleCallback(
c_context: ?*const v8.C_Context, c_context: ?*const v8.c.Context,
c_specifier: ?*const v8.C_String, c_specifier: ?*const v8.c.String,
import_attributes: ?*const v8.C_FixedArray, import_attributes: ?*const v8.c.FixedArray,
c_referrer: ?*const v8.C_Module, c_referrer: ?*const v8.c.Module,
) callconv(.c) ?*const v8.C_Module { ) callconv(.c) ?*const v8.c.Module {
_ = import_attributes; _ = import_attributes;
const self = fromC(c_context.?); const self = fromC(c_context.?);
@@ -1215,7 +1216,7 @@ pub fn dynamicModuleCallback(
return @constCast(promise.handle); return @constCast(promise.handle);
} }
pub fn metaObjectCallback(c_context: ?*v8.C_Context, c_module: ?*v8.C_Module, c_meta: ?*v8.C_Value) callconv(.c) void { pub fn metaObjectCallback(c_context: ?*v8.c.Context, c_module: ?*v8.c.Module, c_meta: ?*v8.c.Value) callconv(.c) void {
const self = fromC(c_context.?); const self = fromC(c_context.?);
const m = js.Module{ .ctx = self, .handle = c_module.? }; const m = js.Module{ .ctx = self, .handle = c_module.? };
const meta = js.Object{ .ctx = self, .handle = @ptrCast(c_meta.?) }; const meta = js.Object{ .ctx = self, .handle = @ptrCast(c_meta.?) };
@@ -1236,7 +1237,7 @@ pub fn metaObjectCallback(c_context: ?*v8.C_Context, c_module: ?*v8.C_Module, c_
} }
} }
fn _resolveModuleCallback(self: *Context, referrer: js.Module, specifier: [:0]const u8) !?*const v8.C_Module { fn _resolveModuleCallback(self: *Context, referrer: js.Module, specifier: [:0]const u8) !?*const v8.c.Module {
const referrer_path = self.module_identifier.get(referrer.getIdentityHash()) orelse { const referrer_path = self.module_identifier.get(referrer.getIdentityHash()) orelse {
// Shouldn't be possible. // Shouldn't be possible.
return error.UnknownModuleReferrer; return error.UnknownModuleReferrer;
@@ -1997,16 +1998,17 @@ pub fn startCpuProfiler(self: *Context) void {
} }
std.debug.assert(self.cpu_profiler == null); std.debug.assert(self.cpu_profiler == null);
v8.CpuProfiler.useDetailedSourcePositionsForProfiling(self.isolate); v8.c.v8__CpuProfiler__UseDetailedSourcePositionsForProfiling(self.isolate.handle);
const cpu_profiler = v8.CpuProfiler.init(self.isolate);
const title = self.isolate.initStringUtf8("v8_cpu_profile"); const cpu_profiler = v8.c.v8__CpuProfiler__Get(self.isolate.handle).?;
cpu_profiler.startProfiling(title); const title = self.isolate.initStringHandle("v8_cpu_profile");
v8.c.v8__CpuProfiler__StartProfiling(cpu_profiler, title);
self.cpu_profiler = cpu_profiler; self.cpu_profiler = cpu_profiler;
} }
pub fn stopCpuProfiler(self: *Context) ![]const u8 { pub fn stopCpuProfiler(self: *Context) ![]const u8 {
const title = self.isolate.initStringUtf8("v8_cpu_profile"); const title = self.isolate.initStringHandle("v8_cpu_profile");
const profile = self.cpu_profiler.?.stopProfiling(title) orelse unreachable; const handle = v8.c.v8__CpuProfiler__StopProfiling(self.cpu_profiler.?, title) orelse return error.NoProfiles;
const serialized = profile.serialize(self.isolate).?; const string_handle = v8.c.v8__CpuProfile__Serialize(handle, self.isolate.handle) orelse return error.NoProfile;
return self.jsStringToZig(serialized, .{}); return self.jsStringToZig(string_handle, .{});
} }

View File

@@ -65,8 +65,8 @@ pub fn init(allocator: Allocator, platform: *const Platform, snapshot: *Snapshot
v8.c.v8__Isolate__CreateParams__CONSTRUCT(params); v8.c.v8__Isolate__CreateParams__CONSTRUCT(params);
params.snapshot_blob = @ptrCast(&snapshot.startup_data); params.snapshot_blob = @ptrCast(&snapshot.startup_data);
params.array_buffer_allocator = v8.createDefaultArrayBufferAllocator(); params.array_buffer_allocator = v8.c.v8__ArrayBuffer__Allocator__NewDefaultAllocator().?;
errdefer v8.destroyArrayBufferAllocator(params.array_buffer_allocator.?); errdefer v8.c.v8__ArrayBuffer__Allocator__DELETE(params.array_buffer_allocator.?);
params.external_references = &snapshot.external_references; params.external_references = &snapshot.external_references;
@@ -130,7 +130,7 @@ pub fn deinit(self: *Env) void {
self.isolate.exit(); self.isolate.exit();
self.isolate.deinit(); self.isolate.deinit();
v8.destroyArrayBufferAllocator(self.isolate_params.array_buffer_allocator.?); v8.c.v8__ArrayBuffer__Allocator__DELETE(self.isolate_params.array_buffer_allocator.?);
self.allocator.destroy(self.isolate_params); self.allocator.destroy(self.isolate_params);
} }
@@ -191,15 +191,15 @@ pub fn dumpMemoryStats(self: *Env) void {
, .{ stats.total_heap_size, stats.total_heap_size_executable, stats.total_physical_size, stats.total_available_size, stats.used_heap_size, stats.heap_size_limit, stats.malloced_memory, stats.external_memory, stats.peak_malloced_memory, stats.number_of_native_contexts, stats.number_of_detached_contexts, stats.total_global_handles_size, stats.used_global_handles_size, stats.does_zap_garbage }); , .{ stats.total_heap_size, stats.total_heap_size_executable, stats.total_physical_size, stats.total_available_size, stats.used_heap_size, stats.heap_size_limit, stats.malloced_memory, stats.external_memory, stats.peak_malloced_memory, stats.number_of_native_contexts, stats.number_of_detached_contexts, stats.total_global_handles_size, stats.used_global_handles_size, stats.does_zap_garbage });
} }
fn promiseRejectCallback(v8_msg: v8.C_PromiseRejectMessage) callconv(.c) void { fn promiseRejectCallback(message_handle: v8.c.PromiseRejectMessage) callconv(.c) void {
const msg = v8.PromiseRejectMessage.initFromC(v8_msg); const promise_handle = v8.c.v8__PromiseRejectMessage__GetPromise(&message_handle).?;
const isolate_handle = v8.c.v8__Object__GetIsolate(@ptrCast(msg.getPromise().handle)).?; const isolate_handle = v8.c.v8__Object__GetIsolate(@ptrCast(promise_handle)).?;
const js_isolate = js.Isolate{ .handle = isolate_handle }; const js_isolate = js.Isolate{ .handle = isolate_handle };
const context = Context.fromIsolate(js_isolate); const context = Context.fromIsolate(js_isolate);
const value = const value =
if (msg.getValue()) |v8_value| if (v8.c.v8__PromiseRejectMessage__GetValue(&message_handle)) |v8_value|
context.valueToString(js.Value{ .ctx = context, .handle = v8_value.handle }, .{}) catch |err| @errorName(err) context.valueToString(.{ .ctx = context, .handle = v8_value }, .{}) catch |err| @errorName(err)
else else
"no value"; "no value";

View File

@@ -52,6 +52,7 @@ context_arena: ArenaAllocator,
// does all the work, but having all page-specific data structures // does all the work, but having all page-specific data structures
// grouped together helps keep things clean. // grouped together helps keep things clean.
context: ?Context = null, context: ?Context = null,
persisted_context: ?js.Global(Context) = null,
// no init, must be initialized via env.newExecutionWorld() // no init, must be initialized via env.newExecutionWorld()
@@ -59,7 +60,6 @@ pub fn deinit(self: *ExecutionWorld) void {
if (self.context != null) { if (self.context != null) {
self.removeContext(); self.removeContext();
} }
self.context_arena.deinit(); self.context_arena.deinit();
} }
@@ -76,7 +76,7 @@ pub fn createContext(self: *ExecutionWorld, page: *Page, enter: bool) !*Context
const isolate = env.isolate; const isolate = env.isolate;
const arena = self.context_arena.allocator(); const arena = self.context_arena.allocator();
const context_handle: *const v8.c.Context = blk: { const persisted_context: js.Global(Context) = blk: {
var temp_scope: js.HandleScope = undefined; var temp_scope: js.HandleScope = undefined;
temp_scope.init(isolate); temp_scope.init(isolate);
defer temp_scope.deinit(); defer temp_scope.deinit();
@@ -98,24 +98,22 @@ pub fn createContext(self: *ExecutionWorld, page: *Page, enter: bool) !*Context
}; };
v8.c.v8__ObjectTemplate__SetNamedHandler(global_template, &configuration); v8.c.v8__ObjectTemplate__SetNamedHandler(global_template, &configuration);
const context_local = isolate.createContextHandle(null, null); const context_handle = isolate.createContextHandle(null, null);
// Make the context persistent so it survives beyond this handle scope break :blk js.Global(Context).init(isolate.handle, context_handle);
var persistent_handle: *v8.c.Data = undefined;
v8.c.v8__Persistent__New(isolate.handle, @ptrCast(context_local), @ptrCast(&persistent_handle));
break :blk @ptrCast(persistent_handle);
}; };
// For a Page we only create one HandleScope, it is stored in the main World (enter==true). A page can have multple contexts, 1 for each World. // For a Page we only create one HandleScope, it is stored in the main World (enter==true). A page can have multple contexts, 1 for each World.
// The main Context that enters and holds the HandleScope should therefore always be created first. Following other worlds for this page // The main Context that enters and holds the HandleScope should therefore always be created first. Following other worlds for this page
// like isolated Worlds, will thereby place their objects on the main page's HandleScope. Note: In the furure the number of context will multiply multiple frames support // like isolated Worlds, will thereby place their objects on the main page's HandleScope. Note: In the furure the number of context will multiply multiple frames support
const v8_context = persisted_context.local();
var handle_scope: ?js.HandleScope = null; var handle_scope: ?js.HandleScope = null;
if (enter) { if (enter) {
handle_scope = @as(js.HandleScope, undefined); handle_scope = @as(js.HandleScope, undefined);
handle_scope.?.init(isolate); handle_scope.?.init(isolate);
v8.c.v8__Context__Enter(context_handle); v8.c.v8__Context__Enter(v8_context);
} }
errdefer if (enter) { errdefer if (enter) {
v8.c.v8__Context__Exit(context_handle); v8.c.v8__Context__Exit(v8_context);
handle_scope.?.deinit(); handle_scope.?.deinit();
}; };
@@ -126,19 +124,20 @@ pub fn createContext(self: *ExecutionWorld, page: *Page, enter: bool) !*Context
.page = page, .page = page,
.id = context_id, .id = context_id,
.isolate = isolate, .isolate = isolate,
.handle = context_handle, .handle = v8_context,
.templates = env.templates, .templates = env.templates,
.handle_scope = handle_scope, .handle_scope = handle_scope,
.script_manager = &page._script_manager, .script_manager = &page._script_manager,
.call_arena = page.call_arena, .call_arena = page.call_arena,
.arena = arena, .arena = arena,
}; };
self.persisted_context = persisted_context;
var context = &self.context.?; var context = &self.context.?;
// Store a pointer to our context inside the v8 context so that, given // Store a pointer to our context inside the v8 context so that, given
// a v8 context, we can get our context out // a v8 context, we can get our context out
const data = isolate.initBigInt(@intFromPtr(context)); const data = isolate.initBigInt(@intFromPtr(context));
v8.c.v8__Context__SetEmbedderData(context_handle, 1, @ptrCast(data.handle)); v8.c.v8__Context__SetEmbedderData(context.handle, 1, @ptrCast(data.handle));
try context.setupGlobal(); try context.setupGlobal();
return context; return context;
@@ -151,8 +150,13 @@ pub fn removeContext(self: *ExecutionWorld) void {
// the queue. Running them later could lead to invalid memory accesses. // the queue. Running them later could lead to invalid memory accesses.
self.env.runMicrotasks(); self.env.runMicrotasks();
self.context.?.deinit(); var context = &(self.context orelse return);
context.deinit();
self.context = null; self.context = null;
self.persisted_context.?.deinit();
self.persisted_context = null;
_ = self.context_arena.reset(.{ .retain_with_limit = CONTEXT_ARENA_RETAIN }); _ = self.context_arena.reset(.{ .retain_with_limit = CONTEXT_ARENA_RETAIN });
} }
@@ -164,7 +168,7 @@ pub fn resumeExecution(self: *const ExecutionWorld) void {
self.env.isolate.cancelTerminateExecution(); self.env.isolate.cancelTerminateExecution();
} }
pub fn unknownPropertyCallback(c_name: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 { pub fn unknownPropertyCallback(c_name: ?*const v8.c.Name, raw_info: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 {
const isolate_handle = v8.c.v8__PropertyCallbackInfo__GetIsolate(raw_info).?; const isolate_handle = v8.c.v8__PropertyCallbackInfo__GetIsolate(raw_info).?;
const context = Context.fromIsolate(.{ .handle = isolate_handle }); const context = Context.fromIsolate(.{ .handle = isolate_handle });
@@ -216,5 +220,6 @@ pub fn unknownPropertyCallback(c_name: ?*const v8.C_Name, raw_info: ?*const v8.C
} }
} }
return v8.Intercepted.No; // not intercepted
return 0;
} }

View File

@@ -25,7 +25,7 @@ const Context = @import("Context.zig");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const RndGen = std.Random.DefaultPrng; const RndGen = std.Random.DefaultPrng;
const CONTEST_GROUP_ID = 1; const CONTEXT_GROUP_ID = 1;
const CLIENT_TRUST_LEVEL = 1; const CLIENT_TRUST_LEVEL = 1;
const Inspector = @This(); const Inspector = @This();
@@ -36,7 +36,7 @@ client: Client,
channel: Channel, channel: Channel,
session: Session, session: Session,
rnd: RndGen = RndGen.init(0), rnd: RndGen = RndGen.init(0),
ctx_handle: ?*const v8.c.Context = null, default_context: ?*const v8.c.Context = null,
// We expect allocator to be an arena // We expect allocator to be an arena
// Note: This initializes the pre-allocated inspector in-place // Note: This initializes the pre-allocated inspector in-place
@@ -59,7 +59,7 @@ pub fn init(self: *Inspector, isolate: *v8.c.Isolate, ctx: anytype) !void {
.client = undefined, .client = undefined,
.channel = undefined, .channel = undefined,
.rnd = RndGen.init(0), .rnd = RndGen.init(0),
.ctx_handle = null, .default_context = null,
.session = undefined, .session = undefined,
}; };
@@ -88,7 +88,7 @@ pub fn init(self: *Inspector, isolate: *v8.c.Isolate, ctx: anytype) !void {
// Create the session // Create the session
const session_handle = v8.c.v8_inspector__Inspector__Connect( const session_handle = v8.c.v8_inspector__Inspector__Connect(
handle, handle,
CONTEST_GROUP_ID, CONTEXT_GROUP_ID,
channel.handle, channel.handle,
CLIENT_TRUST_LEVEL, CLIENT_TRUST_LEVEL,
).?; ).?;
@@ -127,34 +127,28 @@ pub fn send(self: *const Inspector, msg: []const u8) void {
// {isDefault: boolean, type: 'default'|'isolated'|'worker', frameId: string} // {isDefault: boolean, type: 'default'|'isolated'|'worker', frameId: string}
// - is_default_context: Whether the execution context is default, should match the auxData // - is_default_context: Whether the execution context is default, should match the auxData
pub fn contextCreated( pub fn contextCreated(
self: *const Inspector, self: *Inspector,
context: *const Context, context: *const Context,
name: []const u8, name: []const u8,
origin: []const u8, origin: []const u8,
aux_data: ?[]const u8, aux_data: []const u8,
is_default_context: bool, is_default_context: bool,
) void { ) void {
_ = is_default_context; // TODO: Should this be passed to the C API?
var auxData_ptr: [*c]const u8 = undefined;
var auxData_len: usize = undefined;
if (aux_data) |data| {
auxData_ptr = data.ptr;
auxData_len = data.len;
} else {
auxData_ptr = null;
auxData_len = 0;
}
v8.c.v8_inspector__Inspector__ContextCreated( v8.c.v8_inspector__Inspector__ContextCreated(
self.handle, self.handle,
name.ptr, name.ptr,
name.len, name.len,
origin.ptr, origin.ptr,
origin.len, origin.len,
auxData_ptr, aux_data.ptr,
auxData_len, aux_data.len,
CONTEST_GROUP_ID, CONTEXT_GROUP_ID,
context.handle, context.handle,
); );
if (is_default_context) {
self.default_context = context.handle;
}
} }
// Retrieves the RemoteObject for a given value. // Retrieves the RemoteObject for a given value.
@@ -475,7 +469,7 @@ pub export fn v8_inspector__Client__IMPL__ensureDefaultContextInGroup(
data: *anyopaque, data: *anyopaque,
) callconv(.c) ?*const v8.c.Context { ) callconv(.c) ?*const v8.c.Context {
const inspector: *Inspector = @ptrCast(@alignCast(data)); const inspector: *Inspector = @ptrCast(@alignCast(data));
return inspector.ctx_handle; return inspector.default_context;
} }
pub export fn v8_inspector__Channel__IMPL__sendResponse( pub export fn v8_inspector__Channel__IMPL__sendResponse(

View File

@@ -57,44 +57,44 @@ const Name = struct {
handle: *const v8.c.Name, handle: *const v8.c.Name,
}; };
const CallbackInfo = struct { const FunctionCallbackInfo = struct {
raw: *const v8.c.FunctionCallbackInfo, handle: *const v8.c.FunctionCallbackInfo,
fn length(self: CallbackInfo) u32 { fn length(self: FunctionCallbackInfo) u32 {
return @intCast(v8.c.v8__FunctionCallbackInfo__Length(self.raw)); return @intCast(v8.c.v8__FunctionCallbackInfo__Length(self.handle));
} }
fn getArg(self: CallbackInfo, index: u32) Value { fn getArg(self: FunctionCallbackInfo, index: u32) Value {
return .{ .handle = v8.c.v8__FunctionCallbackInfo__INDEX(self.raw, @intCast(index)).? }; return .{ .handle = v8.c.v8__FunctionCallbackInfo__INDEX(self.handle, @intCast(index)).? };
} }
fn getThis(self: CallbackInfo) *const v8.c.Object { fn getThis(self: FunctionCallbackInfo) *const v8.c.Object {
return v8.c.v8__FunctionCallbackInfo__This(self.raw).?; return v8.c.v8__FunctionCallbackInfo__This(self.handle).?;
} }
fn getReturnValue(self: CallbackInfo) ReturnValue { fn getReturnValue(self: FunctionCallbackInfo) ReturnValue {
var rv: v8.c.ReturnValue = undefined; var rv: v8.c.ReturnValue = undefined;
v8.c.v8__FunctionCallbackInfo__GetReturnValue(self.raw, &rv); v8.c.v8__FunctionCallbackInfo__GetReturnValue(self.handle, &rv);
return .{ .raw = rv }; return .{ .handle = rv };
} }
}; };
const PropertyCallbackInfo = struct { const PropertyCallbackInfo = struct {
raw: *const v8.c.PropertyCallbackInfo, handle: *const v8.c.PropertyCallbackInfo,
fn getThis(self: PropertyCallbackInfo) *const v8.c.Object { fn getThis(self: PropertyCallbackInfo) *const v8.c.Object {
return v8.c.v8__PropertyCallbackInfo__This(self.raw).?; return v8.c.v8__PropertyCallbackInfo__This(self.handle).?;
} }
fn getReturnValue(self: PropertyCallbackInfo) ReturnValue { fn getReturnValue(self: PropertyCallbackInfo) ReturnValue {
var rv: v8.c.ReturnValue = undefined; var rv: v8.c.ReturnValue = undefined;
v8.c.v8__PropertyCallbackInfo__GetReturnValue(self.raw, &rv); v8.c.v8__PropertyCallbackInfo__GetReturnValue(self.handle, &rv);
return .{ .raw = rv }; return .{ .handle = rv };
} }
}; };
const ReturnValue = struct { const ReturnValue = struct {
raw: v8.c.ReturnValue, handle: v8.c.ReturnValue,
fn set(self: ReturnValue, value: anytype) void { fn set(self: ReturnValue, value: anytype) void {
const T = @TypeOf(value); const T = @TypeOf(value);
@@ -112,7 +112,7 @@ const ReturnValue = struct {
} }
fn setValueHandle(self: ReturnValue, handle: *const v8.c.Value) void { fn setValueHandle(self: ReturnValue, handle: *const v8.c.Value) void {
v8.c.v8__ReturnValue__Set(self.raw, handle); v8.c.v8__ReturnValue__Set(self.handle, handle);
} }
}; };
@@ -170,13 +170,13 @@ pub const Caller = struct {
as_typed_array: bool = false, as_typed_array: bool = false,
}; };
pub fn constructor(self: *Caller, comptime T: type, func: anytype, info: CallbackInfo, comptime opts: CallOpts) void { pub fn constructor(self: *Caller, comptime T: type, func: anytype, info: FunctionCallbackInfo, comptime opts: CallOpts) void {
self._constructor(func, info) catch |err| { self._constructor(func, info) catch |err| {
self.handleError(T, @TypeOf(func), err, info, opts); self.handleError(T, @TypeOf(func), err, info, opts);
}; };
} }
fn _constructor(self: *Caller, func: anytype, info: CallbackInfo) !void { fn _constructor(self: *Caller, func: anytype, info: FunctionCallbackInfo) !void {
const F = @TypeOf(func); const F = @TypeOf(func);
const args = try self.getArgs(F, 0, info); const args = try self.getArgs(F, 0, info);
const res = @call(.auto, func, args); const res = @call(.auto, func, args);
@@ -208,13 +208,13 @@ pub const Caller = struct {
info.getReturnValue().set(this.handle); info.getReturnValue().set(this.handle);
} }
pub fn method(self: *Caller, comptime T: type, func: anytype, info: CallbackInfo, comptime opts: CallOpts) void { pub fn method(self: *Caller, comptime T: type, func: anytype, info: FunctionCallbackInfo, comptime opts: CallOpts) void {
self._method(T, func, info, opts) catch |err| { self._method(T, func, info, opts) catch |err| {
self.handleError(T, @TypeOf(func), err, info, opts); self.handleError(T, @TypeOf(func), err, info, opts);
}; };
} }
fn _method(self: *Caller, comptime T: type, func: anytype, info: CallbackInfo, comptime opts: CallOpts) !void { fn _method(self: *Caller, comptime T: type, func: anytype, info: FunctionCallbackInfo, comptime opts: CallOpts) !void {
const F = @TypeOf(func); const F = @TypeOf(func);
var handle_scope: js.HandleScope = undefined; var handle_scope: js.HandleScope = undefined;
handle_scope.init(self.isolate); handle_scope.init(self.isolate);
@@ -226,13 +226,13 @@ pub const Caller = struct {
info.getReturnValue().set(try self.context.zigValueToJs(res, opts)); info.getReturnValue().set(try self.context.zigValueToJs(res, opts));
} }
pub fn function(self: *Caller, comptime T: type, func: anytype, info: CallbackInfo, comptime opts: CallOpts) void { pub fn function(self: *Caller, comptime T: type, func: anytype, info: FunctionCallbackInfo, comptime opts: CallOpts) void {
self._function(func, info, opts) catch |err| { self._function(func, info, opts) catch |err| {
self.handleError(T, @TypeOf(func), err, info, opts); self.handleError(T, @TypeOf(func), err, info, opts);
}; };
} }
fn _function(self: *Caller, func: anytype, info: CallbackInfo, comptime opts: CallOpts) !void { fn _function(self: *Caller, func: anytype, info: FunctionCallbackInfo, comptime opts: CallOpts) !void {
const F = @TypeOf(func); const F = @TypeOf(func);
const context = self.context; const context = self.context;
const args = try self.getArgs(F, 0, info); const args = try self.getArgs(F, 0, info);
@@ -243,7 +243,8 @@ pub const Caller = struct {
pub fn getIndex(self: *Caller, comptime T: type, func: anytype, idx: u32, info: PropertyCallbackInfo, comptime opts: CallOpts) u8 { pub fn getIndex(self: *Caller, comptime T: type, func: anytype, idx: u32, info: PropertyCallbackInfo, comptime opts: CallOpts) u8 {
return self._getIndex(T, func, idx, info, opts) catch |err| { return self._getIndex(T, func, idx, info, opts) catch |err| {
self.handleError(T, @TypeOf(func), err, info, opts); self.handleError(T, @TypeOf(func), err, info, opts);
return v8.Intercepted.No; // not intercepted
return 0;
}; };
} }
@@ -259,7 +260,8 @@ pub const Caller = struct {
pub fn getNamedIndex(self: *Caller, comptime T: type, func: anytype, name: Name, info: PropertyCallbackInfo, comptime opts: CallOpts) u8 { pub fn getNamedIndex(self: *Caller, comptime T: type, func: anytype, name: Name, info: PropertyCallbackInfo, comptime opts: CallOpts) u8 {
return self._getNamedIndex(T, func, name, info, opts) catch |err| { return self._getNamedIndex(T, func, name, info, opts) catch |err| {
self.handleError(T, @TypeOf(func), err, info, opts); self.handleError(T, @TypeOf(func), err, info, opts);
return v8.Intercepted.No; // not intercepted
return 0;
}; };
} }
@@ -275,7 +277,8 @@ pub const Caller = struct {
pub fn setNamedIndex(self: *Caller, comptime T: type, func: anytype, name: Name, js_value: Value, info: PropertyCallbackInfo, comptime opts: CallOpts) u8 { pub fn setNamedIndex(self: *Caller, comptime T: type, func: anytype, name: Name, js_value: Value, info: PropertyCallbackInfo, comptime opts: CallOpts) u8 {
return self._setNamedIndex(T, func, name, js_value, info, opts) catch |err| { return self._setNamedIndex(T, func, name, js_value, info, opts) catch |err| {
self.handleError(T, @TypeOf(func), err, info, opts); self.handleError(T, @TypeOf(func), err, info, opts);
return v8.Intercepted.No; // not intercepted
return 0;
}; };
} }
@@ -295,7 +298,7 @@ pub const Caller = struct {
pub fn deleteNamedIndex(self: *Caller, comptime T: type, func: anytype, name: Name, info: PropertyCallbackInfo, comptime opts: CallOpts) u8 { pub fn deleteNamedIndex(self: *Caller, comptime T: type, func: anytype, name: Name, info: PropertyCallbackInfo, comptime opts: CallOpts) u8 {
return self._deleteNamedIndex(T, func, name, info, opts) catch |err| { return self._deleteNamedIndex(T, func, name, info, opts) catch |err| {
self.handleError(T, @TypeOf(func), err, info, opts); self.handleError(T, @TypeOf(func), err, info, opts);
return v8.Intercepted.No; return 0;
}; };
} }
@@ -322,11 +325,13 @@ pub const Caller = struct {
// if error.NotHandled is part of the error set. // if error.NotHandled is part of the error set.
if (isInErrorSet(error.NotHandled, eu.error_set)) { if (isInErrorSet(error.NotHandled, eu.error_set)) {
if (err == error.NotHandled) { if (err == error.NotHandled) {
return v8.Intercepted.No; // not intercepted
return 0;
} }
} }
self.handleError(T, F, err, info, opts); self.handleError(T, F, err, info, opts);
return v8.Intercepted.No; // not intercepted
return 0;
}; };
}, },
else => ret, else => ret,
@@ -335,7 +340,8 @@ pub const Caller = struct {
if (comptime getter) { if (comptime getter) {
info.getReturnValue().set(try self.context.zigValueToJs(non_error_ret, opts)); info.getReturnValue().set(try self.context.zigValueToJs(non_error_ret, opts));
} }
return v8.Intercepted.Yes; // intercepted
return 1;
} }
fn isInErrorSet(err: anyerror, comptime T: type) bool { fn isInErrorSet(err: anyerror, comptime T: type) bool {
@@ -352,7 +358,7 @@ pub const Caller = struct {
fn handleError(self: *Caller, comptime T: type, comptime F: type, err: anyerror, info: anytype, comptime opts: CallOpts) void { fn handleError(self: *Caller, comptime T: type, comptime F: type, err: anyerror, info: anytype, comptime opts: CallOpts) void {
const isolate = self.isolate; const isolate = self.isolate;
if (comptime @import("builtin").mode == .Debug and @TypeOf(info) == CallbackInfo) { if (comptime @import("builtin").mode == .Debug and @TypeOf(info) == FunctionCallbackInfo) {
if (log.enabled(.js, .warn)) { if (log.enabled(.js, .warn)) {
self.logFunctionCallError(@typeName(T), @typeName(F), err, info); self.logFunctionCallError(@typeName(T), @typeName(F), err, info);
} }
@@ -480,7 +486,7 @@ pub const Caller = struct {
// This is extracted to speed up compilation. When left inlined in handleError, // This is extracted to speed up compilation. When left inlined in handleError,
// this can add as much as 10 seconds of compilation time. // this can add as much as 10 seconds of compilation time.
fn logFunctionCallError(self: *Caller, type_name: []const u8, func: []const u8, err: anyerror, info: CallbackInfo) void { fn logFunctionCallError(self: *Caller, type_name: []const u8, func: []const u8, err: anyerror, info: FunctionCallbackInfo) void {
const args_dump = self.serializeFunctionArgs(info) catch "failed to serialize args"; const args_dump = self.serializeFunctionArgs(info) catch "failed to serialize args";
log.info(.js, "function call error", .{ log.info(.js, "function call error", .{
.type = type_name, .type = type_name,
@@ -491,7 +497,7 @@ pub const Caller = struct {
}); });
} }
fn serializeFunctionArgs(self: *Caller, info: CallbackInfo) ![]const u8 { fn serializeFunctionArgs(self: *Caller, info: FunctionCallbackInfo) ![]const u8 {
const context = self.context; const context = self.context;
var buf = std.Io.Writer.Allocating.init(context.call_arena); var buf = std.Io.Writer.Allocating.init(context.call_arena);
@@ -618,7 +624,7 @@ pub fn Builder(comptime T: type) type {
} }
pub const Constructor = struct { pub const Constructor = struct {
func: *const fn (?*const v8.C_FunctionCallbackInfo) callconv(.c) void, func: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void,
const Opts = struct { const Opts = struct {
dom_exception: bool = false, dom_exception: bool = false,
@@ -626,12 +632,12 @@ pub const Constructor = struct {
fn init(comptime T: type, comptime func: anytype, comptime opts: Opts) Constructor { fn init(comptime T: type, comptime func: anytype, comptime opts: Opts) Constructor {
return .{ .func = struct { return .{ .func = struct {
fn wrap(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void { fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(raw_info).?; const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?;
var caller = Caller.init(v8_isolate); var caller = Caller.init(v8_isolate);
defer caller.deinit(); defer caller.deinit();
const info = CallbackInfo{ .raw = raw_info.? }; const info = FunctionCallbackInfo{ .handle = handle.? };
caller.constructor(T, func, info, .{ caller.constructor(T, func, info, .{
.dom_exception = opts.dom_exception, .dom_exception = opts.dom_exception,
}); });
@@ -642,7 +648,7 @@ pub const Constructor = struct {
pub const Function = struct { pub const Function = struct {
static: bool, static: bool,
func: *const fn (?*const v8.C_FunctionCallbackInfo) callconv(.c) void, func: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void,
const Opts = struct { const Opts = struct {
static: bool = false, static: bool = false,
@@ -655,12 +661,12 @@ pub const Function = struct {
return .{ return .{
.static = opts.static, .static = opts.static,
.func = struct { .func = struct {
fn wrap(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void { fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(raw_info).?; const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?;
var caller = Caller.init(v8_isolate); var caller = Caller.init(v8_isolate);
defer caller.deinit(); defer caller.deinit();
const info = CallbackInfo{ .raw = raw_info.? }; const info = FunctionCallbackInfo{ .handle = handle.? };
if (comptime opts.static) { if (comptime opts.static) {
caller.function(T, func, info, .{ caller.function(T, func, info, .{
.dom_exception = opts.dom_exception, .dom_exception = opts.dom_exception,
@@ -682,8 +688,8 @@ pub const Function = struct {
pub const Accessor = struct { pub const Accessor = struct {
static: bool = false, static: bool = false,
getter: ?*const fn (?*const v8.C_FunctionCallbackInfo) callconv(.c) void = null, getter: ?*const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void = null,
setter: ?*const fn (?*const v8.C_FunctionCallbackInfo) callconv(.c) void = null, setter: ?*const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void = null,
const Opts = struct { const Opts = struct {
static: bool = false, static: bool = false,
@@ -699,12 +705,12 @@ pub const Accessor = struct {
if (@typeInfo(@TypeOf(getter)) != .null) { if (@typeInfo(@TypeOf(getter)) != .null) {
accessor.getter = struct { accessor.getter = struct {
fn wrap(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void { fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(raw_info).?; const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?;
var caller = Caller.init(v8_isolate); var caller = Caller.init(v8_isolate);
defer caller.deinit(); defer caller.deinit();
const info = CallbackInfo{ .raw = raw_info.? }; const info = FunctionCallbackInfo{ .handle = handle.? };
caller.method(T, getter, info, .{ caller.method(T, getter, info, .{
.as_typed_array = opts.as_typed_array, .as_typed_array = opts.as_typed_array,
.null_as_undefined = opts.null_as_undefined, .null_as_undefined = opts.null_as_undefined,
@@ -715,12 +721,12 @@ pub const Accessor = struct {
if (@typeInfo(@TypeOf(setter)) != .null) { if (@typeInfo(@TypeOf(setter)) != .null) {
accessor.setter = struct { accessor.setter = struct {
fn wrap(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void { fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(raw_info).?; const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?;
var caller = Caller.init(v8_isolate); var caller = Caller.init(v8_isolate);
defer caller.deinit(); defer caller.deinit();
const info = CallbackInfo{ .raw = raw_info.? }; const info = FunctionCallbackInfo{ .handle = handle.? };
std.debug.assert(info.length() == 1); std.debug.assert(info.length() == 1);
caller.method(T, setter, info, .{ caller.method(T, setter, info, .{
@@ -736,7 +742,7 @@ pub const Accessor = struct {
}; };
pub const Indexed = struct { pub const Indexed = struct {
getter: *const fn (idx: u32, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8, getter: *const fn (idx: u32, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8,
const Opts = struct { const Opts = struct {
as_typed_array: bool = false, as_typed_array: bool = false,
@@ -745,12 +751,12 @@ pub const Indexed = struct {
fn init(comptime T: type, comptime getter: anytype, comptime opts: Opts) Indexed { fn init(comptime T: type, comptime getter: anytype, comptime opts: Opts) Indexed {
return .{ .getter = struct { return .{ .getter = struct {
fn wrap(idx: u32, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 { fn wrap(idx: u32, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 {
const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(raw_info).?; const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(handle).?;
var caller = Caller.init(v8_isolate); var caller = Caller.init(v8_isolate);
defer caller.deinit(); defer caller.deinit();
const info = PropertyCallbackInfo{ .raw = raw_info.? }; const info = PropertyCallbackInfo{ .handle = handle.? };
return caller.getIndex(T, getter, idx, info, .{ return caller.getIndex(T, getter, idx, info, .{
.as_typed_array = opts.as_typed_array, .as_typed_array = opts.as_typed_array,
.null_as_undefined = opts.null_as_undefined, .null_as_undefined = opts.null_as_undefined,
@@ -761,9 +767,9 @@ pub const Indexed = struct {
}; };
pub const NamedIndexed = struct { pub const NamedIndexed = struct {
getter: *const fn (c_name: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8, getter: *const fn (c_name: ?*const v8.c.Name, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8,
setter: ?*const fn (c_name: ?*const v8.C_Name, c_value: ?*const v8.C_Value, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 = null, setter: ?*const fn (c_name: ?*const v8.c.Name, c_value: ?*const v8.c.Value, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 = null,
deleter: ?*const fn (c_name: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 = null, deleter: ?*const fn (c_name: ?*const v8.c.Name, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 = null,
const Opts = struct { const Opts = struct {
as_typed_array: bool = false, as_typed_array: bool = false,
@@ -772,12 +778,12 @@ pub const NamedIndexed = struct {
fn init(comptime T: type, comptime getter: anytype, setter: anytype, deleter: anytype, comptime opts: Opts) NamedIndexed { fn init(comptime T: type, comptime getter: anytype, setter: anytype, deleter: anytype, comptime opts: Opts) NamedIndexed {
const getter_fn = struct { const getter_fn = struct {
fn wrap(c_name: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 { fn wrap(c_name: ?*const v8.c.Name, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 {
const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(raw_info).?; const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(handle).?;
var caller = Caller.init(v8_isolate); var caller = Caller.init(v8_isolate);
defer caller.deinit(); defer caller.deinit();
const info = PropertyCallbackInfo{ .raw = raw_info.? }; const info = PropertyCallbackInfo{ .handle = handle.? };
return caller.getNamedIndex(T, getter, .{ .handle = c_name.? }, info, .{ return caller.getNamedIndex(T, getter, .{ .handle = c_name.? }, info, .{
.as_typed_array = opts.as_typed_array, .as_typed_array = opts.as_typed_array,
.null_as_undefined = opts.null_as_undefined, .null_as_undefined = opts.null_as_undefined,
@@ -786,12 +792,12 @@ pub const NamedIndexed = struct {
}.wrap; }.wrap;
const setter_fn = if (@typeInfo(@TypeOf(setter)) == .null) null else struct { const setter_fn = if (@typeInfo(@TypeOf(setter)) == .null) null else struct {
fn wrap(c_name: ?*const v8.C_Name, c_value: ?*const v8.C_Value, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 { fn wrap(c_name: ?*const v8.c.Name, c_value: ?*const v8.c.Value, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 {
const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(raw_info).?; const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(handle).?;
var caller = Caller.init(v8_isolate); var caller = Caller.init(v8_isolate);
defer caller.deinit(); defer caller.deinit();
const info = PropertyCallbackInfo{ .raw = raw_info.? }; const info = PropertyCallbackInfo{ .handle = handle.? };
return caller.setNamedIndex(T, setter, .{ .handle = c_name.? }, .{ .handle = c_value.? }, info, .{ return caller.setNamedIndex(T, setter, .{ .handle = c_name.? }, .{ .handle = c_value.? }, info, .{
.as_typed_array = opts.as_typed_array, .as_typed_array = opts.as_typed_array,
.null_as_undefined = opts.null_as_undefined, .null_as_undefined = opts.null_as_undefined,
@@ -800,12 +806,12 @@ pub const NamedIndexed = struct {
}.wrap; }.wrap;
const deleter_fn = if (@typeInfo(@TypeOf(deleter)) == .null) null else struct { const deleter_fn = if (@typeInfo(@TypeOf(deleter)) == .null) null else struct {
fn wrap(c_name: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 { fn wrap(c_name: ?*const v8.c.Name, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 {
const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(raw_info).?; const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(handle).?;
var caller = Caller.init(v8_isolate); var caller = Caller.init(v8_isolate);
defer caller.deinit(); defer caller.deinit();
const info = PropertyCallbackInfo{ .raw = raw_info.? }; const info = PropertyCallbackInfo{ .handle = handle.? };
return caller.deleteNamedIndex(T, deleter, .{ .handle = c_name.? }, info, .{ return caller.deleteNamedIndex(T, deleter, .{ .handle = c_name.? }, info, .{
.as_typed_array = opts.as_typed_array, .as_typed_array = opts.as_typed_array,
.null_as_undefined = opts.null_as_undefined, .null_as_undefined = opts.null_as_undefined,
@@ -822,7 +828,7 @@ pub const NamedIndexed = struct {
}; };
pub const Iterator = struct { pub const Iterator = struct {
func: *const fn (?*const v8.C_FunctionCallbackInfo) callconv(.c) void, func: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void,
async: bool, async: bool,
const Opts = struct { const Opts = struct {
@@ -835,8 +841,8 @@ pub const Iterator = struct {
return .{ return .{
.async = opts.async, .async = opts.async,
.func = struct { .func = struct {
fn wrap(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void { fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
const info = v8.FunctionCallbackInfo.initFromV8(raw_info); const info = FunctionCallbackInfo{ .handle = handle.? };
info.getReturnValue().set(info.getThis()); info.getReturnValue().set(info.getThis());
} }
}.wrap, }.wrap,
@@ -846,12 +852,12 @@ pub const Iterator = struct {
return .{ return .{
.async = opts.async, .async = opts.async,
.func = struct { .func = struct {
fn wrap(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void { fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(raw_info).?; const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?;
var caller = Caller.init(v8_isolate); var caller = Caller.init(v8_isolate);
defer caller.deinit(); defer caller.deinit();
const info = CallbackInfo{ .raw = raw_info.? }; const info = FunctionCallbackInfo{ .handle = handle.? };
caller.method(T, struct_or_func, info, .{}); caller.method(T, struct_or_func, info, .{});
} }
}.wrap, }.wrap,
@@ -860,7 +866,7 @@ pub const Iterator = struct {
}; };
pub const Callable = struct { pub const Callable = struct {
func: *const fn (?*const v8.C_FunctionCallbackInfo) callconv(.c) void, func: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void,
const Opts = struct { const Opts = struct {
null_as_undefined: bool = false, null_as_undefined: bool = false,
@@ -868,12 +874,12 @@ pub const Callable = struct {
fn init(comptime T: type, comptime func: anytype, comptime opts: Opts) Callable { fn init(comptime T: type, comptime func: anytype, comptime opts: Opts) Callable {
return .{ .func = struct { return .{ .func = struct {
fn wrap(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void { fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(raw_info).?; const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?;
var caller = Caller.init(v8_isolate); var caller = Caller.init(v8_isolate);
defer caller.deinit(); defer caller.deinit();
const info = CallbackInfo{ .raw = raw_info.? }; const info = FunctionCallbackInfo{ .handle = handle.? };
caller.method(T, func, info, .{ caller.method(T, func, info, .{
.null_as_undefined = opts.null_as_undefined, .null_as_undefined = opts.null_as_undefined,
}); });

View File

@@ -368,7 +368,7 @@ pub const PrototypeChainEntry = struct {
// point of view, is an arbitrary string. // point of view, is an arbitrary string.
pub export fn v8_inspector__Client__IMPL__valueSubtype( pub export fn v8_inspector__Client__IMPL__valueSubtype(
_: *v8.c.InspectorClientImpl, _: *v8.c.InspectorClientImpl,
c_value: *const v8.C_Value, c_value: *const v8.c.Value,
) callconv(.c) [*c]const u8 { ) callconv(.c) [*c]const u8 {
const external_entry = Inspector.getTaggedAnyOpaque(c_value) orelse return null; const external_entry = Inspector.getTaggedAnyOpaque(c_value) orelse return null;
return if (external_entry.subtype) |st| @tagName(st) else null; return if (external_entry.subtype) |st| @tagName(st) else null;
@@ -380,8 +380,8 @@ pub export fn v8_inspector__Client__IMPL__valueSubtype(
// put an empty description. // put an empty description.
pub export fn v8_inspector__Client__IMPL__descriptionForValueSubtype( pub export fn v8_inspector__Client__IMPL__descriptionForValueSubtype(
_: *v8.c.InspectorClientImpl, _: *v8.c.InspectorClientImpl,
v8_context: *const v8.C_Context, v8_context: *const v8.c.Context,
c_value: *const v8.C_Value, c_value: *const v8.c.Value,
) callconv(.c) [*c]const u8 { ) callconv(.c) [*c]const u8 {
_ = v8_context; _ = v8_context;

View File

@@ -275,12 +275,10 @@ fn resolveNode(cmd: anytype) !void {
var js_context = page.js; var js_context = page.js;
if (params.executionContextId) |context_id| { if (params.executionContextId) |context_id| {
const v8_context = v8.Context{ .handle = js_context.handle }; if (js_context.debugContextId() != context_id) {
if (v8_context.debugContextId() != context_id) {
for (bc.isolated_worlds.items) |*isolated_world| { for (bc.isolated_worlds.items) |*isolated_world| {
js_context = &(isolated_world.executor.context orelse return error.ContextNotFound); js_context = &(isolated_world.executor.context orelse return error.ContextNotFound);
const isolated_v8_context = v8.Context{ .handle = js_context.handle }; if (js_context.debugContextId() == context_id) {
if (isolated_v8_context.debugContextId() == context_id) {
break; break;
} }
} else return error.ContextNotFound; } else return error.ContextNotFound;

View File

@@ -196,8 +196,7 @@ fn createIsolatedWorld(cmd: anytype) !void {
const aux_data = try std.fmt.allocPrint(cmd.arena, "{{\"isDefault\":false,\"type\":\"isolated\",\"frameId\":\"{s}\"}}", .{params.frameId}); const aux_data = try std.fmt.allocPrint(cmd.arena, "{{\"isDefault\":false,\"type\":\"isolated\",\"frameId\":\"{s}\"}}", .{params.frameId});
bc.inspector.contextCreated(js_context, world.name, "", aux_data, false); bc.inspector.contextCreated(js_context, world.name, "", aux_data, false);
const v8_context = v8.Context{ .handle = js_context.handle }; return cmd.sendResult(.{ .executionContextId = js_context.debugContextId() }, .{});
return cmd.sendResult(.{ .executionContextId = v8_context.debugContextId() }, .{});
} }
fn navigate(cmd: anytype) !void { fn navigate(cmd: anytype) !void {