diff --git a/src/browser/js/Array.zig b/src/browser/js/Array.zig index 9596ca4c..98442468 100644 --- a/src/browser/js/Array.zig +++ b/src/browser/js/Array.zig @@ -23,17 +23,17 @@ const v8 = js.v8; const Array = @This(); ctx: *js.Context, -handle: *const v8.c.Array, +handle: *const v8.Array, pub fn len(self: Array) usize { - return v8.c.v8__Array__Length(self.handle); + return v8.v8__Array__Length(self.handle); } pub fn get(self: Array, index: u32) !js.Value { const ctx = self.ctx; const idx = js.Integer.init(ctx.isolate.handle, index); - const handle = v8.c.v8__Object__Get(@ptrCast(self.handle), ctx.handle, idx.handle) orelse { + const handle = v8.v8__Object__Get(@ptrCast(self.handle), ctx.handle, idx.handle) orelse { return error.JsException; }; @@ -48,8 +48,8 @@ pub fn set(self: Array, index: u32, value: anytype, comptime opts: js.bridge.Cal const js_value = try ctx.zigValueToJs(value, opts); - var out: v8.c.MaybeBool = undefined; - v8.c.v8__Object__SetAtIndex(@ptrCast(self.handle), ctx.handle, index, js_value.handle, &out); + var out: v8.MaybeBool = undefined; + v8.v8__Object__SetAtIndex(@ptrCast(self.handle), ctx.handle, index, js_value.handle, &out); return out.has_value; } diff --git a/src/browser/js/BigInt.zig b/src/browser/js/BigInt.zig index 16bab38d..5443d69a 100644 --- a/src/browser/js/BigInt.zig +++ b/src/browser/js/BigInt.zig @@ -21,23 +21,23 @@ const v8 = js.v8; const BigInt = @This(); -handle: *const v8.c.Integer, +handle: *const v8.Integer, -pub fn init(isolate: *v8.c.Isolate, val: anytype) BigInt { +pub fn init(isolate: *v8.Isolate, val: anytype) BigInt { const handle = switch (@TypeOf(val)) { - i8, i16, i32, i64, isize => v8.c.v8__BigInt__New(isolate, val).?, - u8, u16, u32, u64, usize => v8.c.v8__BigInt__NewFromUnsigned(isolate, val).?, + i8, i16, i32, i64, isize => v8.v8__BigInt__New(isolate, val).?, + u8, u16, u32, u64, usize => v8.v8__BigInt__NewFromUnsigned(isolate, val).?, else => |T| @compileError("cannot create v8::BigInt from: " ++ @typeName(T)), }; return .{ .handle = handle }; } pub fn getInt64(self: BigInt) i64 { - return v8.c.v8__BigInt__Int64Value(self.handle, null); + return v8.v8__BigInt__Int64Value(self.handle, null); } pub fn getUint64(self: BigInt) u64 { - return v8.c.v8__BigInt__Uint64Value(self.handle, null); + return v8.v8__BigInt__Uint64Value(self.handle, null); } pub fn toValue(self: BigInt) js.Value { diff --git a/src/browser/js/Context.zig b/src/browser/js/Context.zig index d67fb60d..d55b62d2 100644 --- a/src/browser/js/Context.zig +++ b/src/browser/js/Context.zig @@ -41,14 +41,14 @@ id: usize, page: *Page, isolate: js.Isolate, // This context is a persistent object. The persistent needs to be recovered and reset. -handle: *const v8.c.Context, +handle: *const v8.Context, handle_scope: ?js.HandleScope, -cpu_profiler: ?*v8.c.CpuProfiler = null, +cpu_profiler: ?*v8.CpuProfiler = null, // references Env.templates -templates: []*const v8.c.FunctionTemplate, +templates: []*const v8.FunctionTemplate, // Arena for the lifetime of the context arena: Allocator, @@ -115,21 +115,21 @@ const ModuleEntry = struct { resolver_promise: ?js.Promise = null, }; -pub fn fromC(c_context: *const v8.c.Context) *Context { - const data = v8.c.v8__Context__GetEmbedderData(c_context, 1).?; +pub fn fromC(c_context: *const v8.Context) *Context { + const data = v8.v8__Context__GetEmbedderData(c_context, 1).?; const big_int = js.BigInt{ .handle = @ptrCast(data) }; return @ptrFromInt(big_int.getUint64()); } pub fn fromIsolate(isolate: js.Isolate) *Context { - const v8_context = v8.c.v8__Isolate__GetCurrentContext(isolate.handle).?; - const data = v8.c.v8__Context__GetEmbedderData(v8_context, 1).?; + const v8_context = v8.v8__Isolate__GetCurrentContext(isolate.handle).?; + const data = v8.v8__Context__GetEmbedderData(v8_context, 1).?; const big_int = js.BigInt{ .handle = @ptrCast(data) }; return @ptrFromInt(big_int.getUint64()); } pub fn setupGlobal(self: *Context) !void { - const global = v8.c.v8__Context__Global(self.handle).?; + const global = v8.v8__Context__Global(self.handle).?; _ = try self.mapZigInstanceToJs(global, self.page.window); } @@ -167,7 +167,7 @@ pub fn deinit(self: *Context) void { if (self.handle_scope) |*scope| { scope.deinit(); - v8.c.v8__Context__Exit(self.handle); + v8.v8__Context__Exit(self.handle); } } @@ -333,20 +333,20 @@ pub fn newString(self: *Context, str: []const u8) js.String { pub fn newObject(self: *Context) js.Object { return .{ .ctx = self, - .handle = v8.c.v8__Object__New(self.isolate.handle).?, + .handle = v8.v8__Object__New(self.isolate.handle).?, }; } pub fn newArray(self: *Context, len: u32) js.Array { return .{ .ctx = self, - .handle = v8.c.v8__Array__New(self.isolate.handle, @intCast(len)).?, + .handle = v8.v8__Array__New(self.isolate.handle, @intCast(len)).?, }; } -fn newFunctionWithData(self: *Context, comptime callback: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void, data: *anyopaque) js.Function { +fn newFunctionWithData(self: *Context, comptime callback: *const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void, data: *anyopaque) js.Function { const external = self.isolate.createExternal(data); - const handle = v8.c.v8__Function__New__DEFAULT2(self.handle, callback, @ptrCast(external)).?; + const handle = v8.v8__Function__New__DEFAULT2(self.handle, callback, @ptrCast(external)).?; return .{ .ctx = self, .handle = handle, @@ -355,7 +355,7 @@ fn newFunctionWithData(self: *Context, comptime callback: *const fn (?*const v8. pub fn parseJSON(self: *Context, json: []const u8) !js.Value { const string_handle = self.isolate.initStringHandle(json); - const value_handle = v8.c.v8__JSON__Parse(self.handle, string_handle) orelse return error.JsException; + const value_handle = v8.v8__JSON__Parse(self.handle, string_handle) orelse return error.JsException; return .{ .ctx = self, .handle = value_handle, @@ -371,7 +371,7 @@ 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); + return v8.v8__Context__DebugContextId(self.handle); } pub fn zigValueToJs(self: *Context, value: anytype, comptime opts: Caller.CallOpts) !js.Value { @@ -538,7 +538,7 @@ pub fn zigValueToJs(self: *Context, value: anytype, comptime opts: Caller.CallOp // 4 - Store our TaggedAnyOpaque into the persistent object // 5 - Update our identity_map (so that, if we return this same instance again, // we can just grab it from the identity_map) -pub fn mapZigInstanceToJs(self: *Context, js_obj_handle: ?*const v8.c.Object, value: anytype) !js.Object { +pub fn mapZigInstanceToJs(self: *Context, js_obj_handle: ?*const v8.Object, value: anytype) !js.Object { const arena = self.arena; const T = @TypeOf(value); @@ -572,8 +572,8 @@ pub fn mapZigInstanceToJs(self: *Context, js_obj_handle: ?*const v8.c.Object, va .ctx = self, .handle = js_obj_handle orelse blk: { const function_template_handle = self.templates[resolved.class_id]; - const object_template_handle = v8.c.v8__FunctionTemplate__InstanceTemplate(function_template_handle).?; - break :blk v8.c.v8__ObjectTemplate__NewInstance(object_template_handle, self.handle).?; + const object_template_handle = v8.v8__FunctionTemplate__InstanceTemplate(function_template_handle).?; + break :blk v8.v8__ObjectTemplate__NewInstance(object_template_handle, self.handle).?; }, }; @@ -592,7 +592,7 @@ pub fn mapZigInstanceToJs(self: *Context, js_obj_handle: ?*const v8.c.Object, va // Skip setting internal field for the global object (Window) // Window accessors get the instance from context.page.window instead if (resolved.class_id != @import("../webapi/Window.zig").JsApi.Meta.class_id) { - v8.c.v8__Object__SetInternalField(js_obj.handle, 0, isolate.createExternal(tao)); + v8.v8__Object__SetInternalField(js_obj.handle, 0, isolate.createExternal(tao)); } } else { // If the struct is empty, we don't need to do all @@ -835,31 +835,31 @@ fn jsValueToStruct(self: *Context, comptime T: type, js_value: js.Value) !?T { fn jsValueToTypedArray(_: *Context, comptime T: type, js_value: js.Value) !?[]T { var force_u8 = false; - var array_buffer: ?*const v8.c.ArrayBuffer = null; + var array_buffer: ?*const v8.ArrayBuffer = null; var byte_len: usize = undefined; var byte_offset: usize = undefined; if (js_value.isTypedArray()) { - const buffer_handle: *const v8.c.ArrayBufferView = @ptrCast(js_value.handle); - byte_len = v8.c.v8__ArrayBufferView__ByteLength(buffer_handle); - byte_offset = v8.c.v8__ArrayBufferView__ByteOffset(buffer_handle); - array_buffer = v8.c.v8__ArrayBufferView__Buffer(buffer_handle).?; + const buffer_handle: *const v8.ArrayBufferView = @ptrCast(js_value.handle); + byte_len = v8.v8__ArrayBufferView__ByteLength(buffer_handle); + byte_offset = v8.v8__ArrayBufferView__ByteOffset(buffer_handle); + array_buffer = v8.v8__ArrayBufferView__Buffer(buffer_handle).?; } else if (js_value.isArrayBufferView()) { force_u8 = true; - const buffer_handle: *const v8.c.ArrayBufferView = @ptrCast(js_value.handle); - byte_len = v8.c.v8__ArrayBufferView__ByteLength(buffer_handle); - byte_offset = v8.c.v8__ArrayBufferView__ByteOffset(buffer_handle); - array_buffer = v8.c.v8__ArrayBufferView__Buffer(buffer_handle).?; + const buffer_handle: *const v8.ArrayBufferView = @ptrCast(js_value.handle); + byte_len = v8.v8__ArrayBufferView__ByteLength(buffer_handle); + byte_offset = v8.v8__ArrayBufferView__ByteOffset(buffer_handle); + array_buffer = v8.v8__ArrayBufferView__Buffer(buffer_handle).?; } else if (js_value.isArrayBuffer()) { force_u8 = true; array_buffer = @ptrCast(js_value.handle); - byte_len = v8.c.v8__ArrayBuffer__ByteLength(array_buffer); + byte_len = v8.v8__ArrayBuffer__ByteLength(array_buffer); byte_offset = 0; } - const backing_store_ptr = v8.c.v8__ArrayBuffer__GetBackingStore(array_buffer orelse return null); - const backing_store_handle = v8.c.std__shared_ptr__v8__BackingStore__get(&backing_store_ptr).?; - const data = v8.c.v8__BackingStore__Data(backing_store_handle); + const backing_store_ptr = v8.v8__ArrayBuffer__GetBackingStore(array_buffer orelse return null); + const backing_store_handle = v8.std__shared_ptr__v8__BackingStore__get(&backing_store_ptr).?; + const data = v8.v8__BackingStore__Data(backing_store_handle); switch (T) { u8 => { @@ -979,11 +979,11 @@ pub fn valueToStringZ(self: *Context, js_val: js.Value, opts: ToStringOpts) ![:0 fn _valueToString(self: *Context, comptime null_terminate: bool, js_val: js.Value, opts: ToStringOpts) !(if (null_terminate) [:0]u8 else []u8) { if (js_val.isSymbol()) { - const symbol_handle = v8.c.v8__Symbol__Description(@ptrCast(js_val.handle), self.isolate.handle).?; + const symbol_handle = v8.v8__Symbol__Description(@ptrCast(js_val.handle), self.isolate.handle).?; return self._valueToString(null_terminate, .{ .ctx = self, .handle = symbol_handle }, opts); } - const string_handle = v8.c.v8__Value__ToString(js_val.handle, self.handle) orelse { + const string_handle = v8.v8__Value__ToString(js_val.handle, self.handle) orelse { return error.JsException; }; @@ -1002,10 +1002,10 @@ pub fn jsStringToZigZ(self: *const Context, str: anytype, opts: ToStringOpts) ![ fn _jsStringToZig(self: *const Context, comptime null_terminate: bool, str: anytype, opts: ToStringOpts) !(if (null_terminate) [:0]u8 else []u8) { const handle = if (@TypeOf(str) == js.String) str.handle else str; - const len = v8.c.v8__String__Utf8Length(handle, self.isolate.handle); + const len = v8.v8__String__Utf8Length(handle, self.isolate.handle); const allocator = opts.allocator orelse self.call_arena; const buf = try (if (comptime null_terminate) allocator.allocSentinel(u8, @intCast(len), 0) else allocator.alloc(u8, @intCast(len))); - const n = v8.c.v8__String__WriteUtf8(handle, self.isolate.handle, buf.ptr, buf.len, v8.c.NO_NULL_TERMINATION | v8.c.REPLACE_INVALID_UTF8); + const n = v8.v8__String__WriteUtf8(handle, self.isolate.handle, buf.ptr, buf.len, v8.NO_NULL_TERMINATION | v8.REPLACE_INVALID_UTF8); std.debug.assert(n == len); return buf; @@ -1037,7 +1037,7 @@ fn _debugValue(self: *Context, js_val: js.Value, seen: *std.AutoHashMapUnmanaged } if (js_val.isSymbol()) { - const symbol_handle = v8.c.v8__Symbol__Description(@ptrCast(js_val.handle), self.isolate.handle).?; + const symbol_handle = v8.v8__Symbol__Description(@ptrCast(js_val.handle), self.isolate.handle).?; const js_sym_str = try self.valueToString(.{ .ctx = self, .handle = symbol_handle }, .{}); return writer.print("{s} (symbol)", .{js_sym_str}); } @@ -1108,20 +1108,20 @@ pub fn stackTrace(self: *const Context) !?[]const u8 { var buf: std.ArrayList(u8) = .empty; var writer = buf.writer(self.call_arena); - const stack_trace_handle = v8.c.v8__StackTrace__CurrentStackTrace__STATIC(isolate.handle, 30).?; - const frame_count = v8.c.v8__StackTrace__GetFrameCount(stack_trace_handle); + const stack_trace_handle = v8.v8__StackTrace__CurrentStackTrace__STATIC(isolate.handle, 30).?; + const frame_count = v8.v8__StackTrace__GetFrameCount(stack_trace_handle); - if (v8.c.v8__StackTrace__CurrentScriptNameOrSourceURL__STATIC(isolate.handle)) |script| { + if (v8.v8__StackTrace__CurrentScriptNameOrSourceURL__STATIC(isolate.handle)) |script| { try writer.print("{s}<{s}>", .{ separator, try self.jsStringToZig(script, .{}) }); } for (0..@intCast(frame_count)) |i| { - const frame_handle = v8.c.v8__StackTrace__GetFrame(stack_trace_handle, isolate.handle, @intCast(i)).?; - if (v8.c.v8__StackFrame__GetFunctionName(frame_handle)) |name| { + const frame_handle = v8.v8__StackTrace__GetFrame(stack_trace_handle, isolate.handle, @intCast(i)).?; + if (v8.v8__StackFrame__GetFunctionName(frame_handle)) |name| { const script = try self.jsStringToZig(name, .{}); - try writer.print("{s}{s}:{d}", .{ separator, script, v8.c.v8__StackFrame__GetLineNumber(frame_handle) }); + try writer.print("{s}{s}:{d}", .{ separator, script, v8.v8__StackFrame__GetLineNumber(frame_handle) }); } else { - try writer.print("{s}:{d}", .{ separator, v8.c.v8__StackFrame__GetLineNumber(frame_handle) }); + try writer.print("{s}:{d}", .{ separator, v8.v8__StackFrame__GetLineNumber(frame_handle) }); } } return buf.items; @@ -1152,11 +1152,11 @@ pub fn createPromiseResolver(self: *Context) js.PromiseResolver { // Callback from V8, asking us to load a module. The "specifier" is // the src of the module to load. fn resolveModuleCallback( - c_context: ?*const v8.c.Context, - c_specifier: ?*const v8.c.String, - import_attributes: ?*const v8.c.FixedArray, - c_referrer: ?*const v8.c.Module, -) callconv(.c) ?*const v8.c.Module { + c_context: ?*const v8.Context, + c_specifier: ?*const v8.String, + import_attributes: ?*const v8.FixedArray, + c_referrer: ?*const v8.Module, +) callconv(.c) ?*const v8.Module { _ = import_attributes; const self = fromC(c_context.?); @@ -1177,12 +1177,12 @@ fn resolveModuleCallback( } pub fn dynamicModuleCallback( - c_context: ?*const v8.c.Context, - host_defined_options: ?*const v8.c.Data, - resource_name: ?*const v8.c.Value, - v8_specifier: ?*const v8.c.String, - import_attrs: ?*const v8.c.FixedArray, -) callconv(.c) ?*v8.c.Promise { + c_context: ?*const v8.Context, + host_defined_options: ?*const v8.Data, + resource_name: ?*const v8.Value, + v8_specifier: ?*const v8.String, + import_attrs: ?*const v8.FixedArray, +) callconv(.c) ?*v8.Promise { _ = host_defined_options; _ = import_attrs; @@ -1216,7 +1216,7 @@ pub fn dynamicModuleCallback( 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.Context, c_module: ?*v8.Module, c_meta: ?*v8.Value) callconv(.c) void { const self = fromC(c_context.?); const m = js.Module{ .ctx = self, .handle = c_module.? }; const meta = js.Object{ .ctx = self, .handle = @ptrCast(c_meta.?) }; @@ -1237,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.Module { const referrer_path = self.module_identifier.get(referrer.getIdentityHash()) orelse { // Shouldn't be possible. return error.UnknownModuleReferrer; @@ -1420,13 +1420,13 @@ fn resolveDynamicModule(self: *Context, state: *DynamicModuleResolveState, modul // resolve to the module's namespace. const then_callback = self.newFunctionWithData(struct { - pub fn callback(callback_handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void { - const isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(callback_handle).?; + pub fn callback(callback_handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void { + const isolate = v8.v8__FunctionCallbackInfo__GetIsolate(callback_handle).?; var caller = Caller.init(isolate); defer caller.deinit(); - const info_data = v8.c.v8__FunctionCallbackInfo__Data(callback_handle).?; - const s: *DynamicModuleResolveState = @ptrCast(@alignCast(v8.c.v8__External__Value(@ptrCast(info_data)))); + const info_data = v8.v8__FunctionCallbackInfo__Data(callback_handle).?; + const s: *DynamicModuleResolveState = @ptrCast(@alignCast(v8.v8__External__Value(@ptrCast(info_data)))); if (s.context_id != caller.context.id) { // The microtask is tied to the isolate, not the context @@ -1444,13 +1444,13 @@ fn resolveDynamicModule(self: *Context, state: *DynamicModuleResolveState, modul }.callback, @ptrCast(state)); const catch_callback = self.newFunctionWithData(struct { - pub fn callback(callback_handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void { - const isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(callback_handle).?; + pub fn callback(callback_handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void { + const isolate = v8.v8__FunctionCallbackInfo__GetIsolate(callback_handle).?; var caller = Caller.init(isolate); defer caller.deinit(); - const info_data = v8.c.v8__FunctionCallbackInfo__Data(callback_handle).?; - const s: *DynamicModuleResolveState = @ptrCast(@alignCast(v8.c.v8__External__Value(@ptrCast(info_data)))); + const info_data = v8.v8__FunctionCallbackInfo__Data(callback_handle).?; + const s: *DynamicModuleResolveState = @ptrCast(@alignCast(v8.v8__External__Value(@ptrCast(info_data)))); const ctx = caller.context; if (s.context_id != ctx.id) { @@ -1460,7 +1460,7 @@ fn resolveDynamicModule(self: *Context, state: *DynamicModuleResolveState, modul defer ctx.runMicrotasks(); _ = s.resolver.reject("catch callback", js.Value{ .ctx = ctx, - .handle = v8.c.v8__FunctionCallbackInfo__Data(callback_handle).?, + .handle = v8.v8__FunctionCallbackInfo__Data(callback_handle).?, }); } }.callback, @ptrCast(state)); @@ -1478,7 +1478,7 @@ fn resolveDynamicModule(self: *Context, state: *DynamicModuleResolveState, modul // Reverses the mapZigInstanceToJs, making sure that our TaggedAnyOpaque // contains a ptr to the correct type. -pub fn typeTaggedAnyOpaque(comptime R: type, js_obj_handle: *const v8.c.Object) !R { +pub fn typeTaggedAnyOpaque(comptime R: type, js_obj_handle: *const v8.Object) !R { const ti = @typeInfo(R); if (ti != .pointer) { @compileError("non-pointer Zig parameter type: " ++ @typeName(R)); @@ -1494,14 +1494,14 @@ pub fn typeTaggedAnyOpaque(comptime R: type, js_obj_handle: *const v8.c.Object) return @constCast(@as(*const T, &.{})); } - const internal_field_count = v8.c.v8__Object__InternalFieldCount(js_obj_handle); + const internal_field_count = v8.v8__Object__InternalFieldCount(js_obj_handle); // Special case for Window: the global object doesn't have internal fields // Window instance is stored in context.page.window instead if (internal_field_count == 0) { // Normally, this would be an error. All JsObject that map to a Zig type // are either `empty_with_no_proto` (handled above) or have an // interalFieldCount. The only exception to that is the Window... - const isolate = v8.c.v8__Object__GetIsolate(js_obj_handle).?; + const isolate = v8.v8__Object__GetIsolate(js_obj_handle).?; const context = fromIsolate(.{ .handle = isolate }); const Window = @import("../webapi/Window.zig"); @@ -1533,8 +1533,8 @@ pub fn typeTaggedAnyOpaque(comptime R: type, js_obj_handle: *const v8.c.Object) @compileError("unknown Zig type: " ++ @typeName(R)); } - const internal_field_handle = v8.c.v8__Object__GetInternalField(js_obj_handle, 0).?; - const tao: *TaggedAnyOpaque = @ptrCast(@alignCast(v8.c.v8__External__Value(internal_field_handle))); + const internal_field_handle = v8.v8__Object__GetInternalField(js_obj_handle, 0).?; + const tao: *TaggedAnyOpaque = @ptrCast(@alignCast(v8.v8__External__Value(internal_field_handle))); const expected_type_index = bridge.JsApiLookup.getId(JsApi); const prototype_chain = tao.prototype_chain[0..tao.prototype_len]; @@ -1821,30 +1821,30 @@ fn compileAndRun(self: *Context, src: []const u8, name: ?[]const u8) !js.Value { const script_source = self.isolate.initStringHandle(src); // Create ScriptOrigin - var origin: v8.c.ScriptOrigin = undefined; - v8.c.v8__ScriptOrigin__CONSTRUCT(&origin, @ptrCast(script_name)); + var origin: v8.ScriptOrigin = undefined; + v8.v8__ScriptOrigin__CONSTRUCT(&origin, @ptrCast(script_name)); // Create ScriptCompilerSource - var script_comp_source: v8.c.ScriptCompilerSource = undefined; - v8.c.v8__ScriptCompiler__Source__CONSTRUCT2(script_source, &origin, null, &script_comp_source); - defer v8.c.v8__ScriptCompiler__Source__DESTRUCT(&script_comp_source); + var script_comp_source: v8.ScriptCompilerSource = undefined; + v8.v8__ScriptCompiler__Source__CONSTRUCT2(script_source, &origin, null, &script_comp_source); + defer v8.v8__ScriptCompiler__Source__DESTRUCT(&script_comp_source); // Compile the script - const v8_script = v8.c.v8__ScriptCompiler__Compile( + const v8_script = v8.v8__ScriptCompiler__Compile( self.handle, &script_comp_source, - v8.c.kNoCompileOptions, - v8.c.kNoCacheNoReason, + v8.kNoCompileOptions, + v8.kNoCacheNoReason, ) orelse return error.CompilationError; // Run the script - const result = v8.c.v8__Script__Run(v8_script, self.handle) orelse return error.ExecutionError; + const result = v8.v8__Script__Run(v8_script, self.handle) orelse return error.ExecutionError; return .{ .ctx = self, .handle = result }; } fn compileModule(self: *Context, src: []const u8, name: []const u8) !js.Module { - var origin_handle: v8.c.ScriptOrigin = undefined; - v8.c.v8__ScriptOrigin__CONSTRUCT2( + var origin_handle: v8.ScriptOrigin = undefined; + v8.v8__ScriptOrigin__CONSTRUCT2( &origin_handle, self.isolate.initStringHandle(name), 0, // resource_line_offset @@ -1858,21 +1858,21 @@ fn compileModule(self: *Context, src: []const u8, name: []const u8) !js.Module { null, // host_defined_options ); - var source_handle: v8.c.ScriptCompilerSource = undefined; - v8.c.v8__ScriptCompiler__Source__CONSTRUCT2( + var source_handle: v8.ScriptCompilerSource = undefined; + v8.v8__ScriptCompiler__Source__CONSTRUCT2( self.isolate.initStringHandle(src), &origin_handle, null, // cached data &source_handle, ); - defer v8.c.v8__ScriptCompiler__Source__DESTRUCT(&source_handle); + defer v8.v8__ScriptCompiler__Source__DESTRUCT(&source_handle); - const module_handle = v8.c.v8__ScriptCompiler__CompileModule( + const module_handle = v8.v8__ScriptCompiler__CompileModule( self.isolate.handle, &source_handle, - v8.c.kNoCompileOptions, - v8.c.kNoCacheNoReason, + v8.kNoCompileOptions, + v8.kNoCacheNoReason, ) orelse { return error.JsException; }; @@ -1998,17 +1998,17 @@ pub fn startCpuProfiler(self: *Context) void { } std.debug.assert(self.cpu_profiler == null); - v8.c.v8__CpuProfiler__UseDetailedSourcePositionsForProfiling(self.isolate.handle); + v8.v8__CpuProfiler__UseDetailedSourcePositionsForProfiling(self.isolate.handle); - const cpu_profiler = v8.c.v8__CpuProfiler__Get(self.isolate.handle).?; + const cpu_profiler = v8.v8__CpuProfiler__Get(self.isolate.handle).?; const title = self.isolate.initStringHandle("v8_cpu_profile"); - v8.c.v8__CpuProfiler__StartProfiling(cpu_profiler, title); + v8.v8__CpuProfiler__StartProfiling(cpu_profiler, title); self.cpu_profiler = cpu_profiler; } pub fn stopCpuProfiler(self: *Context) ![]const u8 { const title = self.isolate.initStringHandle("v8_cpu_profile"); - const handle = v8.c.v8__CpuProfiler__StopProfiling(self.cpu_profiler.?, title) orelse return error.NoProfiles; - const string_handle = v8.c.v8__CpuProfile__Serialize(handle, self.isolate.handle) orelse return error.NoProfile; + const handle = v8.v8__CpuProfiler__StopProfiling(self.cpu_profiler.?, title) orelse return error.NoProfiles; + const string_handle = v8.v8__CpuProfile__Serialize(handle, self.isolate.handle) orelse return error.NoProfile; return self.jsStringToZig(string_handle, .{}); } diff --git a/src/browser/js/Env.zig b/src/browser/js/Env.zig index 6a11834a..7962e66d 100644 --- a/src/browser/js/Env.zig +++ b/src/browser/js/Env.zig @@ -49,44 +49,44 @@ platform: *const Platform, isolate: js.Isolate, // just kept around because we need to free it on deinit -isolate_params: *v8.c.CreateParams, +isolate_params: *v8.CreateParams, context_id: usize, // Global handles that need to be freed on deinit -globals: []v8.c.Global, +globals: []v8.Global, // Dynamic slice to avoid circular dependency on JsApis.len at comptime -templates: []*const v8.c.FunctionTemplate, +templates: []*const v8.FunctionTemplate, pub fn init(allocator: Allocator, platform: *const Platform, snapshot: *Snapshot) !Env { - var params = try allocator.create(v8.c.CreateParams); + var params = try allocator.create(v8.CreateParams); errdefer allocator.destroy(params); - v8.c.v8__Isolate__CreateParams__CONSTRUCT(params); + v8.v8__Isolate__CreateParams__CONSTRUCT(params); params.snapshot_blob = @ptrCast(&snapshot.startup_data); - params.array_buffer_allocator = v8.c.v8__ArrayBuffer__Allocator__NewDefaultAllocator().?; - errdefer v8.c.v8__ArrayBuffer__Allocator__DELETE(params.array_buffer_allocator.?); + params.array_buffer_allocator = v8.v8__ArrayBuffer__Allocator__NewDefaultAllocator().?; + errdefer v8.v8__ArrayBuffer__Allocator__DELETE(params.array_buffer_allocator.?); params.external_references = &snapshot.external_references; var isolate = js.Isolate.init(params); errdefer isolate.deinit(); - v8.c.v8__Isolate__SetHostImportModuleDynamicallyCallback(isolate.handle, Context.dynamicModuleCallback); - v8.c.v8__Isolate__SetPromiseRejectCallback(isolate.handle, promiseRejectCallback); - v8.c.v8__Isolate__SetMicrotasksPolicy(isolate.handle, v8.c.kExplicit); + v8.v8__Isolate__SetHostImportModuleDynamicallyCallback(isolate.handle, Context.dynamicModuleCallback); + v8.v8__Isolate__SetPromiseRejectCallback(isolate.handle, promiseRejectCallback); + v8.v8__Isolate__SetMicrotasksPolicy(isolate.handle, v8.kExplicit); isolate.enter(); errdefer isolate.exit(); - v8.c.v8__Isolate__SetHostInitializeImportMetaObjectCallback(isolate.handle, Context.metaObjectCallback); + v8.v8__Isolate__SetHostInitializeImportMetaObjectCallback(isolate.handle, Context.metaObjectCallback); // Allocate arrays dynamically to avoid comptime dependency on JsApis.len - const globals = try allocator.alloc(v8.c.Global, JsApis.len); + const globals = try allocator.alloc(v8.Global, JsApis.len); errdefer allocator.free(globals); - const templates = try allocator.alloc(*const v8.c.FunctionTemplate, JsApis.len); + const templates = try allocator.alloc(*const v8.FunctionTemplate, JsApis.len); errdefer allocator.free(templates); { @@ -95,15 +95,15 @@ pub fn init(allocator: Allocator, platform: *const Platform, snapshot: *Snapshot defer temp_scope.deinit(); const context_handle = isolate.createContextHandle(null, null); - v8.c.v8__Context__Enter(context_handle); - defer v8.c.v8__Context__Exit(context_handle); + v8.v8__Context__Enter(context_handle); + defer v8.v8__Context__Exit(context_handle); inline for (JsApis, 0..) |JsApi, i| { JsApi.Meta.class_id = i; - const data = v8.c.v8__Context__GetDataFromSnapshotOnce(context_handle, snapshot.data_start + i); - const function_handle: *const v8.c.FunctionTemplate = @ptrCast(data); + const data = v8.v8__Context__GetDataFromSnapshotOnce(context_handle, snapshot.data_start + i); + const function_handle: *const v8.FunctionTemplate = @ptrCast(data); // Make function template global/persistent - v8.c.v8__Global__New(isolate.handle, @ptrCast(function_handle), &globals[i]); + v8.v8__Global__New(isolate.handle, @ptrCast(function_handle), &globals[i]); // Extract the local handle from the global for easy access templates[i] = @ptrCast(@alignCast(@as(*const anyopaque, @ptrFromInt(globals[i].data_ptr)))); } @@ -123,14 +123,14 @@ pub fn init(allocator: Allocator, platform: *const Platform, snapshot: *Snapshot pub fn deinit(self: *Env) void { // Free global handles before destroying the isolate for (self.globals) |*global| { - v8.c.v8__Global__Reset(global); + v8.v8__Global__Reset(global); } self.allocator.free(self.globals); self.allocator.free(self.templates); self.isolate.exit(); self.isolate.deinit(); - v8.c.v8__ArrayBuffer__Allocator__DELETE(self.isolate_params.array_buffer_allocator.?); + v8.v8__ArrayBuffer__Allocator__DELETE(self.isolate_params.array_buffer_allocator.?); self.allocator.destroy(self.isolate_params); } @@ -145,11 +145,11 @@ pub fn runMicrotasks(self: *const Env) void { } pub fn pumpMessageLoop(self: *const Env) bool { - return v8.c.v8__Platform__PumpMessageLoop(self.platform.handle, self.isolate.handle, false); + return v8.v8__Platform__PumpMessageLoop(self.platform.handle, self.isolate.handle, false); } pub fn runIdleTasks(self: *const Env) void { - v8.c.v8__Platform__RunIdleTasks(self.platform.handle, self.isolate.handle, 1); + v8.v8__Platform__RunIdleTasks(self.platform.handle, self.isolate.handle, 1); } pub fn newExecutionWorld(self: *Env) !ExecutionWorld { return .{ @@ -191,14 +191,14 @@ 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 }); } -fn promiseRejectCallback(message_handle: v8.c.PromiseRejectMessage) callconv(.c) void { - const promise_handle = v8.c.v8__PromiseRejectMessage__GetPromise(&message_handle).?; - const isolate_handle = v8.c.v8__Object__GetIsolate(@ptrCast(promise_handle)).?; +fn promiseRejectCallback(message_handle: v8.PromiseRejectMessage) callconv(.c) void { + const promise_handle = v8.v8__PromiseRejectMessage__GetPromise(&message_handle).?; + const isolate_handle = v8.v8__Object__GetIsolate(@ptrCast(promise_handle)).?; const js_isolate = js.Isolate{ .handle = isolate_handle }; const context = Context.fromIsolate(js_isolate); const value = - if (v8.c.v8__PromiseRejectMessage__GetValue(&message_handle)) |v8_value| + if (v8.v8__PromiseRejectMessage__GetValue(&message_handle)) |v8_value| context.valueToString(.{ .ctx = context, .handle = v8_value }, .{}) catch |err| @errorName(err) else "no value"; diff --git a/src/browser/js/ExecutionWorld.zig b/src/browser/js/ExecutionWorld.zig index 3ed14760..b8bbbf02 100644 --- a/src/browser/js/ExecutionWorld.zig +++ b/src/browser/js/ExecutionWorld.zig @@ -81,11 +81,12 @@ pub fn createContext(self: *ExecutionWorld, page: *Page, enter: bool) !*Context temp_scope.init(isolate); defer temp_scope.deinit(); + // Getting this into the snapshot is tricky (anything involving the - // global is tricky). Easier to do here. + // global is tricky). Easier to do here const func_tmpl_handle = isolate.createFunctionTemplateHandle(); - const global_template = v8.c.v8__FunctionTemplate__InstanceTemplate(func_tmpl_handle).?; - var configuration: v8.c.NamedPropertyHandlerConfiguration = .{ + const global_template = v8.v8__FunctionTemplate__InstanceTemplate(func_tmpl_handle).?; + var configuration: v8.NamedPropertyHandlerConfiguration = .{ .getter = unknownPropertyCallback, .setter = null, .query = null, @@ -94,9 +95,9 @@ pub fn createContext(self: *ExecutionWorld, page: *Page, enter: bool) !*Context .definer = null, .descriptor = null, .data = null, - .flags = v8.c.kOnlyInterceptStrings | v8.c.kNonMasking, + .flags = v8.kOnlyInterceptStrings | v8.kNonMasking, }; - v8.c.v8__ObjectTemplate__SetNamedHandler(global_template, &configuration); + v8.v8__ObjectTemplate__SetNamedHandler(global_template, &configuration); const context_handle = isolate.createContextHandle(null, null); break :blk js.Global(Context).init(isolate.handle, context_handle); @@ -110,10 +111,10 @@ pub fn createContext(self: *ExecutionWorld, page: *Page, enter: bool) !*Context if (enter) { handle_scope = @as(js.HandleScope, undefined); handle_scope.?.init(isolate); - v8.c.v8__Context__Enter(v8_context); + v8.v8__Context__Enter(v8_context); } errdefer if (enter) { - v8.c.v8__Context__Exit(v8_context); + v8.v8__Context__Exit(v8_context); handle_scope.?.deinit(); }; @@ -137,7 +138,7 @@ pub fn createContext(self: *ExecutionWorld, page: *Page, enter: bool) !*Context // Store a pointer to our context inside the v8 context so that, given // a v8 context, we can get our context out const data = isolate.initBigInt(@intFromPtr(context)); - v8.c.v8__Context__SetEmbedderData(context.handle, 1, @ptrCast(data.handle)); + v8.v8__Context__SetEmbedderData(context.handle, 1, @ptrCast(data.handle)); try context.setupGlobal(); return context; @@ -168,8 +169,9 @@ pub fn resumeExecution(self: *const ExecutionWorld) void { self.env.isolate.cancelTerminateExecution(); } -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).?; + +pub fn unknownPropertyCallback(c_name: ?*const v8.Name, raw_info: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 { + const isolate_handle = v8.v8__PropertyCallbackInfo__GetIsolate(raw_info).?; const context = Context.fromIsolate(.{ .handle = isolate_handle }); const property: ?[]u8 = context.valueToString(.{ .ctx = context, .handle = c_name.? }, .{}) catch { diff --git a/src/browser/js/Function.zig b/src/browser/js/Function.zig index 73efcb64..a08222e8 100644 --- a/src/browser/js/Function.zig +++ b/src/browser/js/Function.zig @@ -25,8 +25,8 @@ const Allocator = std.mem.Allocator; const Function = @This(); ctx: *js.Context, -this: ?*const v8.c.Object = null, -handle: *const v8.c.Function, +this: ?*const v8.Object = null, +handle: *const v8.Function, pub const Result = struct { stack: ?[]const u8, @@ -34,7 +34,7 @@ pub const Result = struct { }; pub fn id(self: *const Function) u32 { - return @as(u32, @bitCast(v8.c.v8__Object__GetIdentityHash(@ptrCast(self.handle)))); + return @as(u32, @bitCast(v8.v8__Object__GetIdentityHash(@ptrCast(self.handle)))); } pub fn withThis(self: *const Function, value: anytype) !Function { @@ -59,7 +59,7 @@ pub fn newInstance(self: *const Function, result: *Result) !js.Object { // This creates a new instance using this Function as a constructor. // const c_args = @as(?[*]const ?*c.Value, @ptrCast(&.{})); - const handle = v8.c.v8__Function__NewInstance(self.handle, ctx.handle, 0, null) orelse { + const handle = v8.v8__Function__NewInstance(self.handle, ctx.handle, 0, null) orelse { if (try_catch.hasCaught()) { const allocator = ctx.call_arena; result.stack = try_catch.stack(allocator) catch null; @@ -129,18 +129,18 @@ pub fn callWithThis(self: *const Function, comptime T: type, this: anytype, args const aargs = if (comptime @typeInfo(@TypeOf(args)) == .null) struct {}{} else args; - const js_args: []const *const v8.c.Value = switch (@typeInfo(@TypeOf(aargs))) { + const js_args: []const *const v8.Value = switch (@typeInfo(@TypeOf(aargs))) { .@"struct" => |s| blk: { const fields = s.fields; - var js_args: [fields.len]*const v8.c.Value = undefined; + var js_args: [fields.len]*const v8.Value = undefined; inline for (fields, 0..) |f, i| { js_args[i] = (try ctx.zigValueToJs(@field(aargs, f.name), .{})).handle; } - const cargs: [fields.len]*const v8.c.Value = js_args; + const cargs: [fields.len]*const v8.Value = js_args; break :blk &cargs; }, .pointer => blk: { - var values = try ctx.call_arena.alloc(*const v8.c.Value, args.len); + var values = try ctx.call_arena.alloc(*const v8.Value, args.len); for (args, 0..) |a, i| { values[i] = (try ctx.zigValueToJs(a, .{})).handle; } @@ -149,8 +149,8 @@ pub fn callWithThis(self: *const Function, comptime T: type, this: anytype, args else => @compileError("JS Function called with invalid paremter type"), }; - const c_args = @as(?[*]const ?*v8.c.Value, @ptrCast(js_args.ptr)); - const handle = v8.c.v8__Function__Call(self.handle, ctx.handle, js_this.handle, @as(c_int, @intCast(js_args.len)), c_args) orelse { + const c_args = @as(?[*]const ?*v8.Value, @ptrCast(js_args.ptr)); + const handle = v8.v8__Function__Call(self.handle, ctx.handle, js_this.handle, @as(c_int, @intCast(js_args.len)), c_args) orelse { // std.debug.print("CB ERR: {s}\n", .{self.src() catch "???"}); return error.JSExecCallback; }; @@ -162,7 +162,7 @@ pub fn callWithThis(self: *const Function, comptime T: type, this: anytype, args } fn getThis(self: *const Function) js.Object { - const handle = if (self.this) |t| t else v8.c.v8__Context__Global(self.ctx.handle).?; + const handle = if (self.this) |t| t else v8.v8__Context__Global(self.ctx.handle).?; return .{ .ctx = self.ctx, .handle = handle, @@ -176,7 +176,7 @@ pub fn src(self: *const Function) ![]const u8 { pub fn getPropertyValue(self: *const Function, name: []const u8) !?js.Value { const ctx = self.ctx; const key = ctx.isolate.initStringHandle(name); - const handle = v8.c.v8__Object__Get(self.handle, ctx.handle, key) orelse { + const handle = v8.v8__Object__Get(self.handle, ctx.handle, key) orelse { return error.JsException; }; diff --git a/src/browser/js/HandleScope.zig b/src/browser/js/HandleScope.zig index 4c47d805..37f7e549 100644 --- a/src/browser/js/HandleScope.zig +++ b/src/browser/js/HandleScope.zig @@ -21,12 +21,12 @@ const v8 = js.v8; const HandleScope = @This(); -handle: v8.c.HandleScope, +handle: v8.HandleScope, pub fn init(self: *HandleScope, isolate: js.Isolate) void { - v8.c.v8__HandleScope__CONSTRUCT(&self.handle, isolate.handle); + v8.v8__HandleScope__CONSTRUCT(&self.handle, isolate.handle); } pub fn deinit(self: *HandleScope) void { - v8.c.v8__HandleScope__DESTRUCT(&self.handle); + v8.v8__HandleScope__DESTRUCT(&self.handle); } diff --git a/src/browser/js/Inspector.zig b/src/browser/js/Inspector.zig index 83bd7822..71d54b87 100644 --- a/src/browser/js/Inspector.zig +++ b/src/browser/js/Inspector.zig @@ -30,17 +30,17 @@ const CLIENT_TRUST_LEVEL = 1; const Inspector = @This(); -handle: *v8.c.Inspector, -isolate: *v8.c.Isolate, +handle: *v8.Inspector, +isolate: *v8.Isolate, client: Client, channel: Channel, session: Session, rnd: RndGen = RndGen.init(0), -default_context: ?*const v8.c.Context = null, +default_context: ?*const v8.Context = null, // We expect allocator to be an arena // Note: This initializes the pre-allocated inspector in-place -pub fn init(self: *Inspector, isolate: *v8.c.Isolate, ctx: anytype) !void { +pub fn init(self: *Inspector, isolate: *v8.Isolate, ctx: anytype) !void { const ContextT = @TypeOf(ctx); const Container = switch (@typeInfo(ContextT)) { @@ -70,7 +70,7 @@ pub fn init(self: *Inspector, isolate: *v8.c.Isolate, ctx: anytype) !void { client.setInspector(self); // Now create the inspector - generateUniqueId will work because data is set - const handle = v8.c.v8_inspector__Inspector__Create(isolate, client.handle).?; + const handle = v8.v8_inspector__Inspector__Create(isolate, client.handle).?; self.handle = handle; // Create the channel @@ -86,7 +86,7 @@ pub fn init(self: *Inspector, isolate: *v8.c.Isolate, ctx: anytype) !void { channel.setInspector(self); // Create the session - const session_handle = v8.c.v8_inspector__Inspector__Connect( + const session_handle = v8.v8_inspector__Inspector__Connect( handle, CONTEXT_GROUP_ID, channel.handle, @@ -103,7 +103,7 @@ pub fn deinit(self: *const Inspector) void { self.session.deinit(); self.client.deinit(); self.channel.deinit(); - v8.c.v8_inspector__Inspector__DELETE(self.handle); + v8.v8_inspector__Inspector__DELETE(self.handle); } pub fn send(self: *const Inspector, msg: []const u8) void { @@ -111,9 +111,9 @@ pub fn send(self: *const Inspector, msg: []const u8) void { // available when doing this. Pages (and thus the HandleScope) // comes and goes, but CDP can keep sending messages. const isolate = self.isolate; - var temp_scope: v8.c.HandleScope = undefined; - v8.c.v8__HandleScope__CONSTRUCT(&temp_scope, isolate); - defer v8.c.v8__HandleScope__DESTRUCT(&temp_scope); + var temp_scope: v8.HandleScope = undefined; + v8.v8__HandleScope__CONSTRUCT(&temp_scope, isolate); + defer v8.v8__HandleScope__DESTRUCT(&temp_scope); self.session.dispatchProtocolMessage(isolate, msg); } @@ -134,7 +134,7 @@ pub fn contextCreated( aux_data: []const u8, is_default_context: bool, ) void { - v8.c.v8_inspector__Inspector__ContextCreated( + v8.v8_inspector__Inspector__ContextCreated( self.handle, name.ptr, name.len, @@ -185,71 +185,71 @@ pub fn getNodePtr(self: *const Inspector, allocator: Allocator, object_id: []con const unwrapped = try self.session.unwrapObject(allocator, object_id); // The values context and groupId are not used here const js_val = unwrapped.value; - if (!v8.c.v8__Value__IsObject(js_val)) { + if (!v8.v8__Value__IsObject(js_val)) { return error.ObjectIdIsNotANode; } const Node = @import("../webapi/Node.zig"); - // Cast to *const v8.c.Object for typeTaggedAnyOpaque + // Cast to *const v8.Object for typeTaggedAnyOpaque return Context.typeTaggedAnyOpaque(*Node, @ptrCast(js_val)) catch { return error.ObjectIdIsNotANode; }; } pub const RemoteObject = struct { - handle: *v8.c.RemoteObject, + handle: *v8.RemoteObject, pub fn deinit(self: RemoteObject) void { - v8.c.v8_inspector__RemoteObject__DELETE(self.handle); + v8.v8_inspector__RemoteObject__DELETE(self.handle); } pub fn getType(self: RemoteObject, allocator: Allocator) ![]const u8 { - var ctype_: v8.c.CZigString = .{ .ptr = null, .len = 0 }; - if (!v8.c.v8_inspector__RemoteObject__getType(self.handle, &allocator, &ctype_)) return error.V8AllocFailed; + var ctype_: v8.CZigString = .{ .ptr = null, .len = 0 }; + if (!v8.v8_inspector__RemoteObject__getType(self.handle, &allocator, &ctype_)) return error.V8AllocFailed; return cZigStringToString(ctype_) orelse return error.InvalidType; } pub fn getSubtype(self: RemoteObject, allocator: Allocator) !?[]const u8 { - if (!v8.c.v8_inspector__RemoteObject__hasSubtype(self.handle)) return null; + if (!v8.v8_inspector__RemoteObject__hasSubtype(self.handle)) return null; - var csubtype: v8.c.CZigString = .{ .ptr = null, .len = 0 }; - if (!v8.c.v8_inspector__RemoteObject__getSubtype(self.handle, &allocator, &csubtype)) return error.V8AllocFailed; + var csubtype: v8.CZigString = .{ .ptr = null, .len = 0 }; + if (!v8.v8_inspector__RemoteObject__getSubtype(self.handle, &allocator, &csubtype)) return error.V8AllocFailed; return cZigStringToString(csubtype); } pub fn getClassName(self: RemoteObject, allocator: Allocator) !?[]const u8 { - if (!v8.c.v8_inspector__RemoteObject__hasClassName(self.handle)) return null; + if (!v8.v8_inspector__RemoteObject__hasClassName(self.handle)) return null; - var cclass_name: v8.c.CZigString = .{ .ptr = null, .len = 0 }; - if (!v8.c.v8_inspector__RemoteObject__getClassName(self.handle, &allocator, &cclass_name)) return error.V8AllocFailed; + var cclass_name: v8.CZigString = .{ .ptr = null, .len = 0 }; + if (!v8.v8_inspector__RemoteObject__getClassName(self.handle, &allocator, &cclass_name)) return error.V8AllocFailed; return cZigStringToString(cclass_name); } pub fn getDescription(self: RemoteObject, allocator: Allocator) !?[]const u8 { - if (!v8.c.v8_inspector__RemoteObject__hasDescription(self.handle)) return null; + if (!v8.v8_inspector__RemoteObject__hasDescription(self.handle)) return null; - var description: v8.c.CZigString = .{ .ptr = null, .len = 0 }; - if (!v8.c.v8_inspector__RemoteObject__getDescription(self.handle, &allocator, &description)) return error.V8AllocFailed; + var description: v8.CZigString = .{ .ptr = null, .len = 0 }; + if (!v8.v8_inspector__RemoteObject__getDescription(self.handle, &allocator, &description)) return error.V8AllocFailed; return cZigStringToString(description); } pub fn getObjectId(self: RemoteObject, allocator: Allocator) !?[]const u8 { - if (!v8.c.v8_inspector__RemoteObject__hasObjectId(self.handle)) return null; + if (!v8.v8_inspector__RemoteObject__hasObjectId(self.handle)) return null; - var cobject_id: v8.c.CZigString = .{ .ptr = null, .len = 0 }; - if (!v8.c.v8_inspector__RemoteObject__getObjectId(self.handle, &allocator, &cobject_id)) return error.V8AllocFailed; + var cobject_id: v8.CZigString = .{ .ptr = null, .len = 0 }; + if (!v8.v8_inspector__RemoteObject__getObjectId(self.handle, &allocator, &cobject_id)) return error.V8AllocFailed; return cZigStringToString(cobject_id); } }; const Session = struct { - handle: *v8.c.InspectorSession, + handle: *v8.InspectorSession, fn deinit(self: Session) void { - v8.c.v8_inspector__Session__DELETE(self.handle); + v8.v8_inspector__Session__DELETE(self.handle); } - fn dispatchProtocolMessage(self: Session, isolate: *v8.c.Isolate, msg: []const u8) void { - v8.c.v8_inspector__Session__dispatchProtocolMessage( + fn dispatchProtocolMessage(self: Session, isolate: *v8.Isolate, msg: []const u8) void { + v8.v8_inspector__Session__dispatchProtocolMessage( self.handle, isolate, msg.ptr, @@ -259,13 +259,13 @@ const Session = struct { fn wrapObject( self: Session, - isolate: *v8.c.Isolate, - ctx: *const v8.c.Context, - val: *const v8.c.Value, + isolate: *v8.Isolate, + ctx: *const v8.Context, + val: *const v8.Value, grpname: []const u8, generatepreview: bool, ) !RemoteObject { - const remote_object = v8.c.v8_inspector__Session__wrapObject( + const remote_object = v8.v8_inspector__Session__wrapObject( self.handle, isolate, ctx, @@ -282,16 +282,16 @@ const Session = struct { allocator: Allocator, object_id: []const u8, ) !UnwrappedObject { - const in_object_id = v8.c.CZigString{ + const in_object_id = v8.CZigString{ .ptr = object_id.ptr, .len = object_id.len, }; - var out_error: v8.c.CZigString = .{ .ptr = null, .len = 0 }; - var out_value_handle: ?*v8.c.Value = null; - var out_context_handle: ?*v8.c.Context = null; - var out_object_group: v8.c.CZigString = .{ .ptr = null, .len = 0 }; + var out_error: v8.CZigString = .{ .ptr = null, .len = 0 }; + var out_value_handle: ?*v8.Value = null; + var out_context_handle: ?*v8.Context = null; + var out_object_group: v8.CZigString = .{ .ptr = null, .len = 0 }; - const result = v8.c.v8_inspector__Session__unwrapObject( + const result = v8.v8_inspector__Session__unwrapObject( self.handle, &allocator, &out_error, @@ -316,13 +316,13 @@ const Session = struct { }; const UnwrappedObject = struct { - value: *const v8.c.Value, - context: *const v8.c.Context, + value: *const v8.Value, + context: *const v8.Context, object_group: ?[]const u8, }; const Channel = struct { - handle: *v8.c.InspectorChannelImpl, + handle: *v8.InspectorChannelImpl, // callbacks ctx: *anyopaque, @@ -342,9 +342,9 @@ const Channel = struct { onNotif: onNotifFn, onRunMessageLoopOnPause: onRunMessageLoopOnPauseFn, onQuitMessageLoopOnPause: onQuitMessageLoopOnPauseFn, - isolate: *v8.c.Isolate, + isolate: *v8.Isolate, ) Channel { - const handle = v8.c.v8_inspector__Channel__IMPL__CREATE(isolate); + const handle = v8.v8_inspector__Channel__IMPL__CREATE(isolate); return .{ .handle = handle, .ctx = ctx, @@ -356,11 +356,11 @@ const Channel = struct { } fn deinit(self: Channel) void { - v8.c.v8_inspector__Channel__IMPL__DELETE(self.handle); + v8.v8_inspector__Channel__IMPL__DELETE(self.handle); } fn setInspector(self: Channel, inspector: *anyopaque) void { - v8.c.v8_inspector__Channel__IMPL__SET_DATA(self.handle, inspector); + v8.v8_inspector__Channel__IMPL__SET_DATA(self.handle, inspector); } fn resp(self: Channel, call_id: u32, msg: []const u8) void { @@ -373,18 +373,18 @@ const Channel = struct { }; const Client = struct { - handle: *v8.c.InspectorClientImpl, + handle: *v8.InspectorClientImpl, fn init() Client { - return .{ .handle = v8.c.v8_inspector__Client__IMPL__CREATE() }; + return .{ .handle = v8.v8_inspector__Client__IMPL__CREATE() }; } fn deinit(self: Client) void { - v8.c.v8_inspector__Client__IMPL__DELETE(self.handle); + v8.v8_inspector__Client__IMPL__DELETE(self.handle); } fn setInspector(self: Client, inspector: *anyopaque) void { - v8.c.v8_inspector__Client__IMPL__SET_DATA(self.handle, inspector); + v8.v8_inspector__Client__IMPL__SET_DATA(self.handle, inspector); } }; @@ -399,28 +399,28 @@ fn fromData(data: *anyopaque) *Inspector { return @ptrCast(@alignCast(data)); } -pub fn getTaggedAnyOpaque(value: *const v8.c.Value) ?*js.TaggedAnyOpaque { - if (!v8.c.v8__Value__IsObject(value)) { +pub fn getTaggedAnyOpaque(value: *const v8.Value) ?*js.TaggedAnyOpaque { + if (!v8.v8__Value__IsObject(value)) { return null; } - const internal_field_count = v8.c.v8__Object__InternalFieldCount(value); + const internal_field_count = v8.v8__Object__InternalFieldCount(value); if (internal_field_count == 0) { return null; } - const external_value = v8.c.v8__Object__GetInternalField(value, 0).?; - const external_data = v8.c.v8__External__Value(external_value).?; + const external_value = v8.v8__Object__GetInternalField(value, 0).?; + const external_data = v8.v8__External__Value(external_value).?; return @ptrCast(@alignCast(external_data)); } -fn cZigStringToString(s: v8.c.CZigString) ?[]const u8 { +fn cZigStringToString(s: v8.CZigString) ?[]const u8 { if (s.ptr == null) return null; return s.ptr[0..s.len]; } // C export functions for Inspector callbacks pub export fn v8_inspector__Client__IMPL__generateUniqueId( - _: *v8.c.InspectorClientImpl, + _: *v8.InspectorClientImpl, data: *anyopaque, ) callconv(.c) i64 { const inspector: *Inspector = @ptrCast(@alignCast(data)); @@ -428,7 +428,7 @@ pub export fn v8_inspector__Client__IMPL__generateUniqueId( } pub export fn v8_inspector__Client__IMPL__runMessageLoopOnPause( - _: *v8.c.InspectorClientImpl, + _: *v8.InspectorClientImpl, data: *anyopaque, ctx_group_id: c_int, ) callconv(.c) void { @@ -437,7 +437,7 @@ pub export fn v8_inspector__Client__IMPL__runMessageLoopOnPause( } pub export fn v8_inspector__Client__IMPL__quitMessageLoopOnPause( - _: *v8.c.InspectorClientImpl, + _: *v8.InspectorClientImpl, data: *anyopaque, ) callconv(.c) void { const inspector: *Inspector = @ptrCast(@alignCast(data)); @@ -445,7 +445,7 @@ pub export fn v8_inspector__Client__IMPL__quitMessageLoopOnPause( } pub export fn v8_inspector__Client__IMPL__runIfWaitingForDebugger( - _: *v8.c.InspectorClientImpl, + _: *v8.InspectorClientImpl, _: *anyopaque, _: c_int, ) callconv(.c) void { @@ -453,27 +453,27 @@ pub export fn v8_inspector__Client__IMPL__runIfWaitingForDebugger( } pub export fn v8_inspector__Client__IMPL__consoleAPIMessage( - _: *v8.c.InspectorClientImpl, + _: *v8.InspectorClientImpl, _: *anyopaque, _: c_int, - _: v8.c.MessageErrorLevel, - _: *v8.c.StringView, - _: *v8.c.StringView, + _: v8.MessageErrorLevel, + _: *v8.StringView, + _: *v8.StringView, _: c_uint, _: c_uint, - _: *v8.c.StackTrace, + _: *v8.StackTrace, ) callconv(.c) void {} pub export fn v8_inspector__Client__IMPL__ensureDefaultContextInGroup( - _: *v8.c.InspectorClientImpl, + _: *v8.InspectorClientImpl, data: *anyopaque, -) callconv(.c) ?*const v8.c.Context { +) callconv(.c) ?*const v8.Context { const inspector: *Inspector = @ptrCast(@alignCast(data)); return inspector.default_context; } pub export fn v8_inspector__Channel__IMPL__sendResponse( - _: *v8.c.InspectorChannelImpl, + _: *v8.InspectorChannelImpl, data: *anyopaque, call_id: c_int, msg: [*c]u8, @@ -484,7 +484,7 @@ pub export fn v8_inspector__Channel__IMPL__sendResponse( } pub export fn v8_inspector__Channel__IMPL__sendNotification( - _: *v8.c.InspectorChannelImpl, + _: *v8.InspectorChannelImpl, data: *anyopaque, msg: [*c]u8, length: usize, @@ -494,7 +494,7 @@ pub export fn v8_inspector__Channel__IMPL__sendNotification( } pub export fn v8_inspector__Channel__IMPL__flushProtocolNotifications( - _: *v8.c.InspectorChannelImpl, + _: *v8.InspectorChannelImpl, _: *anyopaque, ) callconv(.c) void { // TODO diff --git a/src/browser/js/Integer.zig b/src/browser/js/Integer.zig index 5d7cef5b..e0383fbf 100644 --- a/src/browser/js/Integer.zig +++ b/src/browser/js/Integer.zig @@ -23,12 +23,12 @@ const v8 = js.v8; const Integer = @This(); -handle: *const v8.c.Integer, +handle: *const v8.Integer, -pub fn init(isolate: *v8.c.Isolate, value: anytype) Integer { +pub fn init(isolate: *v8.Isolate, value: anytype) Integer { const handle = switch (@TypeOf(value)) { - i8, i16, i32 => v8.c.v8__Integer__New(isolate, value).?, - u8, u16, u32 => v8.c.v8__Integer__NewFromUnsigned(isolate, value).?, + i8, i16, i32 => v8.v8__Integer__New(isolate, value).?, + u8, u16, u32 => v8.v8__Integer__NewFromUnsigned(isolate, value).?, else => |T| @compileError("cannot create v8::Integer from: " ++ @typeName(T)), }; return .{ .handle = handle }; diff --git a/src/browser/js/Isolate.zig b/src/browser/js/Isolate.zig index c142ad91..9b4ae1d1 100644 --- a/src/browser/js/Isolate.zig +++ b/src/browser/js/Isolate.zig @@ -21,80 +21,80 @@ const v8 = js.v8; const Isolate = @This(); -handle: *v8.c.Isolate, +handle: *v8.Isolate, -pub fn init(params: *v8.c.CreateParams) Isolate { +pub fn init(params: *v8.CreateParams) Isolate { return .{ - .handle = v8.c.v8__Isolate__New(params).?, + .handle = v8.v8__Isolate__New(params).?, }; } pub fn deinit(self: Isolate) void { - v8.c.v8__Isolate__Dispose(self.handle); + v8.v8__Isolate__Dispose(self.handle); } pub fn enter(self: Isolate) void { - v8.c.v8__Isolate__Enter(self.handle); + v8.v8__Isolate__Enter(self.handle); } pub fn exit(self: Isolate) void { - v8.c.v8__Isolate__Exit(self.handle); + v8.v8__Isolate__Exit(self.handle); } pub fn performMicrotasksCheckpoint(self: Isolate) void { - v8.c.v8__Isolate__PerformMicrotaskCheckpoint(self.handle); + v8.v8__Isolate__PerformMicrotaskCheckpoint(self.handle); } pub fn enqueueMicrotask(self: Isolate, callback: anytype, data: anytype) void { - v8.c.v8__Isolate__EnqueueMicrotask(self.handle, callback, data); + v8.v8__Isolate__EnqueueMicrotask(self.handle, callback, data); } pub fn enqueueMicrotaskFunc(self: Isolate, function: js.Function) void { - v8.c.v8__Isolate__EnqueueMicrotaskFunc(self.handle, function.handle); + v8.v8__Isolate__EnqueueMicrotaskFunc(self.handle, function.handle); } pub fn lowMemoryNotification(self: Isolate) void { - v8.c.v8__Isolate__LowMemoryNotification(self.handle); + v8.v8__Isolate__LowMemoryNotification(self.handle); } -pub fn getHeapStatistics(self: Isolate) v8.c.HeapStatistics { - var res: v8.c.HeapStatistics = undefined; - v8.c.v8__Isolate__GetHeapStatistics(self.handle, &res); +pub fn getHeapStatistics(self: Isolate) v8.HeapStatistics { + var res: v8.HeapStatistics = undefined; + v8.v8__Isolate__GetHeapStatistics(self.handle, &res); return res; } -pub fn throwException(self: Isolate, value: *const v8.c.Value) *const v8.c.Value { - return v8.c.v8__Isolate__ThrowException(self.handle, value).?; +pub fn throwException(self: Isolate, value: *const v8.Value) *const v8.Value { + return v8.v8__Isolate__ThrowException(self.handle, value).?; } -pub fn initStringHandle(self: Isolate, str: []const u8) *const v8.c.String { - return v8.c.v8__String__NewFromUtf8(self.handle, str.ptr, v8.c.kNormal, @as(c_int, @intCast(str.len))).?; +pub fn initStringHandle(self: Isolate, str: []const u8) *const v8.String { + return v8.v8__String__NewFromUtf8(self.handle, str.ptr, v8.kNormal, @as(c_int, @intCast(str.len))).?; } -pub fn createError(self: Isolate, msg: []const u8) *const v8.c.Value { +pub fn createError(self: Isolate, msg: []const u8) *const v8.Value { const message = self.initStringHandle(msg); - return v8.c.v8__Exception__Error(message).?; + return v8.v8__Exception__Error(message).?; } -pub fn createTypeError(self: Isolate, msg: []const u8) *const v8.c.Value { +pub fn createTypeError(self: Isolate, msg: []const u8) *const v8.Value { const message = self.initStringHandle(msg); - return v8.c.v8__Exception__TypeError(message).?; + return v8.v8__Exception__TypeError(message).?; } -pub fn initNull(self: Isolate) *const v8.c.Value { - return v8.c.v8__Null(self.handle).?; +pub fn initNull(self: Isolate) *const v8.Value { + return v8.v8__Null(self.handle).?; } -pub fn initUndefined(self: Isolate) *const v8.c.Value { - return v8.c.v8__Undefined(self.handle).?; +pub fn initUndefined(self: Isolate) *const v8.Value { + return v8.v8__Undefined(self.handle).?; } -pub fn initFalse(self: Isolate) *const v8.c.Value { - return v8.c.v8__False(self.handle).?; +pub fn initFalse(self: Isolate) *const v8.Value { + return v8.v8__False(self.handle).?; } -pub fn initTrue(self: Isolate) *const v8.c.Value { - return v8.c.v8__True(self.handle).?; +pub fn initTrue(self: Isolate) *const v8.Value { + return v8.v8__True(self.handle).?; } pub fn initInteger(self: Isolate, val: anytype) js.Integer { @@ -109,14 +109,14 @@ pub fn initNumber(self: Isolate, val: anytype) js.Number { return js.Number.init(self.handle, val); } -pub fn createContextHandle(self: Isolate, global_tmpl: ?*const v8.c.ObjectTemplate, global_obj: ?*const v8.c.Value) *const v8.c.Context { - return v8.c.v8__Context__New(self.handle, global_tmpl, global_obj).?; +pub fn createContextHandle(self: Isolate, global_tmpl: ?*const v8.ObjectTemplate, global_obj: ?*const v8.Value) *const v8.Context { + return v8.v8__Context__New(self.handle, global_tmpl, global_obj).?; } -pub fn createFunctionTemplateHandle(self: Isolate) *const v8.c.FunctionTemplate { - return v8.c.v8__FunctionTemplate__New__DEFAULT(self.handle).?; +pub fn createFunctionTemplateHandle(self: Isolate) *const v8.FunctionTemplate { + return v8.v8__FunctionTemplate__New__DEFAULT(self.handle).?; } -pub fn createExternal(self: Isolate, val: *anyopaque) *const v8.c.External { - return v8.c.v8__External__New(self.handle, val).?; +pub fn createExternal(self: Isolate, val: *anyopaque) *const v8.External { + return v8.v8__External__New(self.handle, val).?; } diff --git a/src/browser/js/Module.zig b/src/browser/js/Module.zig index 571def25..ef8dec57 100644 --- a/src/browser/js/Module.zig +++ b/src/browser/js/Module.zig @@ -22,38 +22,38 @@ const v8 = js.v8; const Module = @This(); ctx: *js.Context, -handle: *const v8.c.Module, +handle: *const v8.Module, pub const Status = enum(u32) { - kUninstantiated = v8.c.kUninstantiated, - kInstantiating = v8.c.kInstantiating, - kInstantiated = v8.c.kInstantiated, - kEvaluating = v8.c.kEvaluating, - kEvaluated = v8.c.kEvaluated, - kErrored = v8.c.kErrored, + kUninstantiated = v8.kUninstantiated, + kInstantiating = v8.kInstantiating, + kInstantiated = v8.kInstantiated, + kEvaluating = v8.kEvaluating, + kEvaluated = v8.kEvaluated, + kErrored = v8.kErrored, }; pub fn getStatus(self: Module) Status { - return @enumFromInt(v8.c.v8__Module__GetStatus(self.handle)); + return @enumFromInt(v8.v8__Module__GetStatus(self.handle)); } pub fn getException(self: Module) js.Value { return .{ .ctx = self.ctx, - .handle = v8.c.v8__Module__GetException(self.handle).?, + .handle = v8.v8__Module__GetException(self.handle).?, }; } pub fn getModuleRequests(self: Module) Requests { return .{ .ctx = self.ctx.handle, - .handle = v8.c.v8__Module__GetModuleRequests(self.handle).?, + .handle = v8.v8__Module__GetModuleRequests(self.handle).?, }; } -pub fn instantiate(self: Module, cb: v8.c.ResolveModuleCallback) !bool { - var out: v8.c.MaybeBool = undefined; - v8.c.v8__Module__InstantiateModule(self.handle, self.ctx.handle, cb, &out); +pub fn instantiate(self: Module, cb: v8.ResolveModuleCallback) !bool { + var out: v8.MaybeBool = undefined; + v8.v8__Module__InstantiateModule(self.handle, self.ctx.handle, cb, &out); if (out.has_value) { return out.value; } @@ -62,7 +62,7 @@ pub fn instantiate(self: Module, cb: v8.c.ResolveModuleCallback) !bool { pub fn evaluate(self: Module) !js.Value { const ctx = self.ctx; - const res = v8.c.v8__Module__Evaluate(self.handle, ctx.handle) orelse return error.JsException; + const res = v8.v8__Module__Evaluate(self.handle, ctx.handle) orelse return error.JsException; if (self.getStatus() == .kErrored) { return error.JsException; @@ -75,18 +75,18 @@ pub fn evaluate(self: Module) !js.Value { } pub fn getIdentityHash(self: Module) u32 { - return @bitCast(v8.c.v8__Module__GetIdentityHash(self.handle)); + return @bitCast(v8.v8__Module__GetIdentityHash(self.handle)); } pub fn getModuleNamespace(self: Module) js.Value { return .{ .ctx = self.ctx, - .handle = v8.c.v8__Module__GetModuleNamespace(self.handle).?, + .handle = v8.v8__Module__GetModuleNamespace(self.handle).?, }; } pub fn getScriptId(self: Module) u32 { - return @intCast(v8.c.v8__Module__ScriptId(self.handle)); + return @intCast(v8.v8__Module__ScriptId(self.handle)); } pub fn persist(self: Module) !Module { @@ -102,22 +102,22 @@ pub fn persist(self: Module) !Module { } const Requests = struct { - ctx: *const v8.c.Context, - handle: *const v8.c.FixedArray, + ctx: *const v8.Context, + handle: *const v8.FixedArray, pub fn len(self: Requests) usize { - return @intCast(v8.c.v8__FixedArray__Length(self.handle)); + return @intCast(v8.v8__FixedArray__Length(self.handle)); } pub fn get(self: Requests, idx: usize) Request { - return .{ .handle = v8.c.v8__FixedArray__Get(self.handle, self.ctx, @intCast(idx)).? }; + return .{ .handle = v8.v8__FixedArray__Get(self.handle, self.ctx, @intCast(idx)).? }; } }; const Request = struct { - handle: *const v8.c.ModuleRequest, + handle: *const v8.ModuleRequest, - pub fn specifier(self: Request) *const v8.c.String { - return v8.c.v8__ModuleRequest__GetSpecifier(self.handle).?; + pub fn specifier(self: Request) *const v8.String { + return v8.v8__ModuleRequest__GetSpecifier(self.handle).?; } }; diff --git a/src/browser/js/Name.zig b/src/browser/js/Name.zig index 17b04173..90def5cb 100644 --- a/src/browser/js/Name.zig +++ b/src/browser/js/Name.zig @@ -21,7 +21,7 @@ const v8 = js.v8; const Name = @This(); -handle: *const v8.c.Name, +handle: *const v8.Name, pub fn toValue(self: Name) js.Value { return .{ diff --git a/src/browser/js/Number.zig b/src/browser/js/Number.zig index 0bba90ea..1676632b 100644 --- a/src/browser/js/Number.zig +++ b/src/browser/js/Number.zig @@ -23,9 +23,9 @@ const v8 = js.v8; const Number = @This(); -handle: *const v8.c.Number, +handle: *const v8.Number, -pub fn init(isolate: *v8.c.Isolate, value: anytype) Number { - const handle = v8.c.v8__Number__New(isolate, value).?; +pub fn init(isolate: *v8.Isolate, value: anytype) Number { + const handle = v8.v8__Number__New(isolate, value).?; return .{ .handle = handle }; } diff --git a/src/browser/js/Object.zig b/src/browser/js/Object.zig index e68cb445..082f135f 100644 --- a/src/browser/js/Object.zig +++ b/src/browser/js/Object.zig @@ -30,18 +30,18 @@ const Allocator = std.mem.Allocator; const Object = @This(); ctx: *js.Context, -handle: *const v8.c.Object, +handle: *const v8.Object, pub fn getId(self: Object) u32 { - return @bitCast(v8.c.v8__Object__GetIdentityHash(self.handle)); + return @bitCast(v8.v8__Object__GetIdentityHash(self.handle)); } pub fn has(self: Object, key: anytype) bool { const ctx = self.ctx; - const key_handle = if (@TypeOf(key) == *const v8.c.String) key else ctx.isolate.initStringHandle(key); + const key_handle = if (@TypeOf(key) == *const v8.String) key else ctx.isolate.initStringHandle(key); - var out: v8.c.MaybeBool = undefined; - v8.c.v8__Object__Has(self.handle, self.ctx.handle, key_handle, &out); + var out: v8.MaybeBool = undefined; + v8.v8__Object__Has(self.handle, self.ctx.handle, key_handle, &out); if (out.has_value) { return out.value; } @@ -51,8 +51,8 @@ pub fn has(self: Object, key: anytype) bool { pub fn get(self: Object, key: anytype) !js.Value { const ctx = self.ctx; - const key_handle = if (@TypeOf(key) == *const v8.c.String) key else ctx.isolate.initStringHandle(key); - const js_val_handle = v8.c.v8__Object__Get(self.handle, ctx.handle, key_handle) orelse return error.JsException; + const key_handle = if (@TypeOf(key) == *const v8.String) key else ctx.isolate.initStringHandle(key); + const js_val_handle = v8.v8__Object__Get(self.handle, ctx.handle, key_handle) orelse return error.JsException; return .{ .ctx = ctx, @@ -64,10 +64,10 @@ pub fn set(self: Object, key: anytype, value: anytype, comptime opts: js.bridge. const ctx = self.ctx; const js_value = try ctx.zigValueToJs(value, opts); - const key_handle = if (@TypeOf(key) == *const v8.c.String) key else ctx.isolate.initStringHandle(key); + const key_handle = if (@TypeOf(key) == *const v8.String) key else ctx.isolate.initStringHandle(key); - var out: v8.c.MaybeBool = undefined; - v8.c.v8__Object__Set(self.handle, ctx.handle, key_handle, js_value.handle, &out); + var out: v8.MaybeBool = undefined; + v8.v8__Object__Set(self.handle, ctx.handle, key_handle, js_value.handle, &out); return out.has_value; } @@ -76,16 +76,18 @@ pub fn setIndex(self: Object, key: u32, value: anytype, comptime opts: js.bridge const js_value = try ctx.zigValueToJs(value, opts); - var out: v8.c.MaybeBool = undefined; - v8.c.v8__Object__SetAtIndex(self.handle, ctx.handle, key, js_value.handle, &out); + var out: v8.MaybeBool = undefined; + v8.v8__Object__SetAtIndex(self.handle, ctx.handle, key, js_value.handle, &out); return out.has_value; } -pub fn defineOwnProperty(self: Object, name: []const u8, value: js.Value, attr: v8.c.PropertyAttribute) ?bool { +pub fn defineOwnProperty(self: Object, name: []const u8, value: js.Value, attr: v8.PropertyAttribute) ?bool { const ctx = self.ctx; const name_handle = ctx.isolate.initStringHandle(name); - var out: v8.c.MaybeBool = undefined; - v8.c.v8__Object__DefineOwnProperty(self.handle, ctx.handle, @ptrCast(name_handle), value.handle, attr, &out); + + var out: v8.MaybeBool = undefined; + v8.v8__Object__DefineOwnProperty(self.handle, ctx.handle, @ptrCast(name_handle), value.handle, attr, &out); + if (out.has_value) { return out.value; } else { @@ -113,7 +115,7 @@ pub fn format(self: Object, writer: *std.Io.Writer) !void { } pub fn toJson(self: Object, allocator: Allocator) ![]u8 { - const json_str_handle = v8.c.v8__JSON__Stringify(self.ctx.handle, @ptrCast(self.handle), null) orelse return error.JsException; + const json_str_handle = v8.v8__JSON__Stringify(self.ctx.handle, @ptrCast(self.handle), null) orelse return error.JsException; return self.ctx.jsStringToZig(json_str_handle, .{ .allocator = allocator }); } @@ -136,9 +138,9 @@ pub fn getFunction(self: Object, name: []const u8) !?js.Function { const ctx = self.ctx; const js_name = ctx.isolate.initStringHandle(name); - const js_val_handle = v8.c.v8__Object__Get(self.handle, ctx.handle, js_name) orelse return error.JsException; + const js_val_handle = v8.v8__Object__Get(self.handle, ctx.handle, js_name) orelse return error.JsException; - if (v8.c.v8__Value__IsFunction(js_val_handle) == false) { + if (v8.v8__Value__IsFunction(js_val_handle) == false) { return null; } return .{ @@ -153,11 +155,11 @@ pub fn callMethod(self: Object, comptime T: type, method_name: []const u8, args: } pub fn isNullOrUndefined(self: Object) bool { - return v8.c.v8__Value__IsNullOrUndefined(@ptrCast(self.handle)); + return v8.v8__Value__IsNullOrUndefined(@ptrCast(self.handle)); } pub fn getOwnPropertyNames(self: Object) js.Array { - const handle = v8.c.v8__Object__GetOwnPropertyNames(self.handle, self.ctx.handle).?; + const handle = v8.v8__Object__GetOwnPropertyNames(self.handle, self.ctx.handle).?; return .{ .ctx = self.ctx, .handle = handle, @@ -165,7 +167,7 @@ pub fn getOwnPropertyNames(self: Object) js.Array { } pub fn getPropertyNames(self: Object) js.Array { - const handle = v8.c.v8__Object__GetPropertyNames(self.handle, self.ctx.handle).?; + const handle = v8.v8__Object__GetPropertyNames(self.handle, self.ctx.handle).?; return .{ .ctx = self.ctx, .handle = handle, @@ -175,8 +177,8 @@ pub fn getPropertyNames(self: Object) js.Array { pub fn nameIterator(self: Object) NameIterator { const ctx = self.ctx; - const handle = v8.c.v8__Object__GetPropertyNames(self.handle, ctx.handle).?; - const count = v8.c.v8__Array__Length(handle); + const handle = v8.v8__Object__GetPropertyNames(self.handle, ctx.handle).?; + const count = v8.v8__Array__Length(handle); return .{ .ctx = ctx, @@ -194,7 +196,7 @@ pub const NameIterator = struct { count: u32, idx: u32 = 0, ctx: *Context, - handle: *const v8.c.Array, + handle: *const v8.Array, pub fn next(self: *NameIterator) !?[]const u8 { const idx = self.idx; @@ -203,7 +205,7 @@ pub const NameIterator = struct { } self.idx += 1; - const js_val_handle = v8.c.v8__Object__GetIndex(@ptrCast(self.handle), self.ctx.handle, idx) orelse return error.JsException; + const js_val_handle = v8.v8__Object__GetIndex(@ptrCast(self.handle), self.ctx.handle, idx) orelse return error.JsException; const js_val = js.Value{ .ctx = self.ctx, .handle = js_val_handle }; return try self.ctx.valueToString(js_val, .{}); } diff --git a/src/browser/js/Platform.zig b/src/browser/js/Platform.zig index 6390abad..0a173331 100644 --- a/src/browser/js/Platform.zig +++ b/src/browser/js/Platform.zig @@ -20,22 +20,22 @@ const js = @import("js.zig"); const v8 = js.v8; const Platform = @This(); -handle: *v8.c.Platform, +handle: *v8.Platform, pub fn init() !Platform { - if (v8.c.v8__V8__InitializeICU() == false) { + if (v8.v8__V8__InitializeICU() == false) { return error.FailedToInitializeICU; } // 0 - threadpool size, 0 == let v8 decide // 1 - idle_task_support, 1 == enabled - const handle = v8.c.v8__Platform__NewDefaultPlatform(0, 1).?; - v8.c.v8__V8__InitializePlatform(handle); - v8.c.v8__V8__Initialize(); + const handle = v8.v8__Platform__NewDefaultPlatform(0, 1).?; + v8.v8__V8__InitializePlatform(handle); + v8.v8__V8__Initialize(); return .{ .handle = handle }; } pub fn deinit(self: Platform) void { - _ = v8.c.v8__V8__Dispose(); - v8.c.v8__V8__DisposePlatform(); - v8.c.v8__Platform__DELETE(self.handle); + _ = v8.v8__V8__Dispose(); + v8.v8__V8__DisposePlatform(); + v8.v8__Platform__DELETE(self.handle); } diff --git a/src/browser/js/Promise.zig b/src/browser/js/Promise.zig index 6cbac804..f520a9d6 100644 --- a/src/browser/js/Promise.zig +++ b/src/browser/js/Promise.zig @@ -22,7 +22,7 @@ const v8 = js.v8; const Promise = @This(); ctx: *js.Context, -handle: *const v8.c.Promise, +handle: *const v8.Promise, pub fn toObject(self: Promise) js.Object { return .{ @@ -39,7 +39,7 @@ pub fn toValue(self: Promise) js.Value { } pub fn thenAndCatch(self: Promise, on_fulfilled: js.Function, on_rejected: js.Function) !Promise { - if (v8.c.v8__Promise__Then2(self.handle, self.ctx.handle, on_fulfilled.handle, on_rejected.handle)) |handle| { + if (v8.v8__Promise__Then2(self.handle, self.ctx.handle, on_fulfilled.handle, on_rejected.handle)) |handle| { return .{ .ctx = self.ctx, .handle = handle, diff --git a/src/browser/js/PromiseResolver.zig b/src/browser/js/PromiseResolver.zig index 117d0978..a12d3a26 100644 --- a/src/browser/js/PromiseResolver.zig +++ b/src/browser/js/PromiseResolver.zig @@ -23,19 +23,19 @@ const log = @import("../../log.zig"); const PromiseResolver = @This(); ctx: *js.Context, -handle: *const v8.c.PromiseResolver, +handle: *const v8.PromiseResolver, pub fn init(ctx: *js.Context) PromiseResolver { return .{ .ctx = ctx, - .handle = v8.c.v8__Promise__Resolver__New(ctx.handle).?, + .handle = v8.v8__Promise__Resolver__New(ctx.handle).?, }; } pub fn promise(self: PromiseResolver) js.Promise { return .{ .ctx = self.ctx, - .handle = v8.c.v8__Promise__Resolver__GetPromise(self.handle).?, + .handle = v8.v8__Promise__Resolver__GetPromise(self.handle).?, }; } @@ -49,8 +49,8 @@ fn _resolve(self: PromiseResolver, value: anytype) !void { const ctx: *js.Context = @constCast(self.ctx); const js_value = try ctx.zigValueToJs(value, .{}); - var out: v8.c.MaybeBool = undefined; - v8.c.v8__Promise__Resolver__Resolve(self.handle, self.ctx.handle, js_value.handle, &out); + var out: v8.MaybeBool = undefined; + v8.v8__Promise__Resolver__Resolve(self.handle, self.ctx.handle, js_value.handle, &out); if (!out.has_value or !out.value) { return error.FailedToResolvePromise; } @@ -67,8 +67,8 @@ fn _reject(self: PromiseResolver, value: anytype) !void { const ctx = self.ctx; const js_value = try ctx.zigValueToJs(value, .{}); - var out: v8.c.MaybeBool = undefined; - v8.c.v8__Promise__Resolver__Reject(self.handle, ctx.handle, js_value.handle, &out); + var out: v8.MaybeBool = undefined; + v8.v8__Promise__Resolver__Reject(self.handle, ctx.handle, js_value.handle, &out); if (!out.has_value or !out.value) { return error.FailedToRejectPromise; } diff --git a/src/browser/js/Snapshot.zig b/src/browser/js/Snapshot.zig index af7cb324..bab594da 100644 --- a/src/browser/js/Snapshot.zig +++ b/src/browser/js/Snapshot.zig @@ -41,8 +41,8 @@ const embedded_snapshot_blob = if (@import("build_config").snapshot_path) |path| // sequence data_start: usize, -// The snapshot data (v8.c.StartupData is a ptr to the data and len). -startup_data: v8.c.StartupData, +// The snapshot data (v8.StartupData is a ptr to the data and len). +startup_data: v8.StartupData, // V8 doesn't know how to serialize external references, and pretty much any hook // into Zig is an external reference (e.g. every accessor and function callback). @@ -74,8 +74,8 @@ fn loadEmbedded() ?Snapshot { const data_start = std.mem.readInt(usize, embedded_snapshot_blob[0..@sizeOf(usize)], .little); const blob = embedded_snapshot_blob[@sizeOf(usize)..]; - const startup_data = v8.c.StartupData{ .data = blob.ptr, .raw_size = @intCast(blob.len) }; - if (!v8.c.v8__StartupData__IsValid(startup_data)) { + const startup_data = v8.StartupData{ .data = blob.ptr, .raw_size = @intCast(blob.len) }; + if (!v8.v8__StartupData__IsValid(startup_data)) { return null; } @@ -110,7 +110,7 @@ pub fn fromEmbedded(self: Snapshot) bool { } fn isValid(self: Snapshot) bool { - return v8.c.v8__StartupData__IsValid(self.startup_data); + return v8.v8__StartupData__IsValid(self.startup_data); } pub fn createGlobalTemplate(isolate: v8.Isolate, templates: []const v8.FunctionTemplate) v8.ObjectTemplate { @@ -130,28 +130,28 @@ pub fn createGlobalTemplate(isolate: v8.Isolate, templates: []const v8.FunctionT pub fn create(allocator: Allocator) !Snapshot { var external_references = collectExternalReferences(); - var params: v8.c.CreateParams = undefined; - v8.c.v8__Isolate__CreateParams__CONSTRUCT(¶ms); - params.array_buffer_allocator = v8.c.v8__ArrayBuffer__Allocator__NewDefaultAllocator(); - defer v8.c.v8__ArrayBuffer__Allocator__DELETE(params.array_buffer_allocator.?); + var params: v8.CreateParams = undefined; + v8.v8__Isolate__CreateParams__CONSTRUCT(¶ms); + params.array_buffer_allocator = v8.v8__ArrayBuffer__Allocator__NewDefaultAllocator(); + defer v8.v8__ArrayBuffer__Allocator__DELETE(params.array_buffer_allocator.?); params.external_references = @ptrCast(&external_references); - const snapshot_creator = v8.c.v8__SnapshotCreator__CREATE(¶ms); - defer v8.c.v8__SnapshotCreator__DESTRUCT(snapshot_creator); + const snapshot_creator = v8.v8__SnapshotCreator__CREATE(¶ms); + defer v8.v8__SnapshotCreator__DESTRUCT(snapshot_creator); var data_start: usize = 0; - const isolate = v8.c.v8__SnapshotCreator__getIsolate(snapshot_creator).?; + const isolate = v8.v8__SnapshotCreator__getIsolate(snapshot_creator).?; { // CreateBlob, which we'll call once everything is setup, MUST NOT // be called from an active HandleScope. Hence we have this scope to // clean it up before we call CreateBlob - var handle_scope: v8.c.HandleScope = undefined; - v8.c.v8__HandleScope__CONSTRUCT(&handle_scope, isolate); - defer v8.c.v8__HandleScope__DESTRUCT(&handle_scope); + var handle_scope: v8.HandleScope = undefined; + v8.v8__HandleScope__CONSTRUCT(&handle_scope, isolate); + defer v8.v8__HandleScope__DESTRUCT(&handle_scope); // Create templates (constructors only) FIRST - var templates: [JsApis.len]*v8.c.FunctionTemplate = undefined; + var templates: [JsApis.len]*v8.FunctionTemplate = undefined; inline for (JsApis, 0..) |JsApi, i| { @setEvalBranchQuota(10_000); templates[i] = generateConstructor(JsApi, isolate); @@ -162,23 +162,22 @@ pub fn create(allocator: Allocator) !Snapshot { // This must come before attachClass so inheritance is set up first inline for (JsApis, 0..) |JsApi, i| { if (comptime protoIndexLookup(JsApi)) |proto_index| { - v8.c.v8__FunctionTemplate__Inherit(templates[i], templates[proto_index]); + v8.v8__FunctionTemplate__Inherit(templates[i], templates[proto_index]); } } // Set up the global template to inherit from Window's template // This way the global object gets all Window properties through inheritance - const global_template = createGlobalTemplate(isolate, templates[0..]); - const context = v8.c.v8__Context__New(isolate, global_template, null); - v8.c.v8__Context__Enter(context); - defer v8.c.v8__Context__Exit(context); + const context = v8.v8__Context__New(isolate, global_template, null); + v8.v8__Context__Enter(context); + defer v8.v8__Context__Exit(context); // Add templates to context snapshot var last_data_index: usize = 0; inline for (JsApis, 0..) |_, i| { @setEvalBranchQuota(10_000); - const data_index = v8.c.v8__SnapshotCreator__AddData2(snapshot_creator, context, @ptrCast(templates[i])); + const data_index = v8.v8__SnapshotCreator__AddData2(snapshot_creator, context, @ptrCast(templates[i])); if (i == 0) { data_start = data_index; last_data_index = data_index; @@ -196,18 +195,18 @@ pub fn create(allocator: Allocator) !Snapshot { } // Realize all templates by getting their functions and attaching to global - const global_obj = v8.c.v8__Context__Global(context); + const global_obj = v8.v8__Context__Global(context); inline for (JsApis, 0..) |JsApi, i| { - const func = v8.c.v8__FunctionTemplate__GetFunction(templates[i], context); + const func = v8.v8__FunctionTemplate__GetFunction(templates[i], context); // Attach to global if it has a name if (@hasDecl(JsApi.Meta, "name")) { if (@hasDecl(JsApi.Meta, "constructor_alias")) { const alias = JsApi.Meta.constructor_alias; - const v8_class_name = v8.c.v8__String__NewFromUtf8(isolate, alias.ptr, v8.c.kNormal, @intCast(alias.len)); - var maybe_result: v8.c.MaybeBool = undefined; - v8.c.v8__Object__Set(global_obj, context, v8_class_name, func, &maybe_result); + const v8_class_name = v8.v8__String__NewFromUtf8(isolate, alias.ptr, v8.kNormal, @intCast(alias.len)); + var maybe_result: v8.MaybeBool = undefined; + v8.v8__Object__Set(global_obj, context, v8_class_name, func, &maybe_result); // @TODO: This is wrong. This name should be registered with the // illegalConstructorCallback. I.e. new Image() is OK, but @@ -216,14 +215,14 @@ pub fn create(allocator: Allocator) !Snapshot { // has to be registered so, for now, instead of creating another // template, we just hook it into the constructor. const name = JsApi.Meta.name; - const illegal_class_name = v8.c.v8__String__NewFromUtf8(isolate, name.ptr, v8.c.kNormal, @intCast(name.len)); - var maybe_result2: v8.c.MaybeBool = undefined; - v8.c.v8__Object__Set(global_obj, context, illegal_class_name, func, &maybe_result2); + const illegal_class_name = v8.v8__String__NewFromUtf8(isolate, name.ptr, v8.kNormal, @intCast(name.len)); + var maybe_result2: v8.MaybeBool = undefined; + v8.v8__Object__Set(global_obj, context, illegal_class_name, func, &maybe_result2); } else { const name = JsApi.Meta.name; - const v8_class_name = v8.c.v8__String__NewFromUtf8(isolate, name.ptr, v8.c.kNormal, @intCast(name.len)); - var maybe_result: v8.c.MaybeBool = undefined; - v8.c.v8__Object__Set(global_obj, context, v8_class_name, func, &maybe_result); + const v8_class_name = v8.v8__String__NewFromUtf8(isolate, name.ptr, v8.kNormal, @intCast(name.len)); + var maybe_result: v8.MaybeBool = undefined; + v8.v8__Object__Set(global_obj, context, v8_class_name, func, &maybe_result); } } } @@ -231,9 +230,9 @@ pub fn create(allocator: Allocator) !Snapshot { { // If we want to overwrite the built-in console, we have to // delete the built-in one. - const console_key = v8.c.v8__String__NewFromUtf8(isolate, "console", v8.c.kNormal, 7); - var maybe_deleted: v8.c.MaybeBool = undefined; - v8.c.v8__Object__Delete(global_obj, context, console_key, &maybe_deleted); + const console_key = v8.v8__String__NewFromUtf8(isolate, "console", v8.kNormal, 7); + var maybe_deleted: v8.MaybeBool = undefined; + v8.v8__Object__Delete(global_obj, context, console_key, &maybe_deleted); if (maybe_deleted.value == false) { return error.ConsoleDeleteError; } @@ -244,14 +243,14 @@ pub fn create(allocator: Allocator) !Snapshot { // TODO: see if newer V8 engines have a way around this. inline for (JsApis, 0..) |JsApi, i| { if (comptime protoIndexLookup(JsApi)) |proto_index| { - const proto_func = v8.c.v8__FunctionTemplate__GetFunction(templates[proto_index], context); - const proto_obj: *const v8.c.Object = @ptrCast(proto_func); + const proto_func = v8.v8__FunctionTemplate__GetFunction(templates[proto_index], context); + const proto_obj: *const v8.Object = @ptrCast(proto_func); - const self_func = v8.c.v8__FunctionTemplate__GetFunction(templates[i], context); - const self_obj: *const v8.c.Object = @ptrCast(self_func); + const self_func = v8.v8__FunctionTemplate__GetFunction(templates[i], context); + const self_obj: *const v8.Object = @ptrCast(self_func); - var maybe_result: v8.c.MaybeBool = undefined; - v8.c.v8__Object__SetPrototype(self_obj, context, proto_obj, &maybe_result); + var maybe_result: v8.MaybeBool = undefined; + v8.v8__Object__SetPrototype(self_obj, context, proto_obj, &maybe_result); } } @@ -259,15 +258,15 @@ pub fn create(allocator: Allocator) !Snapshot { // Custom exception // TODO: this is an horrible hack, I can't figure out how to do this cleanly. const code_str = "DOMException.prototype.__proto__ = Error.prototype"; - const code = v8.c.v8__String__NewFromUtf8(isolate, code_str.ptr, v8.c.kNormal, @intCast(code_str.len)); - const script = v8.c.v8__Script__Compile(context, code, null) orelse return error.ScriptCompileFailed; - _ = v8.c.v8__Script__Run(script, context) orelse return error.ScriptRunFailed; + const code = v8.v8__String__NewFromUtf8(isolate, code_str.ptr, v8.kNormal, @intCast(code_str.len)); + const script = v8.v8__Script__Compile(context, code, null) orelse return error.ScriptCompileFailed; + _ = v8.v8__Script__Run(script, context) orelse return error.ScriptRunFailed; } - v8.c.v8__SnapshotCreator__setDefaultContext(snapshot_creator, context); + v8.v8__SnapshotCreator__setDefaultContext(snapshot_creator, context); } - const blob = v8.c.v8__SnapshotCreator__createBlob(snapshot_creator, v8.c.kKeep); + const blob = v8.v8__SnapshotCreator__createBlob(snapshot_creator, v8.kKeep); const owned = try allocator.dupe(u8, blob.data[0..@intCast(blob.raw_size)]); return .{ @@ -383,7 +382,7 @@ fn collectExternalReferences() [countExternalReferences()]isize { // via `new ClassName()` - but they could, for example, be created in // Zig and returned from a function call, which is why we need the // FunctionTemplate. -fn generateConstructor(comptime JsApi: type, isolate: *v8.c.Isolate) *v8.c.FunctionTemplate { +fn generateConstructor(comptime JsApi: type, isolate: *v8.Isolate) *v8.FunctionTemplate { const callback = blk: { if (@hasDecl(JsApi, "constructor")) { break :blk JsApi.constructor.func; @@ -393,24 +392,23 @@ fn generateConstructor(comptime JsApi: type, isolate: *v8.c.Isolate) *v8.c.Funct break :blk illegalConstructorCallback; }; - const template = @constCast(v8.c.v8__FunctionTemplate__New__DEFAULT2(isolate, callback).?); + const template = @constCast(v8.v8__FunctionTemplate__New__DEFAULT2(isolate, callback).?); if (!@hasDecl(JsApi.Meta, "empty_with_no_proto")) { - const instance_template = v8.c.v8__FunctionTemplate__InstanceTemplate(template); - v8.c.v8__ObjectTemplate__SetInternalFieldCount(instance_template, 1); + const instance_template = v8.v8__FunctionTemplate__InstanceTemplate(template); + v8.v8__ObjectTemplate__SetInternalFieldCount(instance_template, 1); } const name_str = if (@hasDecl(JsApi.Meta, "name")) JsApi.Meta.name else @typeName(JsApi); - const class_name = v8.c.v8__String__NewFromUtf8(isolate, name_str.ptr, v8.c.kNormal, @intCast(name_str.len)); - v8.c.v8__FunctionTemplate__SetClassName(template, class_name); + const class_name = v8.v8__String__NewFromUtf8(isolate, name_str.ptr, v8.kNormal, @intCast(name_str.len)); + v8.v8__FunctionTemplate__SetClassName(template, class_name); return template; } // Attaches JsApi members to the prototype template (normal case) - fn attachClass(comptime JsApi: type, isolate: *v8.Isolate, template: *v8.FunctionTemplate) void { const target = v8.c.v8__FunctionTemplate__PrototypeTemplate(template); const instance = v8.c.v8__FunctionTemplate__InstanceTemplate(template); - const declarations = @typeInfo(JsApi).@"struct".decls; + inline for (declarations) |d| { const name: [:0]const u8 = d.name; const value = @field(JsApi, name); @@ -418,31 +416,31 @@ fn attachClass(comptime JsApi: type, isolate: *v8.Isolate, template: *v8.Functio switch (definition) { bridge.Accessor => { - const js_name = v8.c.v8__String__NewFromUtf8(isolate, name.ptr, v8.c.kNormal, @intCast(name.len)); - const getter_callback = @constCast(v8.c.v8__FunctionTemplate__New__DEFAULT2(isolate, value.getter).?); + const js_name = v8.v8__String__NewFromUtf8(isolate, name.ptr, v8.kNormal, @intCast(name.len)); + const getter_callback = @constCast(v8.v8__FunctionTemplate__New__DEFAULT2(isolate, value.getter).?); if (value.setter == null) { if (value.static) { - v8.c.v8__Template__SetAccessorProperty__DEFAULT(@ptrCast(template), js_name, getter_callback); + v8.v8__Template__SetAccessorProperty__DEFAULT(@ptrCast(template), js_name, getter_callback); } else { - v8.c.v8__ObjectTemplate__SetAccessorProperty__DEFAULT(target, js_name, getter_callback); + v8.v8__ObjectTemplate__SetAccessorProperty__DEFAULT(target, js_name, getter_callback); } } else { std.debug.assert(value.static == false); - const setter_callback = @constCast(v8.c.v8__FunctionTemplate__New__DEFAULT2(isolate, value.setter.?).?); - v8.c.v8__ObjectTemplate__SetAccessorProperty__DEFAULT2(target, js_name, getter_callback, setter_callback); + const setter_callback = @constCast(v8.v8__FunctionTemplate__New__DEFAULT2(isolate, value.setter.?).?); + v8.v8__ObjectTemplate__SetAccessorProperty__DEFAULT2(target, js_name, getter_callback, setter_callback); } }, bridge.Function => { - const function_template = @constCast(v8.c.v8__FunctionTemplate__New__DEFAULT2(isolate, value.func).?); - const js_name = v8.c.v8__String__NewFromUtf8(isolate, name.ptr, v8.c.kNormal, @intCast(name.len)); + const function_template = @constCast(v8.v8__FunctionTemplate__New__DEFAULT2(isolate, value.func).?); + const js_name = v8.v8__String__NewFromUtf8(isolate, name.ptr, v8.kNormal, @intCast(name.len)); if (value.static) { - v8.c.v8__Template__Set(@ptrCast(template), js_name, @ptrCast(function_template), v8.c.None); + v8.v8__Template__Set(@ptrCast(template), js_name, @ptrCast(function_template), v8.None); } else { - v8.c.v8__Template__Set(@ptrCast(target), js_name, @ptrCast(function_template), v8.c.None); + v8.v8__Template__Set(@ptrCast(target), js_name, @ptrCast(function_template), v8.None); } }, bridge.Indexed => { - var configuration: v8.c.IndexedPropertyHandlerConfiguration = .{ + var configuration: v8.IndexedPropertyHandlerConfiguration = .{ .getter = value.getter, .setter = null, .query = null, @@ -453,11 +451,10 @@ fn attachClass(comptime JsApi: type, isolate: *v8.Isolate, template: *v8.Functio .data = null, .flags = 0, }; - instance.setIndexedProperty(configuration, null); + v8.v8__ObjectTemplate__SetIndexedHandler(instance, &configuration); }, bridge.NamedIndexed => { - const instance_template = v8.c.v8__FunctionTemplate__InstanceTemplate(template); - var configuration: v8.c.NamedPropertyHandlerConfiguration = .{ + var configuration: v8.NamedPropertyHandlerConfiguration = .{ .getter = value.getter, .setter = value.setter, .query = null, @@ -466,17 +463,17 @@ fn attachClass(comptime JsApi: type, isolate: *v8.Isolate, template: *v8.Functio .definer = null, .descriptor = null, .data = null, - .flags = v8.c.kOnlyInterceptStrings | v8.c.kNonMasking, + .flags = v8.kOnlyInterceptStrings | v8.kNonMasking, }; - v8.c.v8__ObjectTemplate__SetNamedHandler(instance, &configuration); + v8.v8__ObjectTemplate__SetNamedHandler(instance, &configuration); }, bridge.Iterator => { - const function_template = @constCast(v8.c.v8__FunctionTemplate__New__DEFAULT2(isolate, value.func).?); + const function_template = @constCast(v8.v8__FunctionTemplate__New__DEFAULT2(isolate, value.func).?); const js_name = if (value.async) - v8.c.v8__Symbol__GetAsyncIterator(isolate) + v8.v8__Symbol__GetAsyncIterator(isolate) else - v8.c.v8__Symbol__GetIterator(isolate); - v8.c.v8__Template__Set(@ptrCast(target), js_name, @ptrCast(function_template), v8.c.None); + v8.v8__Symbol__GetIterator(isolate); + v8.v8__Template__Set(@ptrCast(target), js_name, @ptrCast(function_template), v8.None); }, bridge.Property => { // simpleZigValueToJs now returns raw handle directly @@ -484,12 +481,12 @@ fn attachClass(comptime JsApi: type, isolate: *v8.Isolate, template: *v8.Functio .int => |v| js.simpleZigValueToJs(.{ .handle = isolate }, v, true, false), }; - const js_name = v8.c.v8__String__NewFromUtf8(isolate, name.ptr, v8.c.kNormal, @intCast(name.len)); + const js_name = v8.v8__String__NewFromUtf8(isolate, name.ptr, v8.kNormal, @intCast(name.len)); // apply it both to the type itself - v8.c.v8__Template__Set(@ptrCast(template), js_name, js_value, v8.c.ReadOnly + v8.c.DontDelete); + v8.v8__Template__Set(@ptrCast(template), js_name, js_value, v8.ReadOnly + v8.DontDelete); // and to instances of the type - v8.c.v8__Template__Set(@ptrCast(target), js_name, js_value, v8.c.ReadOnly + v8.c.DontDelete); + v8.v8__Template__Set(@ptrCast(target), js_name, js_value, v8.ReadOnly + v8.DontDelete); }, bridge.Constructor => {}, // already handled in generateConstructor else => {}, @@ -521,15 +518,15 @@ fn protoIndexLookup(comptime JsApi: type) ?bridge.JsApiLookup.BackingInt { } // Shared illegal constructor callback for types without explicit constructors -fn illegalConstructorCallback(raw_info: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void { - const isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(raw_info); +fn illegalConstructorCallback(raw_info: ?*const v8.FunctionCallbackInfo) callconv(.c) void { + const isolate = v8.v8__FunctionCallbackInfo__GetIsolate(raw_info); log.warn(.js, "Illegal constructor call", .{}); - const message = v8.c.v8__String__NewFromUtf8(isolate, "Illegal Constructor", v8.c.kNormal, 19); - const js_exception = v8.c.v8__Exception__TypeError(message); + const message = v8.v8__String__NewFromUtf8(isolate, "Illegal Constructor", v8.kNormal, 19); + const js_exception = v8.v8__Exception__TypeError(message); - _ = v8.c.v8__Isolate__ThrowException(isolate, js_exception); - var return_value: v8.c.ReturnValue = undefined; - v8.c.v8__FunctionCallbackInfo__GetReturnValue(raw_info, &return_value); - v8.c.v8__ReturnValue__Set(return_value, js_exception); + _ = v8.v8__Isolate__ThrowException(isolate, js_exception); + var return_value: v8.ReturnValue = undefined; + v8.v8__FunctionCallbackInfo__GetReturnValue(raw_info, &return_value); + v8.v8__ReturnValue__Set(return_value, js_exception); } diff --git a/src/browser/js/String.zig b/src/browser/js/String.zig index a170e538..4fb9b395 100644 --- a/src/browser/js/String.zig +++ b/src/browser/js/String.zig @@ -26,7 +26,7 @@ const v8 = js.v8; const String = @This(); ctx: *js.Context, -handle: *const v8.c.String, +handle: *const v8.String, pub const ToZigOpts = struct { allocator: ?Allocator = null, @@ -43,11 +43,11 @@ pub fn toZigZ(self: String, opts: ToZigOpts) ![:0]u8 { fn _toZig(self: String, comptime null_terminate: bool, opts: ToZigOpts) !(if (null_terminate) [:0]u8 else []u8) { const isolate = self.ctx.isolate.handle; const allocator = opts.allocator orelse self.ctx.call_arena; - const len: u32 = @intCast(v8.c.v8__String__Utf8Length(self.handle, isolate)); + const len: u32 = @intCast(v8.v8__String__Utf8Length(self.handle, isolate)); const buf = if (null_terminate) try allocator.allocSentinel(u8, len, 0) else try allocator.alloc(u8, len); - const options = v8.c.NO_NULL_TERMINATION | v8.c.REPLACE_INVALID_UTF8; - const n = v8.c.v8__String__WriteUtf8(self.handle, isolate, buf.ptr, buf.len, options); + const options = v8.NO_NULL_TERMINATION | v8.REPLACE_INVALID_UTF8; + const n = v8.v8__String__WriteUtf8(self.handle, isolate, buf.ptr, buf.len, options); std.debug.assert(n == len); return buf; } diff --git a/src/browser/js/TryCatch.zig b/src/browser/js/TryCatch.zig index 7fc49598..7009682b 100644 --- a/src/browser/js/TryCatch.zig +++ b/src/browser/js/TryCatch.zig @@ -25,20 +25,20 @@ const Allocator = std.mem.Allocator; const TryCatch = @This(); ctx: *js.Context, -handle: v8.c.TryCatch, +handle: v8.TryCatch, pub fn init(self: *TryCatch, ctx: *js.Context) void { self.ctx = ctx; - v8.c.v8__TryCatch__CONSTRUCT(&self.handle, ctx.isolate.handle); + v8.v8__TryCatch__CONSTRUCT(&self.handle, ctx.isolate.handle); } pub fn hasCaught(self: TryCatch) bool { - return v8.c.v8__TryCatch__HasCaught(&self.handle); + return v8.v8__TryCatch__HasCaught(&self.handle); } // the caller needs to deinit the string returned pub fn exception(self: TryCatch, allocator: Allocator) !?[]const u8 { - const msg_value = v8.c.v8__TryCatch__Exception(&self.handle) orelse return null; + const msg_value = v8.v8__TryCatch__Exception(&self.handle) orelse return null; const msg = js.Value{ .ctx = self.ctx, .handle = msg_value }; return try self.ctx.valueToString(msg, .{ .allocator = allocator }); } @@ -46,7 +46,7 @@ pub fn exception(self: TryCatch, allocator: Allocator) !?[]const u8 { // the caller needs to deinit the string returned pub fn stack(self: TryCatch, allocator: Allocator) !?[]const u8 { const ctx = self.ctx; - const s_value = v8.c.v8__TryCatch__StackTrace(&self.handle, ctx.handle) orelse return null; + const s_value = v8.v8__TryCatch__StackTrace(&self.handle, ctx.handle) orelse return null; const s = js.Value{ .ctx = ctx, .handle = s_value }; return try ctx.valueToString(s, .{ .allocator = allocator }); } @@ -54,15 +54,15 @@ pub fn stack(self: TryCatch, allocator: Allocator) !?[]const u8 { // the caller needs to deinit the string returned pub fn sourceLine(self: TryCatch, allocator: Allocator) !?[]const u8 { const ctx = self.ctx; - const msg = v8.c.v8__TryCatch__Message(&self.handle) orelse return null; - const source_line_handle = v8.c.v8__Message__GetSourceLine(msg, ctx.handle) orelse return null; + const msg = v8.v8__TryCatch__Message(&self.handle) orelse return null; + const source_line_handle = v8.v8__Message__GetSourceLine(msg, ctx.handle) orelse return null; return try ctx.jsStringToZig(source_line_handle, .{ .allocator = allocator }); } pub fn sourceLineNumber(self: TryCatch) ?u32 { const ctx = self.ctx; - const msg = v8.c.v8__TryCatch__Message(&self.handle) orelse return null; - const line = v8.c.v8__Message__GetLineNumber(msg, ctx.handle); + const msg = v8.v8__TryCatch__Message(&self.handle) orelse return null; + const line = v8.v8__Message__GetLineNumber(msg, ctx.handle); if (line < 0) { return null; } @@ -84,5 +84,5 @@ pub fn err(self: TryCatch, allocator: Allocator) !?[]const u8 { } pub fn deinit(self: *TryCatch) void { - v8.c.v8__TryCatch__DESTRUCT(&self.handle); + v8.v8__TryCatch__DESTRUCT(&self.handle); } diff --git a/src/browser/js/Value.zig b/src/browser/js/Value.zig index a08254d0..cce891a3 100644 --- a/src/browser/js/Value.zig +++ b/src/browser/js/Value.zig @@ -28,18 +28,18 @@ const Allocator = std.mem.Allocator; const Value = @This(); ctx: *js.Context, -handle: *const v8.c.Value, +handle: *const v8.Value, pub fn isObject(self: Value) bool { - return v8.c.v8__Value__IsObject(self.handle); + return v8.v8__Value__IsObject(self.handle); } pub fn isString(self: Value) bool { - return v8.c.v8__Value__IsString(self.handle); + return v8.v8__Value__IsString(self.handle); } pub fn isArray(self: Value) bool { - return v8.c.v8__Value__IsArray(self.handle); + return v8.v8__Value__IsArray(self.handle); } pub fn isNull(self: Value) bool { @@ -51,123 +51,123 @@ pub fn isUndefined(self: Value) bool { } pub fn isSymbol(self: Value) bool { - return v8.c.v8__Value__IsSymbol(self.handle); + return v8.v8__Value__IsSymbol(self.handle); } pub fn isFunction(self: Value) bool { - return v8.c.v8__Value__IsFunction(self.handle); + return v8.v8__Value__IsFunction(self.handle); } pub fn isNull(self: Value) bool { - return v8.c.v8__Value__IsNull(self.handle); + return v8.v8__Value__IsNull(self.handle); } pub fn isUndefined(self: Value) bool { - return v8.c.v8__Value__IsUndefined(self.handle); + return v8.v8__Value__IsUndefined(self.handle); } pub fn isNullOrUndefined(self: Value) bool { - return v8.c.v8__Value__IsNullOrUndefined(self.handle); + return v8.v8__Value__IsNullOrUndefined(self.handle); } pub fn isNumber(self: Value) bool { - return v8.c.v8__Value__IsNumber(self.handle); + return v8.v8__Value__IsNumber(self.handle); } pub fn isNumberObject(self: Value) bool { - return v8.c.v8__Value__IsNumberObject(self.handle); + return v8.v8__Value__IsNumberObject(self.handle); } pub fn isInt32(self: Value) bool { - return v8.c.v8__Value__IsInt32(self.handle); + return v8.v8__Value__IsInt32(self.handle); } pub fn isUint32(self: Value) bool { - return v8.c.v8__Value__IsUint32(self.handle); + return v8.v8__Value__IsUint32(self.handle); } pub fn isBigInt(self: Value) bool { - return v8.c.v8__Value__IsBigInt(self.handle); + return v8.v8__Value__IsBigInt(self.handle); } pub fn isBigIntObject(self: Value) bool { - return v8.c.v8__Value__IsBigIntObject(self.handle); + return v8.v8__Value__IsBigIntObject(self.handle); } pub fn isBoolean(self: Value) bool { - return v8.c.v8__Value__IsBoolean(self.handle); + return v8.v8__Value__IsBoolean(self.handle); } pub fn isBooleanObject(self: Value) bool { - return v8.c.v8__Value__IsBooleanObject(self.handle); + return v8.v8__Value__IsBooleanObject(self.handle); } pub fn isTrue(self: Value) bool { - return v8.c.v8__Value__IsTrue(self.handle); + return v8.v8__Value__IsTrue(self.handle); } pub fn isFalse(self: Value) bool { - return v8.c.v8__Value__IsFalse(self.handle); + return v8.v8__Value__IsFalse(self.handle); } pub fn isTypedArray(self: Value) bool { - return v8.c.v8__Value__IsTypedArray(self.handle); + return v8.v8__Value__IsTypedArray(self.handle); } pub fn isArrayBufferView(self: Value) bool { - return v8.c.v8__Value__IsArrayBufferView(self.handle); + return v8.v8__Value__IsArrayBufferView(self.handle); } pub fn isArrayBuffer(self: Value) bool { - return v8.c.v8__Value__IsArrayBuffer(self.handle); + return v8.v8__Value__IsArrayBuffer(self.handle); } pub fn isUint8Array(self: Value) bool { - return v8.c.v8__Value__IsUint8Array(self.handle); + return v8.v8__Value__IsUint8Array(self.handle); } pub fn isUint8ClampedArray(self: Value) bool { - return v8.c.v8__Value__IsUint8ClampedArray(self.handle); + return v8.v8__Value__IsUint8ClampedArray(self.handle); } pub fn isInt8Array(self: Value) bool { - return v8.c.v8__Value__IsInt8Array(self.handle); + return v8.v8__Value__IsInt8Array(self.handle); } pub fn isUint16Array(self: Value) bool { - return v8.c.v8__Value__IsUint16Array(self.handle); + return v8.v8__Value__IsUint16Array(self.handle); } pub fn isInt16Array(self: Value) bool { - return v8.c.v8__Value__IsInt16Array(self.handle); + return v8.v8__Value__IsInt16Array(self.handle); } pub fn isUint32Array(self: Value) bool { - return v8.c.v8__Value__IsUint32Array(self.handle); + return v8.v8__Value__IsUint32Array(self.handle); } pub fn isInt32Array(self: Value) bool { - return v8.c.v8__Value__IsInt32Array(self.handle); + return v8.v8__Value__IsInt32Array(self.handle); } pub fn isBigUint64Array(self: Value) bool { - return v8.c.v8__Value__IsBigUint64Array(self.handle); + return v8.v8__Value__IsBigUint64Array(self.handle); } pub fn isBigInt64Array(self: Value) bool { - return v8.c.v8__Value__IsBigInt64Array(self.handle); + return v8.v8__Value__IsBigInt64Array(self.handle); } pub fn isPromise(self: Value) bool { - return v8.c.v8__Value__IsPromise(self.handle); + return v8.v8__Value__IsPromise(self.handle); } pub fn toBool(self: Value) bool { - return v8.c.v8__Value__BooleanValue(self.handle, self.ctx.isolate.handle); + return v8.v8__Value__BooleanValue(self.handle, self.ctx.isolate.handle); } pub fn typeOf(self: Value) js.String { - const str_handle = v8.c.v8__Value__TypeOf(self.handle, self.ctx.isolate.handle).?; + const str_handle = v8.v8__Value__TypeOf(self.handle, self.ctx.isolate.handle).?; return js.String{ .ctx = @constCast(self.ctx), .handle = str_handle }; } @@ -176,8 +176,8 @@ pub fn toF32(self: Value) !f32 { } pub fn toF64(self: Value) !f64 { - var maybe: v8.c.MaybeF64 = undefined; - v8.c.v8__Value__NumberValue(self.handle, self.ctx.handle, &maybe); + var maybe: v8.MaybeF64 = undefined; + v8.v8__Value__NumberValue(self.handle, self.ctx.handle, &maybe); if (!maybe.has_value) { return error.JsException; } @@ -185,8 +185,8 @@ pub fn toF64(self: Value) !f64 { } pub fn toI32(self: Value) !i32 { - var maybe: v8.c.MaybeI32 = undefined; - v8.c.v8__Value__Int32Value(self.handle, self.ctx.handle, &maybe); + var maybe: v8.MaybeI32 = undefined; + v8.v8__Value__Int32Value(self.handle, self.ctx.handle, &maybe); if (!maybe.has_value) { return error.JsException; } @@ -194,8 +194,8 @@ pub fn toI32(self: Value) !i32 { } pub fn toU32(self: Value) !u32 { - var maybe: v8.c.MaybeU32 = undefined; - v8.c.v8__Value__Uint32Value(self.handle, self.ctx.handle, &maybe); + var maybe: v8.MaybeU32 = undefined; + v8.v8__Value__Uint32Value(self.handle, self.ctx.handle, &maybe); if (!maybe.has_value) { return error.JsException; } @@ -223,11 +223,11 @@ fn _toString(self: Value, comptime null_terminate: bool, opts: js.String.ToZigOp const ctx: *js.Context = @constCast(self.ctx); if (self.isSymbol()) { - const sym_handle = v8.c.v8__Symbol__Description(@ptrCast(self.handle), ctx.isolate.handle).?; + const sym_handle = v8.v8__Symbol__Description(@ptrCast(self.handle), ctx.isolate.handle).?; return _toString(.{ .handle = @ptrCast(sym_handle), .ctx = ctx }, null_terminate, opts); } - const str_handle = v8.c.v8__Value__ToString(self.handle, ctx.handle) orelse { + const str_handle = v8.v8__Value__ToString(self.handle, ctx.handle) orelse { return error.JsException; }; diff --git a/src/browser/js/bridge.zig b/src/browser/js/bridge.zig index 223e3fc2..2d2adace 100644 --- a/src/browser/js/bridge.zig +++ b/src/browser/js/bridge.zig @@ -38,71 +38,71 @@ const IS_DEBUG = @import("builtin").mode == .Debug; // They are not exported - internal to this module only. const Value = struct { - handle: *const v8.c.Value, + handle: *const v8.Value, fn isArray(self: Value) bool { - return v8.c.v8__Value__IsArray(self.handle); + return v8.v8__Value__IsArray(self.handle); } fn isTypedArray(self: Value) bool { - return v8.c.v8__Value__IsTypedArray(self.handle); + return v8.v8__Value__IsTypedArray(self.handle); } fn isFunction(self: Value) bool { - return v8.c.v8__Value__IsFunction(self.handle); + return v8.v8__Value__IsFunction(self.handle); } }; const Name = struct { - handle: *const v8.c.Name, + handle: *const v8.Name, }; const FunctionCallbackInfo = struct { - handle: *const v8.c.FunctionCallbackInfo, + handle: *const v8.FunctionCallbackInfo, fn length(self: FunctionCallbackInfo) u32 { - return @intCast(v8.c.v8__FunctionCallbackInfo__Length(self.handle)); + return @intCast(v8.v8__FunctionCallbackInfo__Length(self.handle)); } fn getArg(self: FunctionCallbackInfo, index: u32) Value { - return .{ .handle = v8.c.v8__FunctionCallbackInfo__INDEX(self.handle, @intCast(index)).? }; + return .{ .handle = v8.v8__FunctionCallbackInfo__INDEX(self.handle, @intCast(index)).? }; } - fn getThis(self: FunctionCallbackInfo) *const v8.c.Object { - return v8.c.v8__FunctionCallbackInfo__This(self.handle).?; + fn getThis(self: FunctionCallbackInfo) *const v8.Object { + return v8.v8__FunctionCallbackInfo__This(self.handle).?; } fn getReturnValue(self: FunctionCallbackInfo) ReturnValue { - var rv: v8.c.ReturnValue = undefined; - v8.c.v8__FunctionCallbackInfo__GetReturnValue(self.handle, &rv); + var rv: v8.ReturnValue = undefined; + v8.v8__FunctionCallbackInfo__GetReturnValue(self.handle, &rv); return .{ .handle = rv }; } }; const PropertyCallbackInfo = struct { - handle: *const v8.c.PropertyCallbackInfo, + handle: *const v8.PropertyCallbackInfo, - fn getThis(self: PropertyCallbackInfo) *const v8.c.Object { - return v8.c.v8__PropertyCallbackInfo__This(self.handle).?; + fn getThis(self: PropertyCallbackInfo) *const v8.Object { + return v8.v8__PropertyCallbackInfo__This(self.handle).?; } fn getReturnValue(self: PropertyCallbackInfo) ReturnValue { - var rv: v8.c.ReturnValue = undefined; - v8.c.v8__PropertyCallbackInfo__GetReturnValue(self.handle, &rv); + var rv: v8.ReturnValue = undefined; + v8.v8__PropertyCallbackInfo__GetReturnValue(self.handle, &rv); return .{ .handle = rv }; } }; const ReturnValue = struct { - handle: v8.c.ReturnValue, + handle: v8.ReturnValue, fn set(self: ReturnValue, value: anytype) void { const T = @TypeOf(value); if (T == Value) { self.setValueHandle(value.handle); - } else if (T == *const v8.c.Object) { + } else if (T == *const v8.Object) { self.setValueHandle(@ptrCast(value)); - } else if (T == *const v8.c.Value) { + } else if (T == *const v8.Value) { self.setValueHandle(value); } else if (T == js.Value) { self.setValueHandle(value.handle); @@ -111,8 +111,8 @@ const ReturnValue = struct { } } - fn setValueHandle(self: ReturnValue, handle: *const v8.c.Value) void { - v8.c.v8__ReturnValue__Set(self.handle, handle); + fn setValueHandle(self: ReturnValue, handle: *const v8.Value) void { + v8.v8__ReturnValue__Set(self.handle, handle); } }; @@ -126,12 +126,12 @@ pub const Caller = struct { call_arena: Allocator, // Takes the raw v8 isolate and extracts the context from it. - pub fn init(v8_isolate: *v8.c.Isolate) Caller { + pub fn init(v8_isolate: *v8.Isolate) Caller { const isolate = js.Isolate{ .handle = v8_isolate }; - const v8_context_handle = v8.c.v8__Isolate__GetCurrentContext(v8_isolate); - const embedder_data = v8.c.v8__Context__GetEmbedderData(v8_context_handle, 1); + const v8_context_handle = v8.v8__Isolate__GetCurrentContext(v8_isolate); + const embedder_data = v8.v8__Context__GetEmbedderData(v8_context_handle, 1); var lossless: bool = undefined; - const context: *Context = @ptrFromInt(v8.c.v8__BigInt__Uint64Value(embedder_data, &lossless)); + const context: *Context = @ptrFromInt(v8.v8__BigInt__Uint64Value(embedder_data, &lossless)); context.call_depth += 1; return .{ @@ -197,9 +197,9 @@ pub const Caller = struct { // If we got back a different object (existing wrapper), copy the prototype // from new object. (this happens when we're upgrading an CustomElement) if (this.handle != new_this_handle) { - const prototype_handle = v8.c.v8__Object__GetPrototype(new_this_handle).?; - var out: v8.c.MaybeBool = undefined; - v8.c.v8__Object__SetPrototype(this.handle, self.context.handle, prototype_handle, &out); + const prototype_handle = v8.v8__Object__GetPrototype(new_this_handle).?; + var out: v8.MaybeBool = undefined; + v8.v8__Object__SetPrototype(this.handle, self.context.handle, prototype_handle, &out); if (comptime IS_DEBUG) { std.debug.assert(out.has_value and out.value); } @@ -364,7 +364,7 @@ pub const Caller = struct { } } - const js_err: *const v8.c.Value = switch (err) { + const js_err: *const v8.Value = switch (err) { error.InvalidArgument => isolate.createTypeError("invalid argument"), error.OutOfMemory => isolate.createError("out of memory"), error.IllegalConstructor => isolate.createError("Illegal Contructor"), @@ -624,7 +624,7 @@ pub fn Builder(comptime T: type) type { } pub const Constructor = struct { - func: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void, + func: *const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void, const Opts = struct { dom_exception: bool = false, @@ -632,8 +632,8 @@ pub const Constructor = struct { fn init(comptime T: type, comptime func: anytype, comptime opts: Opts) Constructor { return .{ .func = struct { - fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void { - const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?; + fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void { + const v8_isolate = v8.v8__FunctionCallbackInfo__GetIsolate(handle).?; var caller = Caller.init(v8_isolate); defer caller.deinit(); @@ -648,7 +648,7 @@ pub const Constructor = struct { pub const Function = struct { static: bool, - func: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void, + func: *const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void, const Opts = struct { static: bool = false, @@ -661,8 +661,8 @@ pub const Function = struct { return .{ .static = opts.static, .func = struct { - fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void { - const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?; + fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void { + const v8_isolate = v8.v8__FunctionCallbackInfo__GetIsolate(handle).?; var caller = Caller.init(v8_isolate); defer caller.deinit(); @@ -688,8 +688,8 @@ pub const Function = struct { pub const Accessor = struct { static: bool = false, - getter: ?*const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void = null, - setter: ?*const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void = null, + getter: ?*const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void = null, + setter: ?*const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void = null, const Opts = struct { static: bool = false, @@ -705,8 +705,8 @@ pub const Accessor = struct { if (@typeInfo(@TypeOf(getter)) != .null) { accessor.getter = struct { - fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void { - const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?; + fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void { + const v8_isolate = v8.v8__FunctionCallbackInfo__GetIsolate(handle).?; var caller = Caller.init(v8_isolate); defer caller.deinit(); @@ -721,8 +721,8 @@ pub const Accessor = struct { if (@typeInfo(@TypeOf(setter)) != .null) { accessor.setter = struct { - fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void { - const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?; + fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void { + const v8_isolate = v8.v8__FunctionCallbackInfo__GetIsolate(handle).?; var caller = Caller.init(v8_isolate); defer caller.deinit(); @@ -742,7 +742,7 @@ pub const Accessor = struct { }; pub const Indexed = struct { - getter: *const fn (idx: u32, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8, + getter: *const fn (idx: u32, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8, const Opts = struct { as_typed_array: bool = false, @@ -751,8 +751,8 @@ pub const Indexed = struct { fn init(comptime T: type, comptime getter: anytype, comptime opts: Opts) Indexed { return .{ .getter = struct { - fn wrap(idx: u32, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 { - const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(handle).?; + fn wrap(idx: u32, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 { + const v8_isolate = v8.v8__PropertyCallbackInfo__GetIsolate(handle).?; var caller = Caller.init(v8_isolate); defer caller.deinit(); @@ -767,9 +767,9 @@ pub const Indexed = struct { }; pub const NamedIndexed = struct { - 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, handle: ?*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, + getter: *const fn (c_name: ?*const v8.Name, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8, + setter: ?*const fn (c_name: ?*const v8.Name, c_value: ?*const v8.Value, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 = null, + deleter: ?*const fn (c_name: ?*const v8.Name, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 = null, const Opts = struct { as_typed_array: bool = false, @@ -778,8 +778,8 @@ pub const NamedIndexed = struct { fn init(comptime T: type, comptime getter: anytype, setter: anytype, deleter: anytype, comptime opts: Opts) NamedIndexed { const getter_fn = struct { - fn wrap(c_name: ?*const v8.c.Name, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 { - const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(handle).?; + fn wrap(c_name: ?*const v8.Name, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 { + const v8_isolate = v8.v8__PropertyCallbackInfo__GetIsolate(handle).?; var caller = Caller.init(v8_isolate); defer caller.deinit(); @@ -792,8 +792,8 @@ pub const NamedIndexed = struct { }.wrap; 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, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 { - const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(handle).?; + fn wrap(c_name: ?*const v8.Name, c_value: ?*const v8.Value, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 { + const v8_isolate = v8.v8__PropertyCallbackInfo__GetIsolate(handle).?; var caller = Caller.init(v8_isolate); defer caller.deinit(); @@ -806,8 +806,8 @@ pub const NamedIndexed = struct { }.wrap; const deleter_fn = if (@typeInfo(@TypeOf(deleter)) == .null) null else struct { - fn wrap(c_name: ?*const v8.c.Name, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 { - const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(handle).?; + fn wrap(c_name: ?*const v8.Name, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 { + const v8_isolate = v8.v8__PropertyCallbackInfo__GetIsolate(handle).?; var caller = Caller.init(v8_isolate); defer caller.deinit(); @@ -828,7 +828,7 @@ pub const NamedIndexed = struct { }; pub const Iterator = struct { - func: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void, + func: *const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void, async: bool, const Opts = struct { @@ -841,7 +841,7 @@ pub const Iterator = struct { return .{ .async = opts.async, .func = struct { - fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void { + fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void { const info = FunctionCallbackInfo{ .handle = handle.? }; info.getReturnValue().set(info.getThis()); } @@ -852,8 +852,8 @@ pub const Iterator = struct { return .{ .async = opts.async, .func = struct { - fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void { - const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?; + fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void { + const v8_isolate = v8.v8__FunctionCallbackInfo__GetIsolate(handle).?; var caller = Caller.init(v8_isolate); defer caller.deinit(); @@ -866,7 +866,7 @@ pub const Iterator = struct { }; pub const Callable = struct { - func: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void, + func: *const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void, const Opts = struct { null_as_undefined: bool = false, @@ -874,8 +874,8 @@ pub const Callable = struct { fn init(comptime T: type, comptime func: anytype, comptime opts: Opts) Callable { return .{ .func = struct { - fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void { - const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?; + fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void { + const v8_isolate = v8.v8__FunctionCallbackInfo__GetIsolate(handle).?; var caller = Caller.init(v8_isolate); defer caller.deinit(); diff --git a/src/browser/js/global.zig b/src/browser/js/global.zig index 82c2c55b..9bfe782d 100644 --- a/src/browser/js/global.zig +++ b/src/browser/js/global.zig @@ -25,20 +25,20 @@ pub fn Global(comptime T: type) type { const H = @FieldType(T, "handle"); return struct { - global: v8.c.Global, + global: v8.Global, const Self = @This(); - pub fn init(isolate: *v8.c.Isolate, handle: H) Self { - var global: v8.c.Global = undefined; - v8.c.v8__Global__New(isolate, handle, &global); + pub fn init(isolate: *v8.Isolate, handle: H) Self { + var global: v8.Global = undefined; + v8.v8__Global__New(isolate, handle, &global); return .{ .global = global, }; } pub fn deinit(self: *Self) void { - v8.c.v8__Global__Reset(&self.global); + v8.v8__Global__Reset(&self.global); } pub fn local(self: *const Self) H { diff --git a/src/browser/js/js.zig b/src/browser/js/js.zig index 6b895687..bf7f3044 100644 --- a/src/browser/js/js.zig +++ b/src/browser/js/js.zig @@ -17,7 +17,7 @@ // along with this program. If not, see . const std = @import("std"); -pub const v8 = @import("v8"); +pub const v8 = @import("v8").c; const log = @import("../../log.zig"); @@ -79,7 +79,7 @@ pub const ArrayBuffer = struct { pub const Exception = struct { ctx: *const Context, - handle: *const v8.c.Value, + handle: *const v8.Value, pub fn exception(self: Exception, allocator: Allocator) ![]const u8 { return self.context.valueToString(self.inner, .{ .allocator = allocator }); @@ -167,7 +167,7 @@ pub fn isComplexAttributeType(ti: std.builtin.Type) bool { // These are simple types that we can convert to JS with only an isolate. This // is separated from the Caller's zigValueToJs to make it available when we // don't have a caller (i.e., when setting static attributes on types) -pub fn simpleZigValueToJs(isolate: Isolate, value: anytype, comptime fail: bool, comptime null_as_undefined: bool) if (fail) *const v8.c.Value else ?*const v8.c.Value { +pub fn simpleZigValueToJs(isolate: Isolate, value: anytype, comptime fail: bool, comptime null_as_undefined: bool) if (fail) *const v8.Value else ?*const v8.Value { switch (@typeInfo(@TypeOf(value))) { .void => return isolate.initUndefined(), .null => if (comptime null_as_undefined) return isolate.initUndefined() else return isolate.initNull(), @@ -214,11 +214,11 @@ pub fn simpleZigValueToJs(isolate: Isolate, value: anytype, comptime fail: bool, ArrayBuffer => { const values = value.values; const len = values.len; - const backing_store = v8.c.v8__ArrayBuffer__NewBackingStore(isolate.handle, len); - const data: [*]u8 = @ptrCast(@alignCast(v8.c.v8__BackingStore__Data(backing_store))); + const backing_store = v8.v8__ArrayBuffer__NewBackingStore(isolate.handle, len); + const data: [*]u8 = @ptrCast(@alignCast(v8.v8__BackingStore__Data(backing_store))); @memcpy(data[0..len], @as([]const u8, @ptrCast(values))[0..len]); - const backing_store_ptr = v8.c.v8__BackingStore__TO_SHARED_PTR(backing_store); - return @ptrCast(v8.c.v8__ArrayBuffer__New2(isolate.handle, &backing_store_ptr).?); + const backing_store_ptr = v8.v8__BackingStore__TO_SHARED_PTR(backing_store); + return @ptrCast(v8.v8__ArrayBuffer__New2(isolate.handle, &backing_store_ptr).?); }, // zig fmt: off TypedArray(u8), TypedArray(u16), TypedArray(u32), TypedArray(u64), @@ -235,38 +235,38 @@ pub fn simpleZigValueToJs(isolate: Isolate, value: anytype, comptime fail: bool, else => @compileError("Invalid TypeArray type: " ++ @typeName(value_type)), }; - var array_buffer: *const v8.c.ArrayBuffer = undefined; + var array_buffer: *const v8.ArrayBuffer = undefined; if (len == 0) { - array_buffer = v8.c.v8__ArrayBuffer__New(isolate.handle, 0).?; + array_buffer = v8.v8__ArrayBuffer__New(isolate.handle, 0).?; } else { const buffer_len = len * bits / 8; - const backing_store = v8.c.v8__ArrayBuffer__NewBackingStore(isolate.handle, buffer_len).?; - const data: [*]u8 = @ptrCast(@alignCast(v8.c.v8__BackingStore__Data(backing_store))); + const backing_store = v8.v8__ArrayBuffer__NewBackingStore(isolate.handle, buffer_len).?; + const data: [*]u8 = @ptrCast(@alignCast(v8.v8__BackingStore__Data(backing_store))); @memcpy(data[0..buffer_len], @as([]const u8, @ptrCast(values))[0..buffer_len]); - const backing_store_ptr = v8.c.v8__BackingStore__TO_SHARED_PTR(backing_store); - array_buffer = v8.c.v8__ArrayBuffer__New2(isolate.handle, &backing_store_ptr).?; + const backing_store_ptr = v8.v8__BackingStore__TO_SHARED_PTR(backing_store); + array_buffer = v8.v8__ArrayBuffer__New2(isolate.handle, &backing_store_ptr).?; } switch (@typeInfo(value_type)) { .int => |n| switch (n.signedness) { .unsigned => switch (n.bits) { - 8 => return @ptrCast(v8.c.v8__Uint8Array__New(array_buffer, 0, len).?), - 16 => return @ptrCast(v8.c.v8__Uint16Array__New(array_buffer, 0, len).?), - 32 => return @ptrCast(v8.c.v8__Uint32Array__New(array_buffer, 0, len).?), - 64 => return @ptrCast(v8.c.v8__BigUint64Array__New(array_buffer, 0, len).?), + 8 => return @ptrCast(v8.v8__Uint8Array__New(array_buffer, 0, len).?), + 16 => return @ptrCast(v8.v8__Uint16Array__New(array_buffer, 0, len).?), + 32 => return @ptrCast(v8.v8__Uint32Array__New(array_buffer, 0, len).?), + 64 => return @ptrCast(v8.v8__BigUint64Array__New(array_buffer, 0, len).?), else => {}, }, .signed => switch (n.bits) { - 8 => return @ptrCast(v8.c.v8__Int8Array__New(array_buffer, 0, len).?), - 16 => return @ptrCast(v8.c.v8__Int16Array__New(array_buffer, 0, len).?), - 32 => return @ptrCast(v8.c.v8__Int32Array__New(array_buffer, 0, len).?), - 64 => return @ptrCast(v8.c.v8__BigInt64Array__New(array_buffer, 0, len).?), + 8 => return @ptrCast(v8.v8__Int8Array__New(array_buffer, 0, len).?), + 16 => return @ptrCast(v8.v8__Int16Array__New(array_buffer, 0, len).?), + 32 => return @ptrCast(v8.v8__Int32Array__New(array_buffer, 0, len).?), + 64 => return @ptrCast(v8.v8__BigInt64Array__New(array_buffer, 0, len).?), else => {}, }, }, .float => |f| switch (f.bits) { - 32 => return @ptrCast(v8.c.v8__Float32Array__New(array_buffer, 0, len).?), - 64 => return @ptrCast(v8.c.v8__Float64Array__New(array_buffer, 0, len).?), + 32 => return @ptrCast(v8.v8__Float32Array__New(array_buffer, 0, len).?), + 64 => return @ptrCast(v8.v8__Float64Array__New(array_buffer, 0, len).?), else => {}, }, else => {}, @@ -367,8 +367,8 @@ pub const PrototypeChainEntry = struct { // it'll call this function to gets its [optional] subtype - which, from V8's // point of view, is an arbitrary string. pub export fn v8_inspector__Client__IMPL__valueSubtype( - _: *v8.c.InspectorClientImpl, - c_value: *const v8.c.Value, + _: *v8.InspectorClientImpl, + c_value: *const v8.Value, ) callconv(.c) [*c]const u8 { const external_entry = Inspector.getTaggedAnyOpaque(c_value) orelse return null; return if (external_entry.subtype) |st| @tagName(st) else null; @@ -379,9 +379,9 @@ pub export fn v8_inspector__Client__IMPL__valueSubtype( // present, even if it's empty. So if we have a subType for the value, we'll // put an empty description. pub export fn v8_inspector__Client__IMPL__descriptionForValueSubtype( - _: *v8.c.InspectorClientImpl, - v8_context: *const v8.c.Context, - c_value: *const v8.c.Value, + _: *v8.InspectorClientImpl, + v8_context: *const v8.Context, + c_value: *const v8.Value, ) callconv(.c) [*c]const u8 { _ = v8_context;