mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
js.v8 is not equal to js.v8.c
This means the C funtions/types now sit in the root of v8.
This commit is contained in:
@@ -23,17 +23,17 @@ const v8 = js.v8;
|
|||||||
const Array = @This();
|
const Array = @This();
|
||||||
|
|
||||||
ctx: *js.Context,
|
ctx: *js.Context,
|
||||||
handle: *const v8.c.Array,
|
handle: *const v8.Array,
|
||||||
|
|
||||||
pub fn len(self: Array) usize {
|
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 {
|
pub fn get(self: Array, index: u32) !js.Value {
|
||||||
const ctx = self.ctx;
|
const ctx = self.ctx;
|
||||||
|
|
||||||
const idx = js.Integer.init(ctx.isolate.handle, index);
|
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;
|
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);
|
const js_value = try ctx.zigValueToJs(value, opts);
|
||||||
|
|
||||||
var out: v8.c.MaybeBool = undefined;
|
var out: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Object__SetAtIndex(@ptrCast(self.handle), ctx.handle, index, js_value.handle, &out);
|
v8.v8__Object__SetAtIndex(@ptrCast(self.handle), ctx.handle, index, js_value.handle, &out);
|
||||||
return out.has_value;
|
return out.has_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,23 +21,23 @@ const v8 = js.v8;
|
|||||||
|
|
||||||
const BigInt = @This();
|
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)) {
|
const handle = switch (@TypeOf(val)) {
|
||||||
i8, i16, i32, i64, isize => v8.c.v8__BigInt__New(isolate, val).?,
|
i8, i16, i32, i64, isize => v8.v8__BigInt__New(isolate, val).?,
|
||||||
u8, u16, u32, u64, usize => v8.c.v8__BigInt__NewFromUnsigned(isolate, val).?,
|
u8, u16, u32, u64, usize => v8.v8__BigInt__NewFromUnsigned(isolate, val).?,
|
||||||
else => |T| @compileError("cannot create v8::BigInt from: " ++ @typeName(T)),
|
else => |T| @compileError("cannot create v8::BigInt from: " ++ @typeName(T)),
|
||||||
};
|
};
|
||||||
return .{ .handle = handle };
|
return .{ .handle = handle };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getInt64(self: BigInt) i64 {
|
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 {
|
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 {
|
pub fn toValue(self: BigInt) js.Value {
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ id: usize,
|
|||||||
page: *Page,
|
page: *Page,
|
||||||
isolate: js.Isolate,
|
isolate: js.Isolate,
|
||||||
// This context is a persistent object. The persistent needs to be recovered and reset.
|
// This context is a persistent object. The persistent needs to be recovered and reset.
|
||||||
handle: *const v8.c.Context,
|
handle: *const v8.Context,
|
||||||
|
|
||||||
handle_scope: ?js.HandleScope,
|
handle_scope: ?js.HandleScope,
|
||||||
|
|
||||||
cpu_profiler: ?*v8.c.CpuProfiler = null,
|
cpu_profiler: ?*v8.CpuProfiler = null,
|
||||||
|
|
||||||
// references Env.templates
|
// references Env.templates
|
||||||
templates: []*const v8.c.FunctionTemplate,
|
templates: []*const v8.FunctionTemplate,
|
||||||
|
|
||||||
// Arena for the lifetime of the context
|
// Arena for the lifetime of the context
|
||||||
arena: Allocator,
|
arena: Allocator,
|
||||||
@@ -115,21 +115,21 @@ const ModuleEntry = struct {
|
|||||||
resolver_promise: ?js.Promise = null,
|
resolver_promise: ?js.Promise = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn fromC(c_context: *const v8.c.Context) *Context {
|
pub fn fromC(c_context: *const v8.Context) *Context {
|
||||||
const data = v8.c.v8__Context__GetEmbedderData(c_context, 1).?;
|
const data = v8.v8__Context__GetEmbedderData(c_context, 1).?;
|
||||||
const big_int = js.BigInt{ .handle = @ptrCast(data) };
|
const big_int = js.BigInt{ .handle = @ptrCast(data) };
|
||||||
return @ptrFromInt(big_int.getUint64());
|
return @ptrFromInt(big_int.getUint64());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fromIsolate(isolate: js.Isolate) *Context {
|
pub fn fromIsolate(isolate: js.Isolate) *Context {
|
||||||
const v8_context = v8.c.v8__Isolate__GetCurrentContext(isolate.handle).?;
|
const v8_context = v8.v8__Isolate__GetCurrentContext(isolate.handle).?;
|
||||||
const data = v8.c.v8__Context__GetEmbedderData(v8_context, 1).?;
|
const data = v8.v8__Context__GetEmbedderData(v8_context, 1).?;
|
||||||
const big_int = js.BigInt{ .handle = @ptrCast(data) };
|
const big_int = js.BigInt{ .handle = @ptrCast(data) };
|
||||||
return @ptrFromInt(big_int.getUint64());
|
return @ptrFromInt(big_int.getUint64());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setupGlobal(self: *Context) !void {
|
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);
|
_ = try self.mapZigInstanceToJs(global, self.page.window);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ pub fn deinit(self: *Context) void {
|
|||||||
|
|
||||||
if (self.handle_scope) |*scope| {
|
if (self.handle_scope) |*scope| {
|
||||||
scope.deinit();
|
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 {
|
pub fn newObject(self: *Context) js.Object {
|
||||||
return .{
|
return .{
|
||||||
.ctx = self,
|
.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 {
|
pub fn newArray(self: *Context, len: u32) js.Array {
|
||||||
return .{
|
return .{
|
||||||
.ctx = self,
|
.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 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 .{
|
return .{
|
||||||
.ctx = self,
|
.ctx = self,
|
||||||
.handle = handle,
|
.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 {
|
pub fn parseJSON(self: *Context, json: []const u8) !js.Value {
|
||||||
const string_handle = self.isolate.initStringHandle(json);
|
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 .{
|
return .{
|
||||||
.ctx = self,
|
.ctx = self,
|
||||||
.handle = value_handle,
|
.handle = value_handle,
|
||||||
@@ -371,7 +371,7 @@ pub fn throw(self: *Context, err: []const u8) js.Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn debugContextId(self: *const Context) i32 {
|
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 {
|
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
|
// 4 - Store our TaggedAnyOpaque into the persistent object
|
||||||
// 5 - Update our identity_map (so that, if we return this same instance again,
|
// 5 - Update our identity_map (so that, if we return this same instance again,
|
||||||
// we can just grab it from the identity_map)
|
// 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 arena = self.arena;
|
||||||
|
|
||||||
const T = @TypeOf(value);
|
const T = @TypeOf(value);
|
||||||
@@ -572,8 +572,8 @@ pub fn mapZigInstanceToJs(self: *Context, js_obj_handle: ?*const v8.c.Object, va
|
|||||||
.ctx = self,
|
.ctx = self,
|
||||||
.handle = js_obj_handle orelse blk: {
|
.handle = js_obj_handle orelse blk: {
|
||||||
const function_template_handle = self.templates[resolved.class_id];
|
const function_template_handle = self.templates[resolved.class_id];
|
||||||
const object_template_handle = v8.c.v8__FunctionTemplate__InstanceTemplate(function_template_handle).?;
|
const object_template_handle = v8.v8__FunctionTemplate__InstanceTemplate(function_template_handle).?;
|
||||||
break :blk v8.c.v8__ObjectTemplate__NewInstance(object_template_handle, self.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)
|
// Skip setting internal field for the global object (Window)
|
||||||
// Window accessors get the instance from context.page.window instead
|
// Window accessors get the instance from context.page.window instead
|
||||||
if (resolved.class_id != @import("../webapi/Window.zig").JsApi.Meta.class_id) {
|
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 {
|
} else {
|
||||||
// If the struct is empty, we don't need to do all
|
// 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 {
|
fn jsValueToTypedArray(_: *Context, comptime T: type, js_value: js.Value) !?[]T {
|
||||||
var force_u8 = false;
|
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_len: usize = undefined;
|
||||||
var byte_offset: usize = undefined;
|
var byte_offset: usize = undefined;
|
||||||
|
|
||||||
if (js_value.isTypedArray()) {
|
if (js_value.isTypedArray()) {
|
||||||
const buffer_handle: *const v8.c.ArrayBufferView = @ptrCast(js_value.handle);
|
const buffer_handle: *const v8.ArrayBufferView = @ptrCast(js_value.handle);
|
||||||
byte_len = v8.c.v8__ArrayBufferView__ByteLength(buffer_handle);
|
byte_len = v8.v8__ArrayBufferView__ByteLength(buffer_handle);
|
||||||
byte_offset = v8.c.v8__ArrayBufferView__ByteOffset(buffer_handle);
|
byte_offset = v8.v8__ArrayBufferView__ByteOffset(buffer_handle);
|
||||||
array_buffer = v8.c.v8__ArrayBufferView__Buffer(buffer_handle).?;
|
array_buffer = v8.v8__ArrayBufferView__Buffer(buffer_handle).?;
|
||||||
} else if (js_value.isArrayBufferView()) {
|
} else if (js_value.isArrayBufferView()) {
|
||||||
force_u8 = true;
|
force_u8 = true;
|
||||||
const buffer_handle: *const v8.c.ArrayBufferView = @ptrCast(js_value.handle);
|
const buffer_handle: *const v8.ArrayBufferView = @ptrCast(js_value.handle);
|
||||||
byte_len = v8.c.v8__ArrayBufferView__ByteLength(buffer_handle);
|
byte_len = v8.v8__ArrayBufferView__ByteLength(buffer_handle);
|
||||||
byte_offset = v8.c.v8__ArrayBufferView__ByteOffset(buffer_handle);
|
byte_offset = v8.v8__ArrayBufferView__ByteOffset(buffer_handle);
|
||||||
array_buffer = v8.c.v8__ArrayBufferView__Buffer(buffer_handle).?;
|
array_buffer = v8.v8__ArrayBufferView__Buffer(buffer_handle).?;
|
||||||
} else if (js_value.isArrayBuffer()) {
|
} else if (js_value.isArrayBuffer()) {
|
||||||
force_u8 = true;
|
force_u8 = true;
|
||||||
array_buffer = @ptrCast(js_value.handle);
|
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;
|
byte_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const backing_store_ptr = v8.c.v8__ArrayBuffer__GetBackingStore(array_buffer orelse return null);
|
const backing_store_ptr = v8.v8__ArrayBuffer__GetBackingStore(array_buffer orelse return null);
|
||||||
const backing_store_handle = v8.c.std__shared_ptr__v8__BackingStore__get(&backing_store_ptr).?;
|
const backing_store_handle = v8.std__shared_ptr__v8__BackingStore__get(&backing_store_ptr).?;
|
||||||
const data = v8.c.v8__BackingStore__Data(backing_store_handle);
|
const data = v8.v8__BackingStore__Data(backing_store_handle);
|
||||||
|
|
||||||
switch (T) {
|
switch (T) {
|
||||||
u8 => {
|
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) {
|
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()) {
|
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);
|
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;
|
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) {
|
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 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 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 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);
|
std.debug.assert(n == len);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
@@ -1037,7 +1037,7 @@ fn _debugValue(self: *Context, js_val: js.Value, seen: *std.AutoHashMapUnmanaged
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (js_val.isSymbol()) {
|
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 }, .{});
|
const js_sym_str = try self.valueToString(.{ .ctx = self, .handle = symbol_handle }, .{});
|
||||||
return writer.print("{s} (symbol)", .{js_sym_str});
|
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 buf: std.ArrayList(u8) = .empty;
|
||||||
var writer = buf.writer(self.call_arena);
|
var writer = buf.writer(self.call_arena);
|
||||||
|
|
||||||
const stack_trace_handle = v8.c.v8__StackTrace__CurrentStackTrace__STATIC(isolate.handle, 30).?;
|
const stack_trace_handle = v8.v8__StackTrace__CurrentStackTrace__STATIC(isolate.handle, 30).?;
|
||||||
const frame_count = v8.c.v8__StackTrace__GetFrameCount(stack_trace_handle);
|
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, .{}) });
|
try writer.print("{s}<{s}>", .{ separator, try self.jsStringToZig(script, .{}) });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (0..@intCast(frame_count)) |i| {
|
for (0..@intCast(frame_count)) |i| {
|
||||||
const frame_handle = v8.c.v8__StackTrace__GetFrame(stack_trace_handle, isolate.handle, @intCast(i)).?;
|
const frame_handle = v8.v8__StackTrace__GetFrame(stack_trace_handle, isolate.handle, @intCast(i)).?;
|
||||||
if (v8.c.v8__StackFrame__GetFunctionName(frame_handle)) |name| {
|
if (v8.v8__StackFrame__GetFunctionName(frame_handle)) |name| {
|
||||||
const script = try self.jsStringToZig(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 {
|
} else {
|
||||||
try writer.print("{s}<anonymous>:{d}", .{ separator, v8.c.v8__StackFrame__GetLineNumber(frame_handle) });
|
try writer.print("{s}<anonymous>:{d}", .{ separator, v8.v8__StackFrame__GetLineNumber(frame_handle) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buf.items;
|
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
|
// Callback from V8, asking us to load a module. The "specifier" is
|
||||||
// the src of the module to load.
|
// the src of the module to load.
|
||||||
fn resolveModuleCallback(
|
fn resolveModuleCallback(
|
||||||
c_context: ?*const v8.c.Context,
|
c_context: ?*const v8.Context,
|
||||||
c_specifier: ?*const v8.c.String,
|
c_specifier: ?*const v8.String,
|
||||||
import_attributes: ?*const v8.c.FixedArray,
|
import_attributes: ?*const v8.FixedArray,
|
||||||
c_referrer: ?*const v8.c.Module,
|
c_referrer: ?*const v8.Module,
|
||||||
) callconv(.c) ?*const v8.c.Module {
|
) callconv(.c) ?*const v8.Module {
|
||||||
_ = import_attributes;
|
_ = import_attributes;
|
||||||
|
|
||||||
const self = fromC(c_context.?);
|
const self = fromC(c_context.?);
|
||||||
@@ -1177,12 +1177,12 @@ fn resolveModuleCallback(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn dynamicModuleCallback(
|
pub fn dynamicModuleCallback(
|
||||||
c_context: ?*const v8.c.Context,
|
c_context: ?*const v8.Context,
|
||||||
host_defined_options: ?*const v8.c.Data,
|
host_defined_options: ?*const v8.Data,
|
||||||
resource_name: ?*const v8.c.Value,
|
resource_name: ?*const v8.Value,
|
||||||
v8_specifier: ?*const v8.c.String,
|
v8_specifier: ?*const v8.String,
|
||||||
import_attrs: ?*const v8.c.FixedArray,
|
import_attrs: ?*const v8.FixedArray,
|
||||||
) callconv(.c) ?*v8.c.Promise {
|
) callconv(.c) ?*v8.Promise {
|
||||||
_ = host_defined_options;
|
_ = host_defined_options;
|
||||||
_ = import_attrs;
|
_ = import_attrs;
|
||||||
|
|
||||||
@@ -1216,7 +1216,7 @@ pub fn dynamicModuleCallback(
|
|||||||
return @constCast(promise.handle);
|
return @constCast(promise.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn metaObjectCallback(c_context: ?*v8.c.Context, c_module: ?*v8.c.Module, c_meta: ?*v8.c.Value) callconv(.c) void {
|
pub fn metaObjectCallback(c_context: ?*v8.Context, c_module: ?*v8.Module, c_meta: ?*v8.Value) callconv(.c) void {
|
||||||
const self = fromC(c_context.?);
|
const self = fromC(c_context.?);
|
||||||
const m = js.Module{ .ctx = self, .handle = c_module.? };
|
const m = js.Module{ .ctx = self, .handle = c_module.? };
|
||||||
const meta = js.Object{ .ctx = self, .handle = @ptrCast(c_meta.?) };
|
const meta = js.Object{ .ctx = self, .handle = @ptrCast(c_meta.?) };
|
||||||
@@ -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 {
|
const referrer_path = self.module_identifier.get(referrer.getIdentityHash()) orelse {
|
||||||
// Shouldn't be possible.
|
// Shouldn't be possible.
|
||||||
return error.UnknownModuleReferrer;
|
return error.UnknownModuleReferrer;
|
||||||
@@ -1420,13 +1420,13 @@ fn resolveDynamicModule(self: *Context, state: *DynamicModuleResolveState, modul
|
|||||||
// resolve to the module's namespace.
|
// resolve to the module's namespace.
|
||||||
|
|
||||||
const then_callback = self.newFunctionWithData(struct {
|
const then_callback = self.newFunctionWithData(struct {
|
||||||
pub fn callback(callback_handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
|
pub fn callback(callback_handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void {
|
||||||
const isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(callback_handle).?;
|
const isolate = v8.v8__FunctionCallbackInfo__GetIsolate(callback_handle).?;
|
||||||
var caller = Caller.init(isolate);
|
var caller = Caller.init(isolate);
|
||||||
defer caller.deinit();
|
defer caller.deinit();
|
||||||
|
|
||||||
const info_data = v8.c.v8__FunctionCallbackInfo__Data(callback_handle).?;
|
const info_data = v8.v8__FunctionCallbackInfo__Data(callback_handle).?;
|
||||||
const s: *DynamicModuleResolveState = @ptrCast(@alignCast(v8.c.v8__External__Value(@ptrCast(info_data))));
|
const s: *DynamicModuleResolveState = @ptrCast(@alignCast(v8.v8__External__Value(@ptrCast(info_data))));
|
||||||
|
|
||||||
if (s.context_id != caller.context.id) {
|
if (s.context_id != caller.context.id) {
|
||||||
// The microtask is tied to the isolate, not the context
|
// The microtask is tied to the isolate, not the context
|
||||||
@@ -1444,13 +1444,13 @@ fn resolveDynamicModule(self: *Context, state: *DynamicModuleResolveState, modul
|
|||||||
}.callback, @ptrCast(state));
|
}.callback, @ptrCast(state));
|
||||||
|
|
||||||
const catch_callback = self.newFunctionWithData(struct {
|
const catch_callback = self.newFunctionWithData(struct {
|
||||||
pub fn callback(callback_handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
|
pub fn callback(callback_handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void {
|
||||||
const isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(callback_handle).?;
|
const isolate = v8.v8__FunctionCallbackInfo__GetIsolate(callback_handle).?;
|
||||||
var caller = Caller.init(isolate);
|
var caller = Caller.init(isolate);
|
||||||
defer caller.deinit();
|
defer caller.deinit();
|
||||||
|
|
||||||
const info_data = v8.c.v8__FunctionCallbackInfo__Data(callback_handle).?;
|
const info_data = v8.v8__FunctionCallbackInfo__Data(callback_handle).?;
|
||||||
const s: *DynamicModuleResolveState = @ptrCast(@alignCast(v8.c.v8__External__Value(@ptrCast(info_data))));
|
const s: *DynamicModuleResolveState = @ptrCast(@alignCast(v8.v8__External__Value(@ptrCast(info_data))));
|
||||||
|
|
||||||
const ctx = caller.context;
|
const ctx = caller.context;
|
||||||
if (s.context_id != ctx.id) {
|
if (s.context_id != ctx.id) {
|
||||||
@@ -1460,7 +1460,7 @@ fn resolveDynamicModule(self: *Context, state: *DynamicModuleResolveState, modul
|
|||||||
defer ctx.runMicrotasks();
|
defer ctx.runMicrotasks();
|
||||||
_ = s.resolver.reject("catch callback", js.Value{
|
_ = s.resolver.reject("catch callback", js.Value{
|
||||||
.ctx = ctx,
|
.ctx = ctx,
|
||||||
.handle = v8.c.v8__FunctionCallbackInfo__Data(callback_handle).?,
|
.handle = v8.v8__FunctionCallbackInfo__Data(callback_handle).?,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}.callback, @ptrCast(state));
|
}.callback, @ptrCast(state));
|
||||||
@@ -1478,7 +1478,7 @@ fn resolveDynamicModule(self: *Context, state: *DynamicModuleResolveState, modul
|
|||||||
|
|
||||||
// Reverses the mapZigInstanceToJs, making sure that our TaggedAnyOpaque
|
// Reverses the mapZigInstanceToJs, making sure that our TaggedAnyOpaque
|
||||||
// contains a ptr to the correct type.
|
// 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);
|
const ti = @typeInfo(R);
|
||||||
if (ti != .pointer) {
|
if (ti != .pointer) {
|
||||||
@compileError("non-pointer Zig parameter type: " ++ @typeName(R));
|
@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, &.{}));
|
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
|
// Special case for Window: the global object doesn't have internal fields
|
||||||
// Window instance is stored in context.page.window instead
|
// Window instance is stored in context.page.window instead
|
||||||
if (internal_field_count == 0) {
|
if (internal_field_count == 0) {
|
||||||
// Normally, this would be an error. All JsObject that map to a Zig type
|
// 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
|
// are either `empty_with_no_proto` (handled above) or have an
|
||||||
// interalFieldCount. The only exception to that is the Window...
|
// 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 context = fromIsolate(.{ .handle = isolate });
|
||||||
|
|
||||||
const Window = @import("../webapi/Window.zig");
|
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));
|
@compileError("unknown Zig type: " ++ @typeName(R));
|
||||||
}
|
}
|
||||||
|
|
||||||
const internal_field_handle = v8.c.v8__Object__GetInternalField(js_obj_handle, 0).?;
|
const internal_field_handle = v8.v8__Object__GetInternalField(js_obj_handle, 0).?;
|
||||||
const tao: *TaggedAnyOpaque = @ptrCast(@alignCast(v8.c.v8__External__Value(internal_field_handle)));
|
const tao: *TaggedAnyOpaque = @ptrCast(@alignCast(v8.v8__External__Value(internal_field_handle)));
|
||||||
const expected_type_index = bridge.JsApiLookup.getId(JsApi);
|
const expected_type_index = bridge.JsApiLookup.getId(JsApi);
|
||||||
|
|
||||||
const prototype_chain = tao.prototype_chain[0..tao.prototype_len];
|
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);
|
const script_source = self.isolate.initStringHandle(src);
|
||||||
|
|
||||||
// Create ScriptOrigin
|
// Create ScriptOrigin
|
||||||
var origin: v8.c.ScriptOrigin = undefined;
|
var origin: v8.ScriptOrigin = undefined;
|
||||||
v8.c.v8__ScriptOrigin__CONSTRUCT(&origin, @ptrCast(script_name));
|
v8.v8__ScriptOrigin__CONSTRUCT(&origin, @ptrCast(script_name));
|
||||||
|
|
||||||
// Create ScriptCompilerSource
|
// Create ScriptCompilerSource
|
||||||
var script_comp_source: v8.c.ScriptCompilerSource = undefined;
|
var script_comp_source: v8.ScriptCompilerSource = undefined;
|
||||||
v8.c.v8__ScriptCompiler__Source__CONSTRUCT2(script_source, &origin, null, &script_comp_source);
|
v8.v8__ScriptCompiler__Source__CONSTRUCT2(script_source, &origin, null, &script_comp_source);
|
||||||
defer v8.c.v8__ScriptCompiler__Source__DESTRUCT(&script_comp_source);
|
defer v8.v8__ScriptCompiler__Source__DESTRUCT(&script_comp_source);
|
||||||
|
|
||||||
// Compile the script
|
// Compile the script
|
||||||
const v8_script = v8.c.v8__ScriptCompiler__Compile(
|
const v8_script = v8.v8__ScriptCompiler__Compile(
|
||||||
self.handle,
|
self.handle,
|
||||||
&script_comp_source,
|
&script_comp_source,
|
||||||
v8.c.kNoCompileOptions,
|
v8.kNoCompileOptions,
|
||||||
v8.c.kNoCacheNoReason,
|
v8.kNoCacheNoReason,
|
||||||
) orelse return error.CompilationError;
|
) orelse return error.CompilationError;
|
||||||
|
|
||||||
// Run the script
|
// 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 };
|
return .{ .ctx = self, .handle = result };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compileModule(self: *Context, src: []const u8, name: []const u8) !js.Module {
|
fn compileModule(self: *Context, src: []const u8, name: []const u8) !js.Module {
|
||||||
var origin_handle: v8.c.ScriptOrigin = undefined;
|
var origin_handle: v8.ScriptOrigin = undefined;
|
||||||
v8.c.v8__ScriptOrigin__CONSTRUCT2(
|
v8.v8__ScriptOrigin__CONSTRUCT2(
|
||||||
&origin_handle,
|
&origin_handle,
|
||||||
self.isolate.initStringHandle(name),
|
self.isolate.initStringHandle(name),
|
||||||
0, // resource_line_offset
|
0, // resource_line_offset
|
||||||
@@ -1858,21 +1858,21 @@ fn compileModule(self: *Context, src: []const u8, name: []const u8) !js.Module {
|
|||||||
null, // host_defined_options
|
null, // host_defined_options
|
||||||
);
|
);
|
||||||
|
|
||||||
var source_handle: v8.c.ScriptCompilerSource = undefined;
|
var source_handle: v8.ScriptCompilerSource = undefined;
|
||||||
v8.c.v8__ScriptCompiler__Source__CONSTRUCT2(
|
v8.v8__ScriptCompiler__Source__CONSTRUCT2(
|
||||||
self.isolate.initStringHandle(src),
|
self.isolate.initStringHandle(src),
|
||||||
&origin_handle,
|
&origin_handle,
|
||||||
null, // cached data
|
null, // cached data
|
||||||
&source_handle,
|
&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,
|
self.isolate.handle,
|
||||||
&source_handle,
|
&source_handle,
|
||||||
v8.c.kNoCompileOptions,
|
v8.kNoCompileOptions,
|
||||||
v8.c.kNoCacheNoReason,
|
v8.kNoCacheNoReason,
|
||||||
) orelse {
|
) orelse {
|
||||||
return error.JsException;
|
return error.JsException;
|
||||||
};
|
};
|
||||||
@@ -1998,17 +1998,17 @@ pub fn startCpuProfiler(self: *Context) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std.debug.assert(self.cpu_profiler == null);
|
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");
|
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;
|
self.cpu_profiler = cpu_profiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stopCpuProfiler(self: *Context) ![]const u8 {
|
pub fn stopCpuProfiler(self: *Context) ![]const u8 {
|
||||||
const title = self.isolate.initStringHandle("v8_cpu_profile");
|
const title = self.isolate.initStringHandle("v8_cpu_profile");
|
||||||
const handle = v8.c.v8__CpuProfiler__StopProfiling(self.cpu_profiler.?, title) orelse return error.NoProfiles;
|
const handle = v8.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 string_handle = v8.v8__CpuProfile__Serialize(handle, self.isolate.handle) orelse return error.NoProfile;
|
||||||
return self.jsStringToZig(string_handle, .{});
|
return self.jsStringToZig(string_handle, .{});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,44 +49,44 @@ platform: *const Platform,
|
|||||||
isolate: js.Isolate,
|
isolate: js.Isolate,
|
||||||
|
|
||||||
// just kept around because we need to free it on deinit
|
// just kept around because we need to free it on deinit
|
||||||
isolate_params: *v8.c.CreateParams,
|
isolate_params: *v8.CreateParams,
|
||||||
|
|
||||||
context_id: usize,
|
context_id: usize,
|
||||||
|
|
||||||
// Global handles that need to be freed on deinit
|
// 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
|
// 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 {
|
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);
|
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.snapshot_blob = @ptrCast(&snapshot.startup_data);
|
||||||
|
|
||||||
params.array_buffer_allocator = v8.c.v8__ArrayBuffer__Allocator__NewDefaultAllocator().?;
|
params.array_buffer_allocator = v8.v8__ArrayBuffer__Allocator__NewDefaultAllocator().?;
|
||||||
errdefer v8.c.v8__ArrayBuffer__Allocator__DELETE(params.array_buffer_allocator.?);
|
errdefer v8.v8__ArrayBuffer__Allocator__DELETE(params.array_buffer_allocator.?);
|
||||||
|
|
||||||
params.external_references = &snapshot.external_references;
|
params.external_references = &snapshot.external_references;
|
||||||
|
|
||||||
var isolate = js.Isolate.init(params);
|
var isolate = js.Isolate.init(params);
|
||||||
errdefer isolate.deinit();
|
errdefer isolate.deinit();
|
||||||
|
|
||||||
v8.c.v8__Isolate__SetHostImportModuleDynamicallyCallback(isolate.handle, Context.dynamicModuleCallback);
|
v8.v8__Isolate__SetHostImportModuleDynamicallyCallback(isolate.handle, Context.dynamicModuleCallback);
|
||||||
v8.c.v8__Isolate__SetPromiseRejectCallback(isolate.handle, promiseRejectCallback);
|
v8.v8__Isolate__SetPromiseRejectCallback(isolate.handle, promiseRejectCallback);
|
||||||
v8.c.v8__Isolate__SetMicrotasksPolicy(isolate.handle, v8.c.kExplicit);
|
v8.v8__Isolate__SetMicrotasksPolicy(isolate.handle, v8.kExplicit);
|
||||||
|
|
||||||
isolate.enter();
|
isolate.enter();
|
||||||
errdefer isolate.exit();
|
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
|
// 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);
|
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);
|
errdefer allocator.free(templates);
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -95,15 +95,15 @@ pub fn init(allocator: Allocator, platform: *const Platform, snapshot: *Snapshot
|
|||||||
defer temp_scope.deinit();
|
defer temp_scope.deinit();
|
||||||
const context_handle = isolate.createContextHandle(null, null);
|
const context_handle = isolate.createContextHandle(null, null);
|
||||||
|
|
||||||
v8.c.v8__Context__Enter(context_handle);
|
v8.v8__Context__Enter(context_handle);
|
||||||
defer v8.c.v8__Context__Exit(context_handle);
|
defer v8.v8__Context__Exit(context_handle);
|
||||||
|
|
||||||
inline for (JsApis, 0..) |JsApi, i| {
|
inline for (JsApis, 0..) |JsApi, i| {
|
||||||
JsApi.Meta.class_id = i;
|
JsApi.Meta.class_id = i;
|
||||||
const data = v8.c.v8__Context__GetDataFromSnapshotOnce(context_handle, snapshot.data_start + i);
|
const data = v8.v8__Context__GetDataFromSnapshotOnce(context_handle, snapshot.data_start + i);
|
||||||
const function_handle: *const v8.c.FunctionTemplate = @ptrCast(data);
|
const function_handle: *const v8.FunctionTemplate = @ptrCast(data);
|
||||||
// Make function template global/persistent
|
// 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
|
// Extract the local handle from the global for easy access
|
||||||
templates[i] = @ptrCast(@alignCast(@as(*const anyopaque, @ptrFromInt(globals[i].data_ptr))));
|
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 {
|
pub fn deinit(self: *Env) void {
|
||||||
// Free global handles before destroying the isolate
|
// Free global handles before destroying the isolate
|
||||||
for (self.globals) |*global| {
|
for (self.globals) |*global| {
|
||||||
v8.c.v8__Global__Reset(global);
|
v8.v8__Global__Reset(global);
|
||||||
}
|
}
|
||||||
self.allocator.free(self.globals);
|
self.allocator.free(self.globals);
|
||||||
self.allocator.free(self.templates);
|
self.allocator.free(self.templates);
|
||||||
|
|
||||||
self.isolate.exit();
|
self.isolate.exit();
|
||||||
self.isolate.deinit();
|
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);
|
self.allocator.destroy(self.isolate_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,11 +145,11 @@ pub fn runMicrotasks(self: *const Env) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn pumpMessageLoop(self: *const Env) bool {
|
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 {
|
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 {
|
pub fn newExecutionWorld(self: *Env) !ExecutionWorld {
|
||||||
return .{
|
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 });
|
, .{ 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 {
|
fn promiseRejectCallback(message_handle: v8.PromiseRejectMessage) callconv(.c) void {
|
||||||
const promise_handle = v8.c.v8__PromiseRejectMessage__GetPromise(&message_handle).?;
|
const promise_handle = v8.v8__PromiseRejectMessage__GetPromise(&message_handle).?;
|
||||||
const isolate_handle = v8.c.v8__Object__GetIsolate(@ptrCast(promise_handle)).?;
|
const isolate_handle = v8.v8__Object__GetIsolate(@ptrCast(promise_handle)).?;
|
||||||
const js_isolate = js.Isolate{ .handle = isolate_handle };
|
const js_isolate = js.Isolate{ .handle = isolate_handle };
|
||||||
const context = Context.fromIsolate(js_isolate);
|
const context = Context.fromIsolate(js_isolate);
|
||||||
|
|
||||||
const value =
|
const value =
|
||||||
if (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)
|
context.valueToString(.{ .ctx = context, .handle = v8_value }, .{}) catch |err| @errorName(err)
|
||||||
else
|
else
|
||||||
"no value";
|
"no value";
|
||||||
|
|||||||
@@ -81,11 +81,12 @@ pub fn createContext(self: *ExecutionWorld, page: *Page, enter: bool) !*Context
|
|||||||
temp_scope.init(isolate);
|
temp_scope.init(isolate);
|
||||||
defer temp_scope.deinit();
|
defer temp_scope.deinit();
|
||||||
|
|
||||||
|
|
||||||
// Getting this into the snapshot is tricky (anything involving the
|
// 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 func_tmpl_handle = isolate.createFunctionTemplateHandle();
|
||||||
const global_template = v8.c.v8__FunctionTemplate__InstanceTemplate(func_tmpl_handle).?;
|
const global_template = v8.v8__FunctionTemplate__InstanceTemplate(func_tmpl_handle).?;
|
||||||
var configuration: v8.c.NamedPropertyHandlerConfiguration = .{
|
var configuration: v8.NamedPropertyHandlerConfiguration = .{
|
||||||
.getter = unknownPropertyCallback,
|
.getter = unknownPropertyCallback,
|
||||||
.setter = null,
|
.setter = null,
|
||||||
.query = null,
|
.query = null,
|
||||||
@@ -94,9 +95,9 @@ pub fn createContext(self: *ExecutionWorld, page: *Page, enter: bool) !*Context
|
|||||||
.definer = null,
|
.definer = null,
|
||||||
.descriptor = null,
|
.descriptor = null,
|
||||||
.data = 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);
|
const context_handle = isolate.createContextHandle(null, null);
|
||||||
break :blk js.Global(Context).init(isolate.handle, context_handle);
|
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) {
|
if (enter) {
|
||||||
handle_scope = @as(js.HandleScope, undefined);
|
handle_scope = @as(js.HandleScope, undefined);
|
||||||
handle_scope.?.init(isolate);
|
handle_scope.?.init(isolate);
|
||||||
v8.c.v8__Context__Enter(v8_context);
|
v8.v8__Context__Enter(v8_context);
|
||||||
}
|
}
|
||||||
errdefer if (enter) {
|
errdefer if (enter) {
|
||||||
v8.c.v8__Context__Exit(v8_context);
|
v8.v8__Context__Exit(v8_context);
|
||||||
handle_scope.?.deinit();
|
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
|
// Store a pointer to our context inside the v8 context so that, given
|
||||||
// a v8 context, we can get our context out
|
// a v8 context, we can get our context out
|
||||||
const data = isolate.initBigInt(@intFromPtr(context));
|
const data = isolate.initBigInt(@intFromPtr(context));
|
||||||
v8.c.v8__Context__SetEmbedderData(context.handle, 1, @ptrCast(data.handle));
|
v8.v8__Context__SetEmbedderData(context.handle, 1, @ptrCast(data.handle));
|
||||||
|
|
||||||
try context.setupGlobal();
|
try context.setupGlobal();
|
||||||
return context;
|
return context;
|
||||||
@@ -168,8 +169,9 @@ pub fn resumeExecution(self: *const ExecutionWorld) void {
|
|||||||
self.env.isolate.cancelTerminateExecution();
|
self.env.isolate.cancelTerminateExecution();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unknownPropertyCallback(c_name: ?*const v8.c.Name, raw_info: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 {
|
|
||||||
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 context = Context.fromIsolate(.{ .handle = isolate_handle });
|
||||||
|
|
||||||
const property: ?[]u8 = context.valueToString(.{ .ctx = context, .handle = c_name.? }, .{}) catch {
|
const property: ?[]u8 = context.valueToString(.{ .ctx = context, .handle = c_name.? }, .{}) catch {
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ const Allocator = std.mem.Allocator;
|
|||||||
const Function = @This();
|
const Function = @This();
|
||||||
|
|
||||||
ctx: *js.Context,
|
ctx: *js.Context,
|
||||||
this: ?*const v8.c.Object = null,
|
this: ?*const v8.Object = null,
|
||||||
handle: *const v8.c.Function,
|
handle: *const v8.Function,
|
||||||
|
|
||||||
pub const Result = struct {
|
pub const Result = struct {
|
||||||
stack: ?[]const u8,
|
stack: ?[]const u8,
|
||||||
@@ -34,7 +34,7 @@ pub const Result = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn id(self: *const Function) u32 {
|
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 {
|
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.
|
// This creates a new instance using this Function as a constructor.
|
||||||
// const c_args = @as(?[*]const ?*c.Value, @ptrCast(&.{}));
|
// 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()) {
|
if (try_catch.hasCaught()) {
|
||||||
const allocator = ctx.call_arena;
|
const allocator = ctx.call_arena;
|
||||||
result.stack = try_catch.stack(allocator) catch null;
|
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 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: {
|
.@"struct" => |s| blk: {
|
||||||
const fields = s.fields;
|
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| {
|
inline for (fields, 0..) |f, i| {
|
||||||
js_args[i] = (try ctx.zigValueToJs(@field(aargs, f.name), .{})).handle;
|
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;
|
break :blk &cargs;
|
||||||
},
|
},
|
||||||
.pointer => blk: {
|
.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| {
|
for (args, 0..) |a, i| {
|
||||||
values[i] = (try ctx.zigValueToJs(a, .{})).handle;
|
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"),
|
else => @compileError("JS Function called with invalid paremter type"),
|
||||||
};
|
};
|
||||||
|
|
||||||
const c_args = @as(?[*]const ?*v8.c.Value, @ptrCast(js_args.ptr));
|
const c_args = @as(?[*]const ?*v8.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 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 "???"});
|
// std.debug.print("CB ERR: {s}\n", .{self.src() catch "???"});
|
||||||
return error.JSExecCallback;
|
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 {
|
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 .{
|
return .{
|
||||||
.ctx = self.ctx,
|
.ctx = self.ctx,
|
||||||
.handle = handle,
|
.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 {
|
pub fn getPropertyValue(self: *const Function, name: []const u8) !?js.Value {
|
||||||
const ctx = self.ctx;
|
const ctx = self.ctx;
|
||||||
const key = ctx.isolate.initStringHandle(name);
|
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;
|
return error.JsException;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ const v8 = js.v8;
|
|||||||
|
|
||||||
const HandleScope = @This();
|
const HandleScope = @This();
|
||||||
|
|
||||||
handle: v8.c.HandleScope,
|
handle: v8.HandleScope,
|
||||||
|
|
||||||
pub fn init(self: *HandleScope, isolate: js.Isolate) void {
|
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 {
|
pub fn deinit(self: *HandleScope) void {
|
||||||
v8.c.v8__HandleScope__DESTRUCT(&self.handle);
|
v8.v8__HandleScope__DESTRUCT(&self.handle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,17 +30,17 @@ const CLIENT_TRUST_LEVEL = 1;
|
|||||||
|
|
||||||
const Inspector = @This();
|
const Inspector = @This();
|
||||||
|
|
||||||
handle: *v8.c.Inspector,
|
handle: *v8.Inspector,
|
||||||
isolate: *v8.c.Isolate,
|
isolate: *v8.Isolate,
|
||||||
client: Client,
|
client: Client,
|
||||||
channel: Channel,
|
channel: Channel,
|
||||||
session: Session,
|
session: Session,
|
||||||
rnd: RndGen = RndGen.init(0),
|
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
|
// We expect allocator to be an arena
|
||||||
// Note: This initializes the pre-allocated inspector in-place
|
// Note: This initializes the pre-allocated inspector in-place
|
||||||
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 ContextT = @TypeOf(ctx);
|
||||||
|
|
||||||
const Container = switch (@typeInfo(ContextT)) {
|
const Container = switch (@typeInfo(ContextT)) {
|
||||||
@@ -70,7 +70,7 @@ pub fn init(self: *Inspector, isolate: *v8.c.Isolate, ctx: anytype) !void {
|
|||||||
client.setInspector(self);
|
client.setInspector(self);
|
||||||
|
|
||||||
// Now create the inspector - generateUniqueId will work because data is set
|
// 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;
|
self.handle = handle;
|
||||||
|
|
||||||
// Create the channel
|
// Create the channel
|
||||||
@@ -86,7 +86,7 @@ pub fn init(self: *Inspector, isolate: *v8.c.Isolate, ctx: anytype) !void {
|
|||||||
channel.setInspector(self);
|
channel.setInspector(self);
|
||||||
|
|
||||||
// Create the session
|
// Create the session
|
||||||
const session_handle = v8.c.v8_inspector__Inspector__Connect(
|
const session_handle = v8.v8_inspector__Inspector__Connect(
|
||||||
handle,
|
handle,
|
||||||
CONTEXT_GROUP_ID,
|
CONTEXT_GROUP_ID,
|
||||||
channel.handle,
|
channel.handle,
|
||||||
@@ -103,7 +103,7 @@ pub fn deinit(self: *const Inspector) void {
|
|||||||
self.session.deinit();
|
self.session.deinit();
|
||||||
self.client.deinit();
|
self.client.deinit();
|
||||||
self.channel.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 {
|
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)
|
// available when doing this. Pages (and thus the HandleScope)
|
||||||
// comes and goes, but CDP can keep sending messages.
|
// comes and goes, but CDP can keep sending messages.
|
||||||
const isolate = self.isolate;
|
const isolate = self.isolate;
|
||||||
var temp_scope: v8.c.HandleScope = undefined;
|
var temp_scope: v8.HandleScope = undefined;
|
||||||
v8.c.v8__HandleScope__CONSTRUCT(&temp_scope, isolate);
|
v8.v8__HandleScope__CONSTRUCT(&temp_scope, isolate);
|
||||||
defer v8.c.v8__HandleScope__DESTRUCT(&temp_scope);
|
defer v8.v8__HandleScope__DESTRUCT(&temp_scope);
|
||||||
|
|
||||||
self.session.dispatchProtocolMessage(isolate, msg);
|
self.session.dispatchProtocolMessage(isolate, msg);
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ pub fn contextCreated(
|
|||||||
aux_data: []const u8,
|
aux_data: []const u8,
|
||||||
is_default_context: bool,
|
is_default_context: bool,
|
||||||
) void {
|
) void {
|
||||||
v8.c.v8_inspector__Inspector__ContextCreated(
|
v8.v8_inspector__Inspector__ContextCreated(
|
||||||
self.handle,
|
self.handle,
|
||||||
name.ptr,
|
name.ptr,
|
||||||
name.len,
|
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);
|
const unwrapped = try self.session.unwrapObject(allocator, object_id);
|
||||||
// The values context and groupId are not used here
|
// The values context and groupId are not used here
|
||||||
const js_val = unwrapped.value;
|
const js_val = unwrapped.value;
|
||||||
if (!v8.c.v8__Value__IsObject(js_val)) {
|
if (!v8.v8__Value__IsObject(js_val)) {
|
||||||
return error.ObjectIdIsNotANode;
|
return error.ObjectIdIsNotANode;
|
||||||
}
|
}
|
||||||
const Node = @import("../webapi/Node.zig");
|
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 Context.typeTaggedAnyOpaque(*Node, @ptrCast(js_val)) catch {
|
||||||
return error.ObjectIdIsNotANode;
|
return error.ObjectIdIsNotANode;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const RemoteObject = struct {
|
pub const RemoteObject = struct {
|
||||||
handle: *v8.c.RemoteObject,
|
handle: *v8.RemoteObject,
|
||||||
|
|
||||||
pub fn deinit(self: RemoteObject) void {
|
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 {
|
pub fn getType(self: RemoteObject, allocator: Allocator) ![]const u8 {
|
||||||
var ctype_: v8.c.CZigString = .{ .ptr = null, .len = 0 };
|
var ctype_: v8.CZigString = .{ .ptr = null, .len = 0 };
|
||||||
if (!v8.c.v8_inspector__RemoteObject__getType(self.handle, &allocator, &ctype_)) return error.V8AllocFailed;
|
if (!v8.v8_inspector__RemoteObject__getType(self.handle, &allocator, &ctype_)) return error.V8AllocFailed;
|
||||||
return cZigStringToString(ctype_) orelse return error.InvalidType;
|
return cZigStringToString(ctype_) orelse return error.InvalidType;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getSubtype(self: RemoteObject, allocator: Allocator) !?[]const u8 {
|
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 };
|
var csubtype: v8.CZigString = .{ .ptr = null, .len = 0 };
|
||||||
if (!v8.c.v8_inspector__RemoteObject__getSubtype(self.handle, &allocator, &csubtype)) return error.V8AllocFailed;
|
if (!v8.v8_inspector__RemoteObject__getSubtype(self.handle, &allocator, &csubtype)) return error.V8AllocFailed;
|
||||||
return cZigStringToString(csubtype);
|
return cZigStringToString(csubtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getClassName(self: RemoteObject, allocator: Allocator) !?[]const u8 {
|
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 };
|
var cclass_name: v8.CZigString = .{ .ptr = null, .len = 0 };
|
||||||
if (!v8.c.v8_inspector__RemoteObject__getClassName(self.handle, &allocator, &cclass_name)) return error.V8AllocFailed;
|
if (!v8.v8_inspector__RemoteObject__getClassName(self.handle, &allocator, &cclass_name)) return error.V8AllocFailed;
|
||||||
return cZigStringToString(cclass_name);
|
return cZigStringToString(cclass_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDescription(self: RemoteObject, allocator: Allocator) !?[]const u8 {
|
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 };
|
var description: v8.CZigString = .{ .ptr = null, .len = 0 };
|
||||||
if (!v8.c.v8_inspector__RemoteObject__getDescription(self.handle, &allocator, &description)) return error.V8AllocFailed;
|
if (!v8.v8_inspector__RemoteObject__getDescription(self.handle, &allocator, &description)) return error.V8AllocFailed;
|
||||||
return cZigStringToString(description);
|
return cZigStringToString(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getObjectId(self: RemoteObject, allocator: Allocator) !?[]const u8 {
|
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 };
|
var cobject_id: v8.CZigString = .{ .ptr = null, .len = 0 };
|
||||||
if (!v8.c.v8_inspector__RemoteObject__getObjectId(self.handle, &allocator, &cobject_id)) return error.V8AllocFailed;
|
if (!v8.v8_inspector__RemoteObject__getObjectId(self.handle, &allocator, &cobject_id)) return error.V8AllocFailed;
|
||||||
return cZigStringToString(cobject_id);
|
return cZigStringToString(cobject_id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const Session = struct {
|
const Session = struct {
|
||||||
handle: *v8.c.InspectorSession,
|
handle: *v8.InspectorSession,
|
||||||
|
|
||||||
fn deinit(self: Session) void {
|
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 {
|
fn dispatchProtocolMessage(self: Session, isolate: *v8.Isolate, msg: []const u8) void {
|
||||||
v8.c.v8_inspector__Session__dispatchProtocolMessage(
|
v8.v8_inspector__Session__dispatchProtocolMessage(
|
||||||
self.handle,
|
self.handle,
|
||||||
isolate,
|
isolate,
|
||||||
msg.ptr,
|
msg.ptr,
|
||||||
@@ -259,13 +259,13 @@ const Session = struct {
|
|||||||
|
|
||||||
fn wrapObject(
|
fn wrapObject(
|
||||||
self: Session,
|
self: Session,
|
||||||
isolate: *v8.c.Isolate,
|
isolate: *v8.Isolate,
|
||||||
ctx: *const v8.c.Context,
|
ctx: *const v8.Context,
|
||||||
val: *const v8.c.Value,
|
val: *const v8.Value,
|
||||||
grpname: []const u8,
|
grpname: []const u8,
|
||||||
generatepreview: bool,
|
generatepreview: bool,
|
||||||
) !RemoteObject {
|
) !RemoteObject {
|
||||||
const remote_object = v8.c.v8_inspector__Session__wrapObject(
|
const remote_object = v8.v8_inspector__Session__wrapObject(
|
||||||
self.handle,
|
self.handle,
|
||||||
isolate,
|
isolate,
|
||||||
ctx,
|
ctx,
|
||||||
@@ -282,16 +282,16 @@ const Session = struct {
|
|||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
object_id: []const u8,
|
object_id: []const u8,
|
||||||
) !UnwrappedObject {
|
) !UnwrappedObject {
|
||||||
const in_object_id = v8.c.CZigString{
|
const in_object_id = v8.CZigString{
|
||||||
.ptr = object_id.ptr,
|
.ptr = object_id.ptr,
|
||||||
.len = object_id.len,
|
.len = object_id.len,
|
||||||
};
|
};
|
||||||
var out_error: v8.c.CZigString = .{ .ptr = null, .len = 0 };
|
var out_error: v8.CZigString = .{ .ptr = null, .len = 0 };
|
||||||
var out_value_handle: ?*v8.c.Value = null;
|
var out_value_handle: ?*v8.Value = null;
|
||||||
var out_context_handle: ?*v8.c.Context = null;
|
var out_context_handle: ?*v8.Context = null;
|
||||||
var out_object_group: v8.c.CZigString = .{ .ptr = null, .len = 0 };
|
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,
|
self.handle,
|
||||||
&allocator,
|
&allocator,
|
||||||
&out_error,
|
&out_error,
|
||||||
@@ -316,13 +316,13 @@ const Session = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const UnwrappedObject = struct {
|
const UnwrappedObject = struct {
|
||||||
value: *const v8.c.Value,
|
value: *const v8.Value,
|
||||||
context: *const v8.c.Context,
|
context: *const v8.Context,
|
||||||
object_group: ?[]const u8,
|
object_group: ?[]const u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
const Channel = struct {
|
const Channel = struct {
|
||||||
handle: *v8.c.InspectorChannelImpl,
|
handle: *v8.InspectorChannelImpl,
|
||||||
|
|
||||||
// callbacks
|
// callbacks
|
||||||
ctx: *anyopaque,
|
ctx: *anyopaque,
|
||||||
@@ -342,9 +342,9 @@ const Channel = struct {
|
|||||||
onNotif: onNotifFn,
|
onNotif: onNotifFn,
|
||||||
onRunMessageLoopOnPause: onRunMessageLoopOnPauseFn,
|
onRunMessageLoopOnPause: onRunMessageLoopOnPauseFn,
|
||||||
onQuitMessageLoopOnPause: onQuitMessageLoopOnPauseFn,
|
onQuitMessageLoopOnPause: onQuitMessageLoopOnPauseFn,
|
||||||
isolate: *v8.c.Isolate,
|
isolate: *v8.Isolate,
|
||||||
) Channel {
|
) Channel {
|
||||||
const handle = v8.c.v8_inspector__Channel__IMPL__CREATE(isolate);
|
const handle = v8.v8_inspector__Channel__IMPL__CREATE(isolate);
|
||||||
return .{
|
return .{
|
||||||
.handle = handle,
|
.handle = handle,
|
||||||
.ctx = ctx,
|
.ctx = ctx,
|
||||||
@@ -356,11 +356,11 @@ const Channel = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn deinit(self: Channel) void {
|
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 {
|
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 {
|
fn resp(self: Channel, call_id: u32, msg: []const u8) void {
|
||||||
@@ -373,18 +373,18 @@ const Channel = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Client = struct {
|
const Client = struct {
|
||||||
handle: *v8.c.InspectorClientImpl,
|
handle: *v8.InspectorClientImpl,
|
||||||
|
|
||||||
fn init() Client {
|
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 {
|
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 {
|
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));
|
return @ptrCast(@alignCast(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getTaggedAnyOpaque(value: *const v8.c.Value) ?*js.TaggedAnyOpaque {
|
pub fn getTaggedAnyOpaque(value: *const v8.Value) ?*js.TaggedAnyOpaque {
|
||||||
if (!v8.c.v8__Value__IsObject(value)) {
|
if (!v8.v8__Value__IsObject(value)) {
|
||||||
return null;
|
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) {
|
if (internal_field_count == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const external_value = v8.c.v8__Object__GetInternalField(value, 0).?;
|
const external_value = v8.v8__Object__GetInternalField(value, 0).?;
|
||||||
const external_data = v8.c.v8__External__Value(external_value).?;
|
const external_data = v8.v8__External__Value(external_value).?;
|
||||||
return @ptrCast(@alignCast(external_data));
|
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;
|
if (s.ptr == null) return null;
|
||||||
return s.ptr[0..s.len];
|
return s.ptr[0..s.len];
|
||||||
}
|
}
|
||||||
|
|
||||||
// C export functions for Inspector callbacks
|
// C export functions for Inspector callbacks
|
||||||
pub export fn v8_inspector__Client__IMPL__generateUniqueId(
|
pub export fn v8_inspector__Client__IMPL__generateUniqueId(
|
||||||
_: *v8.c.InspectorClientImpl,
|
_: *v8.InspectorClientImpl,
|
||||||
data: *anyopaque,
|
data: *anyopaque,
|
||||||
) callconv(.c) i64 {
|
) callconv(.c) i64 {
|
||||||
const inspector: *Inspector = @ptrCast(@alignCast(data));
|
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(
|
pub export fn v8_inspector__Client__IMPL__runMessageLoopOnPause(
|
||||||
_: *v8.c.InspectorClientImpl,
|
_: *v8.InspectorClientImpl,
|
||||||
data: *anyopaque,
|
data: *anyopaque,
|
||||||
ctx_group_id: c_int,
|
ctx_group_id: c_int,
|
||||||
) callconv(.c) void {
|
) callconv(.c) void {
|
||||||
@@ -437,7 +437,7 @@ pub export fn v8_inspector__Client__IMPL__runMessageLoopOnPause(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub export fn v8_inspector__Client__IMPL__quitMessageLoopOnPause(
|
pub export fn v8_inspector__Client__IMPL__quitMessageLoopOnPause(
|
||||||
_: *v8.c.InspectorClientImpl,
|
_: *v8.InspectorClientImpl,
|
||||||
data: *anyopaque,
|
data: *anyopaque,
|
||||||
) callconv(.c) void {
|
) callconv(.c) void {
|
||||||
const inspector: *Inspector = @ptrCast(@alignCast(data));
|
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(
|
pub export fn v8_inspector__Client__IMPL__runIfWaitingForDebugger(
|
||||||
_: *v8.c.InspectorClientImpl,
|
_: *v8.InspectorClientImpl,
|
||||||
_: *anyopaque,
|
_: *anyopaque,
|
||||||
_: c_int,
|
_: c_int,
|
||||||
) callconv(.c) void {
|
) callconv(.c) void {
|
||||||
@@ -453,27 +453,27 @@ pub export fn v8_inspector__Client__IMPL__runIfWaitingForDebugger(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub export fn v8_inspector__Client__IMPL__consoleAPIMessage(
|
pub export fn v8_inspector__Client__IMPL__consoleAPIMessage(
|
||||||
_: *v8.c.InspectorClientImpl,
|
_: *v8.InspectorClientImpl,
|
||||||
_: *anyopaque,
|
_: *anyopaque,
|
||||||
_: c_int,
|
_: c_int,
|
||||||
_: v8.c.MessageErrorLevel,
|
_: v8.MessageErrorLevel,
|
||||||
_: *v8.c.StringView,
|
_: *v8.StringView,
|
||||||
_: *v8.c.StringView,
|
_: *v8.StringView,
|
||||||
_: c_uint,
|
_: c_uint,
|
||||||
_: c_uint,
|
_: c_uint,
|
||||||
_: *v8.c.StackTrace,
|
_: *v8.StackTrace,
|
||||||
) callconv(.c) void {}
|
) callconv(.c) void {}
|
||||||
|
|
||||||
pub export fn v8_inspector__Client__IMPL__ensureDefaultContextInGroup(
|
pub export fn v8_inspector__Client__IMPL__ensureDefaultContextInGroup(
|
||||||
_: *v8.c.InspectorClientImpl,
|
_: *v8.InspectorClientImpl,
|
||||||
data: *anyopaque,
|
data: *anyopaque,
|
||||||
) callconv(.c) ?*const v8.c.Context {
|
) callconv(.c) ?*const v8.Context {
|
||||||
const inspector: *Inspector = @ptrCast(@alignCast(data));
|
const inspector: *Inspector = @ptrCast(@alignCast(data));
|
||||||
return inspector.default_context;
|
return inspector.default_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub export fn v8_inspector__Channel__IMPL__sendResponse(
|
pub export fn v8_inspector__Channel__IMPL__sendResponse(
|
||||||
_: *v8.c.InspectorChannelImpl,
|
_: *v8.InspectorChannelImpl,
|
||||||
data: *anyopaque,
|
data: *anyopaque,
|
||||||
call_id: c_int,
|
call_id: c_int,
|
||||||
msg: [*c]u8,
|
msg: [*c]u8,
|
||||||
@@ -484,7 +484,7 @@ pub export fn v8_inspector__Channel__IMPL__sendResponse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub export fn v8_inspector__Channel__IMPL__sendNotification(
|
pub export fn v8_inspector__Channel__IMPL__sendNotification(
|
||||||
_: *v8.c.InspectorChannelImpl,
|
_: *v8.InspectorChannelImpl,
|
||||||
data: *anyopaque,
|
data: *anyopaque,
|
||||||
msg: [*c]u8,
|
msg: [*c]u8,
|
||||||
length: usize,
|
length: usize,
|
||||||
@@ -494,7 +494,7 @@ pub export fn v8_inspector__Channel__IMPL__sendNotification(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub export fn v8_inspector__Channel__IMPL__flushProtocolNotifications(
|
pub export fn v8_inspector__Channel__IMPL__flushProtocolNotifications(
|
||||||
_: *v8.c.InspectorChannelImpl,
|
_: *v8.InspectorChannelImpl,
|
||||||
_: *anyopaque,
|
_: *anyopaque,
|
||||||
) callconv(.c) void {
|
) callconv(.c) void {
|
||||||
// TODO
|
// TODO
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ const v8 = js.v8;
|
|||||||
|
|
||||||
const Integer = @This();
|
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)) {
|
const handle = switch (@TypeOf(value)) {
|
||||||
i8, i16, i32 => v8.c.v8__Integer__New(isolate, value).?,
|
i8, i16, i32 => v8.v8__Integer__New(isolate, value).?,
|
||||||
u8, u16, u32 => v8.c.v8__Integer__NewFromUnsigned(isolate, value).?,
|
u8, u16, u32 => v8.v8__Integer__NewFromUnsigned(isolate, value).?,
|
||||||
else => |T| @compileError("cannot create v8::Integer from: " ++ @typeName(T)),
|
else => |T| @compileError("cannot create v8::Integer from: " ++ @typeName(T)),
|
||||||
};
|
};
|
||||||
return .{ .handle = handle };
|
return .{ .handle = handle };
|
||||||
|
|||||||
@@ -21,80 +21,80 @@ const v8 = js.v8;
|
|||||||
|
|
||||||
const Isolate = @This();
|
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 .{
|
return .{
|
||||||
.handle = v8.c.v8__Isolate__New(params).?,
|
.handle = v8.v8__Isolate__New(params).?,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: Isolate) void {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
pub fn getHeapStatistics(self: Isolate) v8.HeapStatistics {
|
||||||
var res: v8.c.HeapStatistics = undefined;
|
var res: v8.HeapStatistics = undefined;
|
||||||
v8.c.v8__Isolate__GetHeapStatistics(self.handle, &res);
|
v8.v8__Isolate__GetHeapStatistics(self.handle, &res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn throwException(self: Isolate, value: *const v8.c.Value) *const v8.c.Value {
|
pub fn throwException(self: Isolate, value: *const v8.Value) *const v8.Value {
|
||||||
return v8.c.v8__Isolate__ThrowException(self.handle, value).?;
|
return v8.v8__Isolate__ThrowException(self.handle, value).?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initStringHandle(self: Isolate, str: []const u8) *const v8.c.String {
|
pub fn initStringHandle(self: Isolate, str: []const u8) *const v8.String {
|
||||||
return v8.c.v8__String__NewFromUtf8(self.handle, str.ptr, v8.c.kNormal, @as(c_int, @intCast(str.len))).?;
|
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);
|
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);
|
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 {
|
pub fn initNull(self: Isolate) *const v8.Value {
|
||||||
return v8.c.v8__Null(self.handle).?;
|
return v8.v8__Null(self.handle).?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initUndefined(self: Isolate) *const v8.c.Value {
|
pub fn initUndefined(self: Isolate) *const v8.Value {
|
||||||
return v8.c.v8__Undefined(self.handle).?;
|
return v8.v8__Undefined(self.handle).?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initFalse(self: Isolate) *const v8.c.Value {
|
pub fn initFalse(self: Isolate) *const v8.Value {
|
||||||
return v8.c.v8__False(self.handle).?;
|
return v8.v8__False(self.handle).?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initTrue(self: Isolate) *const v8.c.Value {
|
pub fn initTrue(self: Isolate) *const v8.Value {
|
||||||
return v8.c.v8__True(self.handle).?;
|
return v8.v8__True(self.handle).?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initInteger(self: Isolate, val: anytype) js.Integer {
|
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);
|
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 {
|
pub fn createContextHandle(self: Isolate, global_tmpl: ?*const v8.ObjectTemplate, global_obj: ?*const v8.Value) *const v8.Context {
|
||||||
return v8.c.v8__Context__New(self.handle, global_tmpl, global_obj).?;
|
return v8.v8__Context__New(self.handle, global_tmpl, global_obj).?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createFunctionTemplateHandle(self: Isolate) *const v8.c.FunctionTemplate {
|
pub fn createFunctionTemplateHandle(self: Isolate) *const v8.FunctionTemplate {
|
||||||
return v8.c.v8__FunctionTemplate__New__DEFAULT(self.handle).?;
|
return v8.v8__FunctionTemplate__New__DEFAULT(self.handle).?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createExternal(self: Isolate, val: *anyopaque) *const v8.c.External {
|
pub fn createExternal(self: Isolate, val: *anyopaque) *const v8.External {
|
||||||
return v8.c.v8__External__New(self.handle, val).?;
|
return v8.v8__External__New(self.handle, val).?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,38 +22,38 @@ const v8 = js.v8;
|
|||||||
const Module = @This();
|
const Module = @This();
|
||||||
|
|
||||||
ctx: *js.Context,
|
ctx: *js.Context,
|
||||||
handle: *const v8.c.Module,
|
handle: *const v8.Module,
|
||||||
|
|
||||||
pub const Status = enum(u32) {
|
pub const Status = enum(u32) {
|
||||||
kUninstantiated = v8.c.kUninstantiated,
|
kUninstantiated = v8.kUninstantiated,
|
||||||
kInstantiating = v8.c.kInstantiating,
|
kInstantiating = v8.kInstantiating,
|
||||||
kInstantiated = v8.c.kInstantiated,
|
kInstantiated = v8.kInstantiated,
|
||||||
kEvaluating = v8.c.kEvaluating,
|
kEvaluating = v8.kEvaluating,
|
||||||
kEvaluated = v8.c.kEvaluated,
|
kEvaluated = v8.kEvaluated,
|
||||||
kErrored = v8.c.kErrored,
|
kErrored = v8.kErrored,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn getStatus(self: Module) Status {
|
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 {
|
pub fn getException(self: Module) js.Value {
|
||||||
return .{
|
return .{
|
||||||
.ctx = self.ctx,
|
.ctx = self.ctx,
|
||||||
.handle = v8.c.v8__Module__GetException(self.handle).?,
|
.handle = v8.v8__Module__GetException(self.handle).?,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getModuleRequests(self: Module) Requests {
|
pub fn getModuleRequests(self: Module) Requests {
|
||||||
return .{
|
return .{
|
||||||
.ctx = self.ctx.handle,
|
.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 {
|
pub fn instantiate(self: Module, cb: v8.ResolveModuleCallback) !bool {
|
||||||
var out: v8.c.MaybeBool = undefined;
|
var out: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Module__InstantiateModule(self.handle, self.ctx.handle, cb, &out);
|
v8.v8__Module__InstantiateModule(self.handle, self.ctx.handle, cb, &out);
|
||||||
if (out.has_value) {
|
if (out.has_value) {
|
||||||
return out.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 {
|
pub fn evaluate(self: Module) !js.Value {
|
||||||
const ctx = self.ctx;
|
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) {
|
if (self.getStatus() == .kErrored) {
|
||||||
return error.JsException;
|
return error.JsException;
|
||||||
@@ -75,18 +75,18 @@ pub fn evaluate(self: Module) !js.Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getIdentityHash(self: Module) u32 {
|
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 {
|
pub fn getModuleNamespace(self: Module) js.Value {
|
||||||
return .{
|
return .{
|
||||||
.ctx = self.ctx,
|
.ctx = self.ctx,
|
||||||
.handle = v8.c.v8__Module__GetModuleNamespace(self.handle).?,
|
.handle = v8.v8__Module__GetModuleNamespace(self.handle).?,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getScriptId(self: Module) u32 {
|
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 {
|
pub fn persist(self: Module) !Module {
|
||||||
@@ -102,22 +102,22 @@ pub fn persist(self: Module) !Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Requests = struct {
|
const Requests = struct {
|
||||||
ctx: *const v8.c.Context,
|
ctx: *const v8.Context,
|
||||||
handle: *const v8.c.FixedArray,
|
handle: *const v8.FixedArray,
|
||||||
|
|
||||||
pub fn len(self: Requests) usize {
|
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 {
|
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 {
|
const Request = struct {
|
||||||
handle: *const v8.c.ModuleRequest,
|
handle: *const v8.ModuleRequest,
|
||||||
|
|
||||||
pub fn specifier(self: Request) *const v8.c.String {
|
pub fn specifier(self: Request) *const v8.String {
|
||||||
return v8.c.v8__ModuleRequest__GetSpecifier(self.handle).?;
|
return v8.v8__ModuleRequest__GetSpecifier(self.handle).?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const v8 = js.v8;
|
|||||||
|
|
||||||
const Name = @This();
|
const Name = @This();
|
||||||
|
|
||||||
handle: *const v8.c.Name,
|
handle: *const v8.Name,
|
||||||
|
|
||||||
pub fn toValue(self: Name) js.Value {
|
pub fn toValue(self: Name) js.Value {
|
||||||
return .{
|
return .{
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ const v8 = js.v8;
|
|||||||
|
|
||||||
const Number = @This();
|
const Number = @This();
|
||||||
|
|
||||||
handle: *const v8.c.Number,
|
handle: *const v8.Number,
|
||||||
|
|
||||||
pub fn init(isolate: *v8.c.Isolate, value: anytype) Number {
|
pub fn init(isolate: *v8.Isolate, value: anytype) Number {
|
||||||
const handle = v8.c.v8__Number__New(isolate, value).?;
|
const handle = v8.v8__Number__New(isolate, value).?;
|
||||||
return .{ .handle = handle };
|
return .{ .handle = handle };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,18 +30,18 @@ const Allocator = std.mem.Allocator;
|
|||||||
const Object = @This();
|
const Object = @This();
|
||||||
|
|
||||||
ctx: *js.Context,
|
ctx: *js.Context,
|
||||||
handle: *const v8.c.Object,
|
handle: *const v8.Object,
|
||||||
|
|
||||||
pub fn getId(self: Object) u32 {
|
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 {
|
pub fn has(self: Object, key: anytype) bool {
|
||||||
const ctx = self.ctx;
|
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;
|
var out: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Object__Has(self.handle, self.ctx.handle, key_handle, &out);
|
v8.v8__Object__Has(self.handle, self.ctx.handle, key_handle, &out);
|
||||||
if (out.has_value) {
|
if (out.has_value) {
|
||||||
return out.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 {
|
pub fn get(self: Object, key: anytype) !js.Value {
|
||||||
const ctx = self.ctx;
|
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);
|
||||||
const js_val_handle = v8.c.v8__Object__Get(self.handle, ctx.handle, key_handle) orelse return error.JsException;
|
const js_val_handle = v8.v8__Object__Get(self.handle, ctx.handle, key_handle) orelse return error.JsException;
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.ctx = ctx,
|
.ctx = ctx,
|
||||||
@@ -64,10 +64,10 @@ pub fn set(self: Object, key: anytype, value: anytype, comptime opts: js.bridge.
|
|||||||
const ctx = self.ctx;
|
const ctx = self.ctx;
|
||||||
|
|
||||||
const js_value = try ctx.zigValueToJs(value, opts);
|
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;
|
var out: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Object__Set(self.handle, ctx.handle, key_handle, js_value.handle, &out);
|
v8.v8__Object__Set(self.handle, ctx.handle, key_handle, js_value.handle, &out);
|
||||||
return out.has_value;
|
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);
|
const js_value = try ctx.zigValueToJs(value, opts);
|
||||||
|
|
||||||
var out: v8.c.MaybeBool = undefined;
|
var out: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Object__SetAtIndex(self.handle, ctx.handle, key, js_value.handle, &out);
|
v8.v8__Object__SetAtIndex(self.handle, ctx.handle, key, js_value.handle, &out);
|
||||||
return out.has_value;
|
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 ctx = self.ctx;
|
||||||
const name_handle = ctx.isolate.initStringHandle(name);
|
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) {
|
if (out.has_value) {
|
||||||
return out.value;
|
return out.value;
|
||||||
} else {
|
} else {
|
||||||
@@ -113,7 +115,7 @@ pub fn format(self: Object, writer: *std.Io.Writer) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn toJson(self: Object, allocator: Allocator) ![]u8 {
|
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 });
|
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 ctx = self.ctx;
|
||||||
|
|
||||||
const js_name = ctx.isolate.initStringHandle(name);
|
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 null;
|
||||||
}
|
}
|
||||||
return .{
|
return .{
|
||||||
@@ -153,11 +155,11 @@ pub fn callMethod(self: Object, comptime T: type, method_name: []const u8, args:
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn isNullOrUndefined(self: Object) bool {
|
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 {
|
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 .{
|
return .{
|
||||||
.ctx = self.ctx,
|
.ctx = self.ctx,
|
||||||
.handle = handle,
|
.handle = handle,
|
||||||
@@ -165,7 +167,7 @@ pub fn getOwnPropertyNames(self: Object) js.Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getPropertyNames(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 .{
|
return .{
|
||||||
.ctx = self.ctx,
|
.ctx = self.ctx,
|
||||||
.handle = handle,
|
.handle = handle,
|
||||||
@@ -175,8 +177,8 @@ pub fn getPropertyNames(self: Object) js.Array {
|
|||||||
pub fn nameIterator(self: Object) NameIterator {
|
pub fn nameIterator(self: Object) NameIterator {
|
||||||
const ctx = self.ctx;
|
const ctx = self.ctx;
|
||||||
|
|
||||||
const handle = v8.c.v8__Object__GetPropertyNames(self.handle, ctx.handle).?;
|
const handle = v8.v8__Object__GetPropertyNames(self.handle, ctx.handle).?;
|
||||||
const count = v8.c.v8__Array__Length(handle);
|
const count = v8.v8__Array__Length(handle);
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.ctx = ctx,
|
.ctx = ctx,
|
||||||
@@ -194,7 +196,7 @@ pub const NameIterator = struct {
|
|||||||
count: u32,
|
count: u32,
|
||||||
idx: u32 = 0,
|
idx: u32 = 0,
|
||||||
ctx: *Context,
|
ctx: *Context,
|
||||||
handle: *const v8.c.Array,
|
handle: *const v8.Array,
|
||||||
|
|
||||||
pub fn next(self: *NameIterator) !?[]const u8 {
|
pub fn next(self: *NameIterator) !?[]const u8 {
|
||||||
const idx = self.idx;
|
const idx = self.idx;
|
||||||
@@ -203,7 +205,7 @@ pub const NameIterator = struct {
|
|||||||
}
|
}
|
||||||
self.idx += 1;
|
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 };
|
const js_val = js.Value{ .ctx = self.ctx, .handle = js_val_handle };
|
||||||
return try self.ctx.valueToString(js_val, .{});
|
return try self.ctx.valueToString(js_val, .{});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,22 +20,22 @@ const js = @import("js.zig");
|
|||||||
const v8 = js.v8;
|
const v8 = js.v8;
|
||||||
|
|
||||||
const Platform = @This();
|
const Platform = @This();
|
||||||
handle: *v8.c.Platform,
|
handle: *v8.Platform,
|
||||||
|
|
||||||
pub fn init() !Platform {
|
pub fn init() !Platform {
|
||||||
if (v8.c.v8__V8__InitializeICU() == false) {
|
if (v8.v8__V8__InitializeICU() == false) {
|
||||||
return error.FailedToInitializeICU;
|
return error.FailedToInitializeICU;
|
||||||
}
|
}
|
||||||
// 0 - threadpool size, 0 == let v8 decide
|
// 0 - threadpool size, 0 == let v8 decide
|
||||||
// 1 - idle_task_support, 1 == enabled
|
// 1 - idle_task_support, 1 == enabled
|
||||||
const handle = v8.c.v8__Platform__NewDefaultPlatform(0, 1).?;
|
const handle = v8.v8__Platform__NewDefaultPlatform(0, 1).?;
|
||||||
v8.c.v8__V8__InitializePlatform(handle);
|
v8.v8__V8__InitializePlatform(handle);
|
||||||
v8.c.v8__V8__Initialize();
|
v8.v8__V8__Initialize();
|
||||||
return .{ .handle = handle };
|
return .{ .handle = handle };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: Platform) void {
|
pub fn deinit(self: Platform) void {
|
||||||
_ = v8.c.v8__V8__Dispose();
|
_ = v8.v8__V8__Dispose();
|
||||||
v8.c.v8__V8__DisposePlatform();
|
v8.v8__V8__DisposePlatform();
|
||||||
v8.c.v8__Platform__DELETE(self.handle);
|
v8.v8__Platform__DELETE(self.handle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const v8 = js.v8;
|
|||||||
const Promise = @This();
|
const Promise = @This();
|
||||||
|
|
||||||
ctx: *js.Context,
|
ctx: *js.Context,
|
||||||
handle: *const v8.c.Promise,
|
handle: *const v8.Promise,
|
||||||
|
|
||||||
pub fn toObject(self: Promise) js.Object {
|
pub fn toObject(self: Promise) js.Object {
|
||||||
return .{
|
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 {
|
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 .{
|
return .{
|
||||||
.ctx = self.ctx,
|
.ctx = self.ctx,
|
||||||
.handle = handle,
|
.handle = handle,
|
||||||
|
|||||||
@@ -23,19 +23,19 @@ const log = @import("../../log.zig");
|
|||||||
const PromiseResolver = @This();
|
const PromiseResolver = @This();
|
||||||
|
|
||||||
ctx: *js.Context,
|
ctx: *js.Context,
|
||||||
handle: *const v8.c.PromiseResolver,
|
handle: *const v8.PromiseResolver,
|
||||||
|
|
||||||
pub fn init(ctx: *js.Context) PromiseResolver {
|
pub fn init(ctx: *js.Context) PromiseResolver {
|
||||||
return .{
|
return .{
|
||||||
.ctx = ctx,
|
.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 {
|
pub fn promise(self: PromiseResolver) js.Promise {
|
||||||
return .{
|
return .{
|
||||||
.ctx = self.ctx,
|
.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 ctx: *js.Context = @constCast(self.ctx);
|
||||||
const js_value = try ctx.zigValueToJs(value, .{});
|
const js_value = try ctx.zigValueToJs(value, .{});
|
||||||
|
|
||||||
var out: v8.c.MaybeBool = undefined;
|
var out: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Promise__Resolver__Resolve(self.handle, self.ctx.handle, js_value.handle, &out);
|
v8.v8__Promise__Resolver__Resolve(self.handle, self.ctx.handle, js_value.handle, &out);
|
||||||
if (!out.has_value or !out.value) {
|
if (!out.has_value or !out.value) {
|
||||||
return error.FailedToResolvePromise;
|
return error.FailedToResolvePromise;
|
||||||
}
|
}
|
||||||
@@ -67,8 +67,8 @@ fn _reject(self: PromiseResolver, value: anytype) !void {
|
|||||||
const ctx = self.ctx;
|
const ctx = self.ctx;
|
||||||
const js_value = try ctx.zigValueToJs(value, .{});
|
const js_value = try ctx.zigValueToJs(value, .{});
|
||||||
|
|
||||||
var out: v8.c.MaybeBool = undefined;
|
var out: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Promise__Resolver__Reject(self.handle, ctx.handle, js_value.handle, &out);
|
v8.v8__Promise__Resolver__Reject(self.handle, ctx.handle, js_value.handle, &out);
|
||||||
if (!out.has_value or !out.value) {
|
if (!out.has_value or !out.value) {
|
||||||
return error.FailedToRejectPromise;
|
return error.FailedToRejectPromise;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ const embedded_snapshot_blob = if (@import("build_config").snapshot_path) |path|
|
|||||||
// sequence
|
// sequence
|
||||||
data_start: usize,
|
data_start: usize,
|
||||||
|
|
||||||
// The snapshot data (v8.c.StartupData is a ptr to the data and len).
|
// The snapshot data (v8.StartupData is a ptr to the data and len).
|
||||||
startup_data: v8.c.StartupData,
|
startup_data: v8.StartupData,
|
||||||
|
|
||||||
// V8 doesn't know how to serialize external references, and pretty much any hook
|
// 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).
|
// 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 data_start = std.mem.readInt(usize, embedded_snapshot_blob[0..@sizeOf(usize)], .little);
|
||||||
const blob = embedded_snapshot_blob[@sizeOf(usize)..];
|
const blob = embedded_snapshot_blob[@sizeOf(usize)..];
|
||||||
|
|
||||||
const startup_data = v8.c.StartupData{ .data = blob.ptr, .raw_size = @intCast(blob.len) };
|
const startup_data = v8.StartupData{ .data = blob.ptr, .raw_size = @intCast(blob.len) };
|
||||||
if (!v8.c.v8__StartupData__IsValid(startup_data)) {
|
if (!v8.v8__StartupData__IsValid(startup_data)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ pub fn fromEmbedded(self: Snapshot) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn isValid(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 {
|
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 {
|
pub fn create(allocator: Allocator) !Snapshot {
|
||||||
var external_references = collectExternalReferences();
|
var external_references = collectExternalReferences();
|
||||||
|
|
||||||
var params: v8.c.CreateParams = undefined;
|
var params: v8.CreateParams = undefined;
|
||||||
v8.c.v8__Isolate__CreateParams__CONSTRUCT(¶ms);
|
v8.v8__Isolate__CreateParams__CONSTRUCT(¶ms);
|
||||||
params.array_buffer_allocator = v8.c.v8__ArrayBuffer__Allocator__NewDefaultAllocator();
|
params.array_buffer_allocator = v8.v8__ArrayBuffer__Allocator__NewDefaultAllocator();
|
||||||
defer v8.c.v8__ArrayBuffer__Allocator__DELETE(params.array_buffer_allocator.?);
|
defer v8.v8__ArrayBuffer__Allocator__DELETE(params.array_buffer_allocator.?);
|
||||||
params.external_references = @ptrCast(&external_references);
|
params.external_references = @ptrCast(&external_references);
|
||||||
|
|
||||||
const snapshot_creator = v8.c.v8__SnapshotCreator__CREATE(¶ms);
|
const snapshot_creator = v8.v8__SnapshotCreator__CREATE(¶ms);
|
||||||
defer v8.c.v8__SnapshotCreator__DESTRUCT(snapshot_creator);
|
defer v8.v8__SnapshotCreator__DESTRUCT(snapshot_creator);
|
||||||
|
|
||||||
var data_start: usize = 0;
|
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
|
// CreateBlob, which we'll call once everything is setup, MUST NOT
|
||||||
// be called from an active HandleScope. Hence we have this scope to
|
// be called from an active HandleScope. Hence we have this scope to
|
||||||
// clean it up before we call CreateBlob
|
// clean it up before we call CreateBlob
|
||||||
var handle_scope: v8.c.HandleScope = undefined;
|
var handle_scope: v8.HandleScope = undefined;
|
||||||
v8.c.v8__HandleScope__CONSTRUCT(&handle_scope, isolate);
|
v8.v8__HandleScope__CONSTRUCT(&handle_scope, isolate);
|
||||||
defer v8.c.v8__HandleScope__DESTRUCT(&handle_scope);
|
defer v8.v8__HandleScope__DESTRUCT(&handle_scope);
|
||||||
|
|
||||||
// Create templates (constructors only) FIRST
|
// 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| {
|
inline for (JsApis, 0..) |JsApi, i| {
|
||||||
@setEvalBranchQuota(10_000);
|
@setEvalBranchQuota(10_000);
|
||||||
templates[i] = generateConstructor(JsApi, isolate);
|
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
|
// This must come before attachClass so inheritance is set up first
|
||||||
inline for (JsApis, 0..) |JsApi, i| {
|
inline for (JsApis, 0..) |JsApi, i| {
|
||||||
if (comptime protoIndexLookup(JsApi)) |proto_index| {
|
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
|
// Set up the global template to inherit from Window's template
|
||||||
// This way the global object gets all Window properties through inheritance
|
// This way the global object gets all Window properties through inheritance
|
||||||
|
|
||||||
const global_template = createGlobalTemplate(isolate, templates[0..]);
|
const global_template = createGlobalTemplate(isolate, templates[0..]);
|
||||||
const context = v8.c.v8__Context__New(isolate, global_template, null);
|
const context = v8.v8__Context__New(isolate, global_template, null);
|
||||||
v8.c.v8__Context__Enter(context);
|
v8.v8__Context__Enter(context);
|
||||||
defer v8.c.v8__Context__Exit(context);
|
defer v8.v8__Context__Exit(context);
|
||||||
|
|
||||||
// Add templates to context snapshot
|
// Add templates to context snapshot
|
||||||
var last_data_index: usize = 0;
|
var last_data_index: usize = 0;
|
||||||
inline for (JsApis, 0..) |_, i| {
|
inline for (JsApis, 0..) |_, i| {
|
||||||
@setEvalBranchQuota(10_000);
|
@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) {
|
if (i == 0) {
|
||||||
data_start = data_index;
|
data_start = data_index;
|
||||||
last_data_index = 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
|
// 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| {
|
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
|
// Attach to global if it has a name
|
||||||
if (@hasDecl(JsApi.Meta, "name")) {
|
if (@hasDecl(JsApi.Meta, "name")) {
|
||||||
if (@hasDecl(JsApi.Meta, "constructor_alias")) {
|
if (@hasDecl(JsApi.Meta, "constructor_alias")) {
|
||||||
const alias = 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));
|
const v8_class_name = v8.v8__String__NewFromUtf8(isolate, alias.ptr, v8.kNormal, @intCast(alias.len));
|
||||||
var maybe_result: v8.c.MaybeBool = undefined;
|
var maybe_result: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Object__Set(global_obj, context, v8_class_name, func, &maybe_result);
|
v8.v8__Object__Set(global_obj, context, v8_class_name, func, &maybe_result);
|
||||||
|
|
||||||
// @TODO: This is wrong. This name should be registered with the
|
// @TODO: This is wrong. This name should be registered with the
|
||||||
// illegalConstructorCallback. I.e. new Image() is OK, but
|
// 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
|
// has to be registered so, for now, instead of creating another
|
||||||
// template, we just hook it into the constructor.
|
// template, we just hook it into the constructor.
|
||||||
const name = JsApi.Meta.name;
|
const name = JsApi.Meta.name;
|
||||||
const illegal_class_name = v8.c.v8__String__NewFromUtf8(isolate, name.ptr, v8.c.kNormal, @intCast(name.len));
|
const illegal_class_name = v8.v8__String__NewFromUtf8(isolate, name.ptr, v8.kNormal, @intCast(name.len));
|
||||||
var maybe_result2: v8.c.MaybeBool = undefined;
|
var maybe_result2: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Object__Set(global_obj, context, illegal_class_name, func, &maybe_result2);
|
v8.v8__Object__Set(global_obj, context, illegal_class_name, func, &maybe_result2);
|
||||||
} else {
|
} else {
|
||||||
const name = JsApi.Meta.name;
|
const name = JsApi.Meta.name;
|
||||||
const v8_class_name = v8.c.v8__String__NewFromUtf8(isolate, name.ptr, v8.c.kNormal, @intCast(name.len));
|
const v8_class_name = v8.v8__String__NewFromUtf8(isolate, name.ptr, v8.kNormal, @intCast(name.len));
|
||||||
var maybe_result: v8.c.MaybeBool = undefined;
|
var maybe_result: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Object__Set(global_obj, context, v8_class_name, func, &maybe_result);
|
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
|
// If we want to overwrite the built-in console, we have to
|
||||||
// delete the built-in one.
|
// delete the built-in one.
|
||||||
const console_key = v8.c.v8__String__NewFromUtf8(isolate, "console", v8.c.kNormal, 7);
|
const console_key = v8.v8__String__NewFromUtf8(isolate, "console", v8.kNormal, 7);
|
||||||
var maybe_deleted: v8.c.MaybeBool = undefined;
|
var maybe_deleted: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Object__Delete(global_obj, context, console_key, &maybe_deleted);
|
v8.v8__Object__Delete(global_obj, context, console_key, &maybe_deleted);
|
||||||
if (maybe_deleted.value == false) {
|
if (maybe_deleted.value == false) {
|
||||||
return error.ConsoleDeleteError;
|
return error.ConsoleDeleteError;
|
||||||
}
|
}
|
||||||
@@ -244,14 +243,14 @@ pub fn create(allocator: Allocator) !Snapshot {
|
|||||||
// TODO: see if newer V8 engines have a way around this.
|
// TODO: see if newer V8 engines have a way around this.
|
||||||
inline for (JsApis, 0..) |JsApi, i| {
|
inline for (JsApis, 0..) |JsApi, i| {
|
||||||
if (comptime protoIndexLookup(JsApi)) |proto_index| {
|
if (comptime protoIndexLookup(JsApi)) |proto_index| {
|
||||||
const proto_func = v8.c.v8__FunctionTemplate__GetFunction(templates[proto_index], context);
|
const proto_func = v8.v8__FunctionTemplate__GetFunction(templates[proto_index], context);
|
||||||
const proto_obj: *const v8.c.Object = @ptrCast(proto_func);
|
const proto_obj: *const v8.Object = @ptrCast(proto_func);
|
||||||
|
|
||||||
const self_func = v8.c.v8__FunctionTemplate__GetFunction(templates[i], context);
|
const self_func = v8.v8__FunctionTemplate__GetFunction(templates[i], context);
|
||||||
const self_obj: *const v8.c.Object = @ptrCast(self_func);
|
const self_obj: *const v8.Object = @ptrCast(self_func);
|
||||||
|
|
||||||
var maybe_result: v8.c.MaybeBool = undefined;
|
var maybe_result: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Object__SetPrototype(self_obj, context, proto_obj, &maybe_result);
|
v8.v8__Object__SetPrototype(self_obj, context, proto_obj, &maybe_result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,15 +258,15 @@ pub fn create(allocator: Allocator) !Snapshot {
|
|||||||
// Custom exception
|
// Custom exception
|
||||||
// TODO: this is an horrible hack, I can't figure out how to do this cleanly.
|
// 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_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 code = v8.v8__String__NewFromUtf8(isolate, code_str.ptr, v8.kNormal, @intCast(code_str.len));
|
||||||
const script = v8.c.v8__Script__Compile(context, code, null) orelse return error.ScriptCompileFailed;
|
const script = v8.v8__Script__Compile(context, code, null) orelse return error.ScriptCompileFailed;
|
||||||
_ = v8.c.v8__Script__Run(script, context) orelse return error.ScriptRunFailed;
|
_ = 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)]);
|
const owned = try allocator.dupe(u8, blob.data[0..@intCast(blob.raw_size)]);
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
@@ -383,7 +382,7 @@ fn collectExternalReferences() [countExternalReferences()]isize {
|
|||||||
// via `new ClassName()` - but they could, for example, be created in
|
// via `new ClassName()` - but they could, for example, be created in
|
||||||
// Zig and returned from a function call, which is why we need the
|
// Zig and returned from a function call, which is why we need the
|
||||||
// FunctionTemplate.
|
// 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: {
|
const callback = blk: {
|
||||||
if (@hasDecl(JsApi, "constructor")) {
|
if (@hasDecl(JsApi, "constructor")) {
|
||||||
break :blk JsApi.constructor.func;
|
break :blk JsApi.constructor.func;
|
||||||
@@ -393,24 +392,23 @@ fn generateConstructor(comptime JsApi: type, isolate: *v8.c.Isolate) *v8.c.Funct
|
|||||||
break :blk illegalConstructorCallback;
|
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")) {
|
if (!@hasDecl(JsApi.Meta, "empty_with_no_proto")) {
|
||||||
const instance_template = v8.c.v8__FunctionTemplate__InstanceTemplate(template);
|
const instance_template = v8.v8__FunctionTemplate__InstanceTemplate(template);
|
||||||
v8.c.v8__ObjectTemplate__SetInternalFieldCount(instance_template, 1);
|
v8.v8__ObjectTemplate__SetInternalFieldCount(instance_template, 1);
|
||||||
}
|
}
|
||||||
const name_str = if (@hasDecl(JsApi.Meta, "name")) JsApi.Meta.name else @typeName(JsApi);
|
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));
|
const class_name = v8.v8__String__NewFromUtf8(isolate, name_str.ptr, v8.kNormal, @intCast(name_str.len));
|
||||||
v8.c.v8__FunctionTemplate__SetClassName(template, class_name);
|
v8.v8__FunctionTemplate__SetClassName(template, class_name);
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attaches JsApi members to the prototype template (normal case)
|
// Attaches JsApi members to the prototype template (normal case)
|
||||||
|
|
||||||
fn attachClass(comptime JsApi: type, isolate: *v8.Isolate, template: *v8.FunctionTemplate) void {
|
fn attachClass(comptime JsApi: type, isolate: *v8.Isolate, template: *v8.FunctionTemplate) void {
|
||||||
const target = v8.c.v8__FunctionTemplate__PrototypeTemplate(template);
|
const target = v8.c.v8__FunctionTemplate__PrototypeTemplate(template);
|
||||||
const instance = v8.c.v8__FunctionTemplate__InstanceTemplate(template);
|
const instance = v8.c.v8__FunctionTemplate__InstanceTemplate(template);
|
||||||
|
|
||||||
const declarations = @typeInfo(JsApi).@"struct".decls;
|
const declarations = @typeInfo(JsApi).@"struct".decls;
|
||||||
|
|
||||||
inline for (declarations) |d| {
|
inline for (declarations) |d| {
|
||||||
const name: [:0]const u8 = d.name;
|
const name: [:0]const u8 = d.name;
|
||||||
const value = @field(JsApi, name);
|
const value = @field(JsApi, name);
|
||||||
@@ -418,31 +416,31 @@ fn attachClass(comptime JsApi: type, isolate: *v8.Isolate, template: *v8.Functio
|
|||||||
|
|
||||||
switch (definition) {
|
switch (definition) {
|
||||||
bridge.Accessor => {
|
bridge.Accessor => {
|
||||||
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));
|
||||||
const getter_callback = @constCast(v8.c.v8__FunctionTemplate__New__DEFAULT2(isolate, value.getter).?);
|
const getter_callback = @constCast(v8.v8__FunctionTemplate__New__DEFAULT2(isolate, value.getter).?);
|
||||||
if (value.setter == null) {
|
if (value.setter == null) {
|
||||||
if (value.static) {
|
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 {
|
} else {
|
||||||
v8.c.v8__ObjectTemplate__SetAccessorProperty__DEFAULT(target, js_name, getter_callback);
|
v8.v8__ObjectTemplate__SetAccessorProperty__DEFAULT(target, js_name, getter_callback);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std.debug.assert(value.static == false);
|
std.debug.assert(value.static == false);
|
||||||
const setter_callback = @constCast(v8.c.v8__FunctionTemplate__New__DEFAULT2(isolate, value.setter.?).?);
|
const setter_callback = @constCast(v8.v8__FunctionTemplate__New__DEFAULT2(isolate, value.setter.?).?);
|
||||||
v8.c.v8__ObjectTemplate__SetAccessorProperty__DEFAULT2(target, js_name, getter_callback, setter_callback);
|
v8.v8__ObjectTemplate__SetAccessorProperty__DEFAULT2(target, js_name, getter_callback, setter_callback);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
bridge.Function => {
|
bridge.Function => {
|
||||||
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 = 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));
|
||||||
if (value.static) {
|
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 {
|
} 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 => {
|
bridge.Indexed => {
|
||||||
var configuration: v8.c.IndexedPropertyHandlerConfiguration = .{
|
var configuration: v8.IndexedPropertyHandlerConfiguration = .{
|
||||||
.getter = value.getter,
|
.getter = value.getter,
|
||||||
.setter = null,
|
.setter = null,
|
||||||
.query = null,
|
.query = null,
|
||||||
@@ -453,11 +451,10 @@ fn attachClass(comptime JsApi: type, isolate: *v8.Isolate, template: *v8.Functio
|
|||||||
.data = null,
|
.data = null,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
};
|
};
|
||||||
instance.setIndexedProperty(configuration, null);
|
v8.v8__ObjectTemplate__SetIndexedHandler(instance, &configuration);
|
||||||
},
|
},
|
||||||
bridge.NamedIndexed => {
|
bridge.NamedIndexed => {
|
||||||
const instance_template = v8.c.v8__FunctionTemplate__InstanceTemplate(template);
|
var configuration: v8.NamedPropertyHandlerConfiguration = .{
|
||||||
var configuration: v8.c.NamedPropertyHandlerConfiguration = .{
|
|
||||||
.getter = value.getter,
|
.getter = value.getter,
|
||||||
.setter = value.setter,
|
.setter = value.setter,
|
||||||
.query = null,
|
.query = null,
|
||||||
@@ -466,17 +463,17 @@ fn attachClass(comptime JsApi: type, isolate: *v8.Isolate, template: *v8.Functio
|
|||||||
.definer = null,
|
.definer = null,
|
||||||
.descriptor = null,
|
.descriptor = null,
|
||||||
.data = 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 => {
|
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)
|
const js_name = if (value.async)
|
||||||
v8.c.v8__Symbol__GetAsyncIterator(isolate)
|
v8.v8__Symbol__GetAsyncIterator(isolate)
|
||||||
else
|
else
|
||||||
v8.c.v8__Symbol__GetIterator(isolate);
|
v8.v8__Symbol__GetIterator(isolate);
|
||||||
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.Property => {
|
bridge.Property => {
|
||||||
// simpleZigValueToJs now returns raw handle directly
|
// 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),
|
.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
|
// 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
|
// 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
|
bridge.Constructor => {}, // already handled in generateConstructor
|
||||||
else => {},
|
else => {},
|
||||||
@@ -521,15 +518,15 @@ fn protoIndexLookup(comptime JsApi: type) ?bridge.JsApiLookup.BackingInt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Shared illegal constructor callback for types without explicit constructors
|
// Shared illegal constructor callback for types without explicit constructors
|
||||||
fn illegalConstructorCallback(raw_info: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
|
fn illegalConstructorCallback(raw_info: ?*const v8.FunctionCallbackInfo) callconv(.c) void {
|
||||||
const isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(raw_info);
|
const isolate = v8.v8__FunctionCallbackInfo__GetIsolate(raw_info);
|
||||||
log.warn(.js, "Illegal constructor call", .{});
|
log.warn(.js, "Illegal constructor call", .{});
|
||||||
|
|
||||||
const message = v8.c.v8__String__NewFromUtf8(isolate, "Illegal Constructor", v8.c.kNormal, 19);
|
const message = v8.v8__String__NewFromUtf8(isolate, "Illegal Constructor", v8.kNormal, 19);
|
||||||
const js_exception = v8.c.v8__Exception__TypeError(message);
|
const js_exception = v8.v8__Exception__TypeError(message);
|
||||||
|
|
||||||
_ = v8.c.v8__Isolate__ThrowException(isolate, js_exception);
|
_ = v8.v8__Isolate__ThrowException(isolate, js_exception);
|
||||||
var return_value: v8.c.ReturnValue = undefined;
|
var return_value: v8.ReturnValue = undefined;
|
||||||
v8.c.v8__FunctionCallbackInfo__GetReturnValue(raw_info, &return_value);
|
v8.v8__FunctionCallbackInfo__GetReturnValue(raw_info, &return_value);
|
||||||
v8.c.v8__ReturnValue__Set(return_value, js_exception);
|
v8.v8__ReturnValue__Set(return_value, js_exception);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const v8 = js.v8;
|
|||||||
const String = @This();
|
const String = @This();
|
||||||
|
|
||||||
ctx: *js.Context,
|
ctx: *js.Context,
|
||||||
handle: *const v8.c.String,
|
handle: *const v8.String,
|
||||||
|
|
||||||
pub const ToZigOpts = struct {
|
pub const ToZigOpts = struct {
|
||||||
allocator: ?Allocator = null,
|
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) {
|
fn _toZig(self: String, comptime null_terminate: bool, opts: ToZigOpts) !(if (null_terminate) [:0]u8 else []u8) {
|
||||||
const isolate = self.ctx.isolate.handle;
|
const isolate = self.ctx.isolate.handle;
|
||||||
const allocator = opts.allocator orelse self.ctx.call_arena;
|
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 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 options = v8.NO_NULL_TERMINATION | v8.REPLACE_INVALID_UTF8;
|
||||||
const n = v8.c.v8__String__WriteUtf8(self.handle, isolate, buf.ptr, buf.len, options);
|
const n = v8.v8__String__WriteUtf8(self.handle, isolate, buf.ptr, buf.len, options);
|
||||||
std.debug.assert(n == len);
|
std.debug.assert(n == len);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,20 +25,20 @@ const Allocator = std.mem.Allocator;
|
|||||||
const TryCatch = @This();
|
const TryCatch = @This();
|
||||||
|
|
||||||
ctx: *js.Context,
|
ctx: *js.Context,
|
||||||
handle: v8.c.TryCatch,
|
handle: v8.TryCatch,
|
||||||
|
|
||||||
pub fn init(self: *TryCatch, ctx: *js.Context) void {
|
pub fn init(self: *TryCatch, ctx: *js.Context) void {
|
||||||
self.ctx = ctx;
|
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 {
|
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
|
// the caller needs to deinit the string returned
|
||||||
pub fn exception(self: TryCatch, allocator: Allocator) !?[]const u8 {
|
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 };
|
const msg = js.Value{ .ctx = self.ctx, .handle = msg_value };
|
||||||
return try self.ctx.valueToString(msg, .{ .allocator = allocator });
|
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
|
// the caller needs to deinit the string returned
|
||||||
pub fn stack(self: TryCatch, allocator: Allocator) !?[]const u8 {
|
pub fn stack(self: TryCatch, allocator: Allocator) !?[]const u8 {
|
||||||
const ctx = self.ctx;
|
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 };
|
const s = js.Value{ .ctx = ctx, .handle = s_value };
|
||||||
return try ctx.valueToString(s, .{ .allocator = allocator });
|
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
|
// the caller needs to deinit the string returned
|
||||||
pub fn sourceLine(self: TryCatch, allocator: Allocator) !?[]const u8 {
|
pub fn sourceLine(self: TryCatch, allocator: Allocator) !?[]const u8 {
|
||||||
const ctx = self.ctx;
|
const ctx = self.ctx;
|
||||||
const msg = v8.c.v8__TryCatch__Message(&self.handle) orelse return null;
|
const msg = v8.v8__TryCatch__Message(&self.handle) orelse return null;
|
||||||
const source_line_handle = v8.c.v8__Message__GetSourceLine(msg, ctx.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 });
|
return try ctx.jsStringToZig(source_line_handle, .{ .allocator = allocator });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sourceLineNumber(self: TryCatch) ?u32 {
|
pub fn sourceLineNumber(self: TryCatch) ?u32 {
|
||||||
const ctx = self.ctx;
|
const ctx = self.ctx;
|
||||||
const msg = v8.c.v8__TryCatch__Message(&self.handle) orelse return null;
|
const msg = v8.v8__TryCatch__Message(&self.handle) orelse return null;
|
||||||
const line = v8.c.v8__Message__GetLineNumber(msg, ctx.handle);
|
const line = v8.v8__Message__GetLineNumber(msg, ctx.handle);
|
||||||
if (line < 0) {
|
if (line < 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -84,5 +84,5 @@ pub fn err(self: TryCatch, allocator: Allocator) !?[]const u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *TryCatch) void {
|
pub fn deinit(self: *TryCatch) void {
|
||||||
v8.c.v8__TryCatch__DESTRUCT(&self.handle);
|
v8.v8__TryCatch__DESTRUCT(&self.handle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,18 +28,18 @@ const Allocator = std.mem.Allocator;
|
|||||||
const Value = @This();
|
const Value = @This();
|
||||||
|
|
||||||
ctx: *js.Context,
|
ctx: *js.Context,
|
||||||
handle: *const v8.c.Value,
|
handle: *const v8.Value,
|
||||||
|
|
||||||
pub fn isObject(self: Value) bool {
|
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 {
|
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 {
|
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 {
|
pub fn isNull(self: Value) bool {
|
||||||
@@ -51,123 +51,123 @@ pub fn isUndefined(self: Value) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn isSymbol(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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 {
|
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 };
|
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 {
|
pub fn toF64(self: Value) !f64 {
|
||||||
var maybe: v8.c.MaybeF64 = undefined;
|
var maybe: v8.MaybeF64 = undefined;
|
||||||
v8.c.v8__Value__NumberValue(self.handle, self.ctx.handle, &maybe);
|
v8.v8__Value__NumberValue(self.handle, self.ctx.handle, &maybe);
|
||||||
if (!maybe.has_value) {
|
if (!maybe.has_value) {
|
||||||
return error.JsException;
|
return error.JsException;
|
||||||
}
|
}
|
||||||
@@ -185,8 +185,8 @@ pub fn toF64(self: Value) !f64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn toI32(self: Value) !i32 {
|
pub fn toI32(self: Value) !i32 {
|
||||||
var maybe: v8.c.MaybeI32 = undefined;
|
var maybe: v8.MaybeI32 = undefined;
|
||||||
v8.c.v8__Value__Int32Value(self.handle, self.ctx.handle, &maybe);
|
v8.v8__Value__Int32Value(self.handle, self.ctx.handle, &maybe);
|
||||||
if (!maybe.has_value) {
|
if (!maybe.has_value) {
|
||||||
return error.JsException;
|
return error.JsException;
|
||||||
}
|
}
|
||||||
@@ -194,8 +194,8 @@ pub fn toI32(self: Value) !i32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn toU32(self: Value) !u32 {
|
pub fn toU32(self: Value) !u32 {
|
||||||
var maybe: v8.c.MaybeU32 = undefined;
|
var maybe: v8.MaybeU32 = undefined;
|
||||||
v8.c.v8__Value__Uint32Value(self.handle, self.ctx.handle, &maybe);
|
v8.v8__Value__Uint32Value(self.handle, self.ctx.handle, &maybe);
|
||||||
if (!maybe.has_value) {
|
if (!maybe.has_value) {
|
||||||
return error.JsException;
|
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);
|
const ctx: *js.Context = @constCast(self.ctx);
|
||||||
|
|
||||||
if (self.isSymbol()) {
|
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);
|
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;
|
return error.JsException;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -38,71 +38,71 @@ const IS_DEBUG = @import("builtin").mode == .Debug;
|
|||||||
// They are not exported - internal to this module only.
|
// They are not exported - internal to this module only.
|
||||||
|
|
||||||
const Value = struct {
|
const Value = struct {
|
||||||
handle: *const v8.c.Value,
|
handle: *const v8.Value,
|
||||||
|
|
||||||
fn isArray(self: Value) bool {
|
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 {
|
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 {
|
fn isFunction(self: Value) bool {
|
||||||
return v8.c.v8__Value__IsFunction(self.handle);
|
return v8.v8__Value__IsFunction(self.handle);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const Name = struct {
|
const Name = struct {
|
||||||
handle: *const v8.c.Name,
|
handle: *const v8.Name,
|
||||||
};
|
};
|
||||||
|
|
||||||
const FunctionCallbackInfo = struct {
|
const FunctionCallbackInfo = struct {
|
||||||
handle: *const v8.c.FunctionCallbackInfo,
|
handle: *const v8.FunctionCallbackInfo,
|
||||||
|
|
||||||
fn length(self: FunctionCallbackInfo) u32 {
|
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 {
|
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 {
|
fn getThis(self: FunctionCallbackInfo) *const v8.Object {
|
||||||
return v8.c.v8__FunctionCallbackInfo__This(self.handle).?;
|
return v8.v8__FunctionCallbackInfo__This(self.handle).?;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getReturnValue(self: FunctionCallbackInfo) ReturnValue {
|
fn getReturnValue(self: FunctionCallbackInfo) ReturnValue {
|
||||||
var rv: v8.c.ReturnValue = undefined;
|
var rv: v8.ReturnValue = undefined;
|
||||||
v8.c.v8__FunctionCallbackInfo__GetReturnValue(self.handle, &rv);
|
v8.v8__FunctionCallbackInfo__GetReturnValue(self.handle, &rv);
|
||||||
return .{ .handle = rv };
|
return .{ .handle = rv };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const PropertyCallbackInfo = struct {
|
const PropertyCallbackInfo = struct {
|
||||||
handle: *const v8.c.PropertyCallbackInfo,
|
handle: *const v8.PropertyCallbackInfo,
|
||||||
|
|
||||||
fn getThis(self: PropertyCallbackInfo) *const v8.c.Object {
|
fn getThis(self: PropertyCallbackInfo) *const v8.Object {
|
||||||
return v8.c.v8__PropertyCallbackInfo__This(self.handle).?;
|
return v8.v8__PropertyCallbackInfo__This(self.handle).?;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getReturnValue(self: PropertyCallbackInfo) ReturnValue {
|
fn getReturnValue(self: PropertyCallbackInfo) ReturnValue {
|
||||||
var rv: v8.c.ReturnValue = undefined;
|
var rv: v8.ReturnValue = undefined;
|
||||||
v8.c.v8__PropertyCallbackInfo__GetReturnValue(self.handle, &rv);
|
v8.v8__PropertyCallbackInfo__GetReturnValue(self.handle, &rv);
|
||||||
return .{ .handle = rv };
|
return .{ .handle = rv };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const ReturnValue = struct {
|
const ReturnValue = struct {
|
||||||
handle: v8.c.ReturnValue,
|
handle: v8.ReturnValue,
|
||||||
|
|
||||||
fn set(self: ReturnValue, value: anytype) void {
|
fn set(self: ReturnValue, value: anytype) void {
|
||||||
const T = @TypeOf(value);
|
const T = @TypeOf(value);
|
||||||
if (T == Value) {
|
if (T == Value) {
|
||||||
self.setValueHandle(value.handle);
|
self.setValueHandle(value.handle);
|
||||||
} else if (T == *const v8.c.Object) {
|
} else if (T == *const v8.Object) {
|
||||||
self.setValueHandle(@ptrCast(value));
|
self.setValueHandle(@ptrCast(value));
|
||||||
} else if (T == *const v8.c.Value) {
|
} else if (T == *const v8.Value) {
|
||||||
self.setValueHandle(value);
|
self.setValueHandle(value);
|
||||||
} else if (T == js.Value) {
|
} else if (T == js.Value) {
|
||||||
self.setValueHandle(value.handle);
|
self.setValueHandle(value.handle);
|
||||||
@@ -111,8 +111,8 @@ const ReturnValue = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setValueHandle(self: ReturnValue, handle: *const v8.c.Value) void {
|
fn setValueHandle(self: ReturnValue, handle: *const v8.Value) void {
|
||||||
v8.c.v8__ReturnValue__Set(self.handle, handle);
|
v8.v8__ReturnValue__Set(self.handle, handle);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,12 +126,12 @@ pub const Caller = struct {
|
|||||||
call_arena: Allocator,
|
call_arena: Allocator,
|
||||||
|
|
||||||
// Takes the raw v8 isolate and extracts the context from it.
|
// 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 isolate = js.Isolate{ .handle = v8_isolate };
|
||||||
const v8_context_handle = v8.c.v8__Isolate__GetCurrentContext(v8_isolate);
|
const v8_context_handle = v8.v8__Isolate__GetCurrentContext(v8_isolate);
|
||||||
const embedder_data = v8.c.v8__Context__GetEmbedderData(v8_context_handle, 1);
|
const embedder_data = v8.v8__Context__GetEmbedderData(v8_context_handle, 1);
|
||||||
var lossless: bool = undefined;
|
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;
|
context.call_depth += 1;
|
||||||
return .{
|
return .{
|
||||||
@@ -197,9 +197,9 @@ pub const Caller = struct {
|
|||||||
// If we got back a different object (existing wrapper), copy the prototype
|
// If we got back a different object (existing wrapper), copy the prototype
|
||||||
// from new object. (this happens when we're upgrading an CustomElement)
|
// from new object. (this happens when we're upgrading an CustomElement)
|
||||||
if (this.handle != new_this_handle) {
|
if (this.handle != new_this_handle) {
|
||||||
const prototype_handle = v8.c.v8__Object__GetPrototype(new_this_handle).?;
|
const prototype_handle = v8.v8__Object__GetPrototype(new_this_handle).?;
|
||||||
var out: v8.c.MaybeBool = undefined;
|
var out: v8.MaybeBool = undefined;
|
||||||
v8.c.v8__Object__SetPrototype(this.handle, self.context.handle, prototype_handle, &out);
|
v8.v8__Object__SetPrototype(this.handle, self.context.handle, prototype_handle, &out);
|
||||||
if (comptime IS_DEBUG) {
|
if (comptime IS_DEBUG) {
|
||||||
std.debug.assert(out.has_value and out.value);
|
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.InvalidArgument => isolate.createTypeError("invalid argument"),
|
||||||
error.OutOfMemory => isolate.createError("out of memory"),
|
error.OutOfMemory => isolate.createError("out of memory"),
|
||||||
error.IllegalConstructor => isolate.createError("Illegal Contructor"),
|
error.IllegalConstructor => isolate.createError("Illegal Contructor"),
|
||||||
@@ -624,7 +624,7 @@ pub fn Builder(comptime T: type) type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub const Constructor = struct {
|
pub const Constructor = struct {
|
||||||
func: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void,
|
func: *const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void,
|
||||||
|
|
||||||
const Opts = struct {
|
const Opts = struct {
|
||||||
dom_exception: bool = false,
|
dom_exception: bool = false,
|
||||||
@@ -632,8 +632,8 @@ pub const Constructor = struct {
|
|||||||
|
|
||||||
fn init(comptime T: type, comptime func: anytype, comptime opts: Opts) Constructor {
|
fn init(comptime T: type, comptime func: anytype, comptime opts: Opts) Constructor {
|
||||||
return .{ .func = struct {
|
return .{ .func = struct {
|
||||||
fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
|
fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void {
|
||||||
const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?;
|
const v8_isolate = v8.v8__FunctionCallbackInfo__GetIsolate(handle).?;
|
||||||
var caller = Caller.init(v8_isolate);
|
var caller = Caller.init(v8_isolate);
|
||||||
defer caller.deinit();
|
defer caller.deinit();
|
||||||
|
|
||||||
@@ -648,7 +648,7 @@ pub const Constructor = struct {
|
|||||||
|
|
||||||
pub const Function = struct {
|
pub const Function = struct {
|
||||||
static: bool,
|
static: bool,
|
||||||
func: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void,
|
func: *const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void,
|
||||||
|
|
||||||
const Opts = struct {
|
const Opts = struct {
|
||||||
static: bool = false,
|
static: bool = false,
|
||||||
@@ -661,8 +661,8 @@ pub const Function = struct {
|
|||||||
return .{
|
return .{
|
||||||
.static = opts.static,
|
.static = opts.static,
|
||||||
.func = struct {
|
.func = struct {
|
||||||
fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
|
fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void {
|
||||||
const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?;
|
const v8_isolate = v8.v8__FunctionCallbackInfo__GetIsolate(handle).?;
|
||||||
var caller = Caller.init(v8_isolate);
|
var caller = Caller.init(v8_isolate);
|
||||||
defer caller.deinit();
|
defer caller.deinit();
|
||||||
|
|
||||||
@@ -688,8 +688,8 @@ pub const Function = struct {
|
|||||||
|
|
||||||
pub const Accessor = struct {
|
pub const Accessor = struct {
|
||||||
static: bool = false,
|
static: bool = false,
|
||||||
getter: ?*const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void = null,
|
getter: ?*const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void = null,
|
||||||
setter: ?*const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void = null,
|
setter: ?*const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void = null,
|
||||||
|
|
||||||
const Opts = struct {
|
const Opts = struct {
|
||||||
static: bool = false,
|
static: bool = false,
|
||||||
@@ -705,8 +705,8 @@ pub const Accessor = struct {
|
|||||||
|
|
||||||
if (@typeInfo(@TypeOf(getter)) != .null) {
|
if (@typeInfo(@TypeOf(getter)) != .null) {
|
||||||
accessor.getter = struct {
|
accessor.getter = struct {
|
||||||
fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
|
fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void {
|
||||||
const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?;
|
const v8_isolate = v8.v8__FunctionCallbackInfo__GetIsolate(handle).?;
|
||||||
var caller = Caller.init(v8_isolate);
|
var caller = Caller.init(v8_isolate);
|
||||||
defer caller.deinit();
|
defer caller.deinit();
|
||||||
|
|
||||||
@@ -721,8 +721,8 @@ pub const Accessor = struct {
|
|||||||
|
|
||||||
if (@typeInfo(@TypeOf(setter)) != .null) {
|
if (@typeInfo(@TypeOf(setter)) != .null) {
|
||||||
accessor.setter = struct {
|
accessor.setter = struct {
|
||||||
fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
|
fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void {
|
||||||
const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?;
|
const v8_isolate = v8.v8__FunctionCallbackInfo__GetIsolate(handle).?;
|
||||||
var caller = Caller.init(v8_isolate);
|
var caller = Caller.init(v8_isolate);
|
||||||
defer caller.deinit();
|
defer caller.deinit();
|
||||||
|
|
||||||
@@ -742,7 +742,7 @@ pub const Accessor = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const Indexed = 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 {
|
const Opts = struct {
|
||||||
as_typed_array: bool = false,
|
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 {
|
fn init(comptime T: type, comptime getter: anytype, comptime opts: Opts) Indexed {
|
||||||
return .{ .getter = struct {
|
return .{ .getter = struct {
|
||||||
fn wrap(idx: u32, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 {
|
fn wrap(idx: u32, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 {
|
||||||
const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(handle).?;
|
const v8_isolate = v8.v8__PropertyCallbackInfo__GetIsolate(handle).?;
|
||||||
var caller = Caller.init(v8_isolate);
|
var caller = Caller.init(v8_isolate);
|
||||||
defer caller.deinit();
|
defer caller.deinit();
|
||||||
|
|
||||||
@@ -767,9 +767,9 @@ pub const Indexed = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const NamedIndexed = struct {
|
pub const NamedIndexed = struct {
|
||||||
getter: *const fn (c_name: ?*const v8.c.Name, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8,
|
getter: *const fn (c_name: ?*const v8.Name, handle: ?*const v8.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,
|
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.c.Name, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 = null,
|
deleter: ?*const fn (c_name: ?*const v8.Name, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 = null,
|
||||||
|
|
||||||
const Opts = struct {
|
const Opts = struct {
|
||||||
as_typed_array: bool = false,
|
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 {
|
fn init(comptime T: type, comptime getter: anytype, setter: anytype, deleter: anytype, comptime opts: Opts) NamedIndexed {
|
||||||
const getter_fn = struct {
|
const getter_fn = struct {
|
||||||
fn wrap(c_name: ?*const v8.c.Name, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 {
|
fn wrap(c_name: ?*const v8.Name, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 {
|
||||||
const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(handle).?;
|
const v8_isolate = v8.v8__PropertyCallbackInfo__GetIsolate(handle).?;
|
||||||
var caller = Caller.init(v8_isolate);
|
var caller = Caller.init(v8_isolate);
|
||||||
defer caller.deinit();
|
defer caller.deinit();
|
||||||
|
|
||||||
@@ -792,8 +792,8 @@ pub const NamedIndexed = struct {
|
|||||||
}.wrap;
|
}.wrap;
|
||||||
|
|
||||||
const setter_fn = if (@typeInfo(@TypeOf(setter)) == .null) null else struct {
|
const setter_fn = if (@typeInfo(@TypeOf(setter)) == .null) null else struct {
|
||||||
fn wrap(c_name: ?*const v8.c.Name, c_value: ?*const v8.c.Value, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 {
|
fn wrap(c_name: ?*const v8.Name, c_value: ?*const v8.Value, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 {
|
||||||
const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(handle).?;
|
const v8_isolate = v8.v8__PropertyCallbackInfo__GetIsolate(handle).?;
|
||||||
var caller = Caller.init(v8_isolate);
|
var caller = Caller.init(v8_isolate);
|
||||||
defer caller.deinit();
|
defer caller.deinit();
|
||||||
|
|
||||||
@@ -806,8 +806,8 @@ pub const NamedIndexed = struct {
|
|||||||
}.wrap;
|
}.wrap;
|
||||||
|
|
||||||
const deleter_fn = if (@typeInfo(@TypeOf(deleter)) == .null) null else struct {
|
const deleter_fn = if (@typeInfo(@TypeOf(deleter)) == .null) null else struct {
|
||||||
fn wrap(c_name: ?*const v8.c.Name, handle: ?*const v8.c.PropertyCallbackInfo) callconv(.c) u8 {
|
fn wrap(c_name: ?*const v8.Name, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u8 {
|
||||||
const v8_isolate = v8.c.v8__PropertyCallbackInfo__GetIsolate(handle).?;
|
const v8_isolate = v8.v8__PropertyCallbackInfo__GetIsolate(handle).?;
|
||||||
var caller = Caller.init(v8_isolate);
|
var caller = Caller.init(v8_isolate);
|
||||||
defer caller.deinit();
|
defer caller.deinit();
|
||||||
|
|
||||||
@@ -828,7 +828,7 @@ pub const NamedIndexed = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const Iterator = struct {
|
pub const Iterator = struct {
|
||||||
func: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void,
|
func: *const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void,
|
||||||
async: bool,
|
async: bool,
|
||||||
|
|
||||||
const Opts = struct {
|
const Opts = struct {
|
||||||
@@ -841,7 +841,7 @@ pub const Iterator = struct {
|
|||||||
return .{
|
return .{
|
||||||
.async = opts.async,
|
.async = opts.async,
|
||||||
.func = struct {
|
.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.? };
|
const info = FunctionCallbackInfo{ .handle = handle.? };
|
||||||
info.getReturnValue().set(info.getThis());
|
info.getReturnValue().set(info.getThis());
|
||||||
}
|
}
|
||||||
@@ -852,8 +852,8 @@ pub const Iterator = struct {
|
|||||||
return .{
|
return .{
|
||||||
.async = opts.async,
|
.async = opts.async,
|
||||||
.func = struct {
|
.func = struct {
|
||||||
fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
|
fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void {
|
||||||
const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?;
|
const v8_isolate = v8.v8__FunctionCallbackInfo__GetIsolate(handle).?;
|
||||||
var caller = Caller.init(v8_isolate);
|
var caller = Caller.init(v8_isolate);
|
||||||
defer caller.deinit();
|
defer caller.deinit();
|
||||||
|
|
||||||
@@ -866,7 +866,7 @@ pub const Iterator = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const Callable = struct {
|
pub const Callable = struct {
|
||||||
func: *const fn (?*const v8.c.FunctionCallbackInfo) callconv(.c) void,
|
func: *const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void,
|
||||||
|
|
||||||
const Opts = struct {
|
const Opts = struct {
|
||||||
null_as_undefined: bool = false,
|
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 {
|
fn init(comptime T: type, comptime func: anytype, comptime opts: Opts) Callable {
|
||||||
return .{ .func = struct {
|
return .{ .func = struct {
|
||||||
fn wrap(handle: ?*const v8.c.FunctionCallbackInfo) callconv(.c) void {
|
fn wrap(handle: ?*const v8.FunctionCallbackInfo) callconv(.c) void {
|
||||||
const v8_isolate = v8.c.v8__FunctionCallbackInfo__GetIsolate(handle).?;
|
const v8_isolate = v8.v8__FunctionCallbackInfo__GetIsolate(handle).?;
|
||||||
var caller = Caller.init(v8_isolate);
|
var caller = Caller.init(v8_isolate);
|
||||||
defer caller.deinit();
|
defer caller.deinit();
|
||||||
|
|
||||||
|
|||||||
@@ -25,20 +25,20 @@ pub fn Global(comptime T: type) type {
|
|||||||
const H = @FieldType(T, "handle");
|
const H = @FieldType(T, "handle");
|
||||||
|
|
||||||
return struct {
|
return struct {
|
||||||
global: v8.c.Global,
|
global: v8.Global,
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
pub fn init(isolate: *v8.c.Isolate, handle: H) Self {
|
pub fn init(isolate: *v8.Isolate, handle: H) Self {
|
||||||
var global: v8.c.Global = undefined;
|
var global: v8.Global = undefined;
|
||||||
v8.c.v8__Global__New(isolate, handle, &global);
|
v8.v8__Global__New(isolate, handle, &global);
|
||||||
return .{
|
return .{
|
||||||
.global = global,
|
.global = global,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
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 {
|
pub fn local(self: *const Self) H {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
pub const v8 = @import("v8");
|
pub const v8 = @import("v8").c;
|
||||||
|
|
||||||
const log = @import("../../log.zig");
|
const log = @import("../../log.zig");
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ pub const ArrayBuffer = struct {
|
|||||||
|
|
||||||
pub const Exception = struct {
|
pub const Exception = struct {
|
||||||
ctx: *const Context,
|
ctx: *const Context,
|
||||||
handle: *const v8.c.Value,
|
handle: *const v8.Value,
|
||||||
|
|
||||||
pub fn exception(self: Exception, allocator: Allocator) ![]const u8 {
|
pub fn exception(self: Exception, allocator: Allocator) ![]const u8 {
|
||||||
return self.context.valueToString(self.inner, .{ .allocator = allocator });
|
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
|
// 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
|
// 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)
|
// 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))) {
|
switch (@typeInfo(@TypeOf(value))) {
|
||||||
.void => return isolate.initUndefined(),
|
.void => return isolate.initUndefined(),
|
||||||
.null => if (comptime null_as_undefined) return isolate.initUndefined() else return isolate.initNull(),
|
.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 => {
|
ArrayBuffer => {
|
||||||
const values = value.values;
|
const values = value.values;
|
||||||
const len = values.len;
|
const len = values.len;
|
||||||
const backing_store = v8.c.v8__ArrayBuffer__NewBackingStore(isolate.handle, len);
|
const backing_store = v8.v8__ArrayBuffer__NewBackingStore(isolate.handle, len);
|
||||||
const data: [*]u8 = @ptrCast(@alignCast(v8.c.v8__BackingStore__Data(backing_store)));
|
const data: [*]u8 = @ptrCast(@alignCast(v8.v8__BackingStore__Data(backing_store)));
|
||||||
@memcpy(data[0..len], @as([]const u8, @ptrCast(values))[0..len]);
|
@memcpy(data[0..len], @as([]const u8, @ptrCast(values))[0..len]);
|
||||||
const backing_store_ptr = v8.c.v8__BackingStore__TO_SHARED_PTR(backing_store);
|
const backing_store_ptr = v8.v8__BackingStore__TO_SHARED_PTR(backing_store);
|
||||||
return @ptrCast(v8.c.v8__ArrayBuffer__New2(isolate.handle, &backing_store_ptr).?);
|
return @ptrCast(v8.v8__ArrayBuffer__New2(isolate.handle, &backing_store_ptr).?);
|
||||||
},
|
},
|
||||||
// zig fmt: off
|
// zig fmt: off
|
||||||
TypedArray(u8), TypedArray(u16), TypedArray(u32), TypedArray(u64),
|
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)),
|
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) {
|
if (len == 0) {
|
||||||
array_buffer = v8.c.v8__ArrayBuffer__New(isolate.handle, 0).?;
|
array_buffer = v8.v8__ArrayBuffer__New(isolate.handle, 0).?;
|
||||||
} else {
|
} else {
|
||||||
const buffer_len = len * bits / 8;
|
const buffer_len = len * bits / 8;
|
||||||
const backing_store = v8.c.v8__ArrayBuffer__NewBackingStore(isolate.handle, buffer_len).?;
|
const backing_store = v8.v8__ArrayBuffer__NewBackingStore(isolate.handle, buffer_len).?;
|
||||||
const data: [*]u8 = @ptrCast(@alignCast(v8.c.v8__BackingStore__Data(backing_store)));
|
const data: [*]u8 = @ptrCast(@alignCast(v8.v8__BackingStore__Data(backing_store)));
|
||||||
@memcpy(data[0..buffer_len], @as([]const u8, @ptrCast(values))[0..buffer_len]);
|
@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);
|
const backing_store_ptr = v8.v8__BackingStore__TO_SHARED_PTR(backing_store);
|
||||||
array_buffer = v8.c.v8__ArrayBuffer__New2(isolate.handle, &backing_store_ptr).?;
|
array_buffer = v8.v8__ArrayBuffer__New2(isolate.handle, &backing_store_ptr).?;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (@typeInfo(value_type)) {
|
switch (@typeInfo(value_type)) {
|
||||||
.int => |n| switch (n.signedness) {
|
.int => |n| switch (n.signedness) {
|
||||||
.unsigned => switch (n.bits) {
|
.unsigned => switch (n.bits) {
|
||||||
8 => return @ptrCast(v8.c.v8__Uint8Array__New(array_buffer, 0, len).?),
|
8 => return @ptrCast(v8.v8__Uint8Array__New(array_buffer, 0, len).?),
|
||||||
16 => return @ptrCast(v8.c.v8__Uint16Array__New(array_buffer, 0, len).?),
|
16 => return @ptrCast(v8.v8__Uint16Array__New(array_buffer, 0, len).?),
|
||||||
32 => return @ptrCast(v8.c.v8__Uint32Array__New(array_buffer, 0, len).?),
|
32 => return @ptrCast(v8.v8__Uint32Array__New(array_buffer, 0, len).?),
|
||||||
64 => return @ptrCast(v8.c.v8__BigUint64Array__New(array_buffer, 0, len).?),
|
64 => return @ptrCast(v8.v8__BigUint64Array__New(array_buffer, 0, len).?),
|
||||||
else => {},
|
else => {},
|
||||||
},
|
},
|
||||||
.signed => switch (n.bits) {
|
.signed => switch (n.bits) {
|
||||||
8 => return @ptrCast(v8.c.v8__Int8Array__New(array_buffer, 0, len).?),
|
8 => return @ptrCast(v8.v8__Int8Array__New(array_buffer, 0, len).?),
|
||||||
16 => return @ptrCast(v8.c.v8__Int16Array__New(array_buffer, 0, len).?),
|
16 => return @ptrCast(v8.v8__Int16Array__New(array_buffer, 0, len).?),
|
||||||
32 => return @ptrCast(v8.c.v8__Int32Array__New(array_buffer, 0, len).?),
|
32 => return @ptrCast(v8.v8__Int32Array__New(array_buffer, 0, len).?),
|
||||||
64 => return @ptrCast(v8.c.v8__BigInt64Array__New(array_buffer, 0, len).?),
|
64 => return @ptrCast(v8.v8__BigInt64Array__New(array_buffer, 0, len).?),
|
||||||
else => {},
|
else => {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.float => |f| switch (f.bits) {
|
.float => |f| switch (f.bits) {
|
||||||
32 => return @ptrCast(v8.c.v8__Float32Array__New(array_buffer, 0, len).?),
|
32 => return @ptrCast(v8.v8__Float32Array__New(array_buffer, 0, len).?),
|
||||||
64 => return @ptrCast(v8.c.v8__Float64Array__New(array_buffer, 0, len).?),
|
64 => return @ptrCast(v8.v8__Float64Array__New(array_buffer, 0, len).?),
|
||||||
else => {},
|
else => {},
|
||||||
},
|
},
|
||||||
else => {},
|
else => {},
|
||||||
@@ -367,8 +367,8 @@ pub const PrototypeChainEntry = struct {
|
|||||||
// it'll call this function to gets its [optional] subtype - which, from V8's
|
// it'll call this function to gets its [optional] subtype - which, from V8's
|
||||||
// point of view, is an arbitrary string.
|
// point of view, is an arbitrary string.
|
||||||
pub export fn v8_inspector__Client__IMPL__valueSubtype(
|
pub export fn v8_inspector__Client__IMPL__valueSubtype(
|
||||||
_: *v8.c.InspectorClientImpl,
|
_: *v8.InspectorClientImpl,
|
||||||
c_value: *const v8.c.Value,
|
c_value: *const v8.Value,
|
||||||
) callconv(.c) [*c]const u8 {
|
) callconv(.c) [*c]const u8 {
|
||||||
const external_entry = Inspector.getTaggedAnyOpaque(c_value) orelse return null;
|
const external_entry = Inspector.getTaggedAnyOpaque(c_value) orelse return null;
|
||||||
return if (external_entry.subtype) |st| @tagName(st) else null;
|
return if (external_entry.subtype) |st| @tagName(st) else null;
|
||||||
@@ -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
|
// present, even if it's empty. So if we have a subType for the value, we'll
|
||||||
// put an empty description.
|
// put an empty description.
|
||||||
pub export fn v8_inspector__Client__IMPL__descriptionForValueSubtype(
|
pub export fn v8_inspector__Client__IMPL__descriptionForValueSubtype(
|
||||||
_: *v8.c.InspectorClientImpl,
|
_: *v8.InspectorClientImpl,
|
||||||
v8_context: *const v8.c.Context,
|
v8_context: *const v8.Context,
|
||||||
c_value: *const v8.c.Value,
|
c_value: *const v8.Value,
|
||||||
) callconv(.c) [*c]const u8 {
|
) callconv(.c) [*c]const u8 {
|
||||||
_ = v8_context;
|
_ = v8_context;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user