Merge pull request #1540 from lightpanda-io/tao_v8_storage

Optimize tao storage in v8 object.
This commit is contained in:
Karl Seguin
2026-02-14 14:14:51 +08:00
committed by GitHub
7 changed files with 17 additions and 14 deletions

View File

@@ -13,7 +13,7 @@ inputs:
zig-v8:
description: 'zig v8 version to install'
required: false
default: 'v0.2.8'
default: 'v0.2.9'
v8:
description: 'v8 version to install'
required: false

View File

@@ -3,7 +3,7 @@ FROM debian:stable-slim
ARG MINISIG=0.12
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
ARG V8=14.0.365.4
ARG ZIG_V8=v0.2.8
ARG ZIG_V8=v0.2.9
ARG TARGETPLATFORM
RUN apt-get update -yq && \

View File

@@ -6,8 +6,8 @@
.minimum_zig_version = "0.15.2",
.dependencies = .{
.v8 = .{
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/refs/tags/v0.2.8.tar.gz",
.hash = "v8-0.0.0-xddH63lfBADJ7UE2zAJ8nJIBnxoSiimXSaX6Q_M_7DS3",
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/refs/tags/v0.2.9.tar.gz",
.hash = "v8-0.0.0-xddH689vBACgpqFVEhT2wxRin-qQQSOcKJoM37MVo0rU",
},
//.v8 = .{ .path = "../zig-v8-fork" },
.@"boringssl-zig" = .{

View File

@@ -78,6 +78,14 @@ pub const InitOpts = struct {
};
pub fn init(app: *App, opts: InitOpts) !Env {
if (comptime IS_DEBUG) {
comptime {
// V8 requirement for any data using SetAlignedPointerInInternalField
const a = @alignOf(@import("TaggedOpaque.zig"));
std.debug.assert(a >= 2 and a % 2 == 0);
}
}
const allocator = app.allocator;
const snapshot = &app.snapshot;

View File

@@ -364,9 +364,8 @@ pub fn getTaggedOpaque(value: *const v8.Value) ?*TaggedOpaque {
return null;
}
const external_value = v8.v8__Object__GetInternalField(value, 0).?;
const external_data = v8.v8__External__Value(external_value).?;
return @ptrCast(@alignCast(external_data));
const tao_ptr = v8.v8__Object__GetAlignedPointerFromInternalField(value, 0).?;
return @ptrCast(@alignCast(tao_ptr));
}
fn cZigStringToString(s: v8.CZigString) ?[]const u8 {

View File

@@ -181,11 +181,7 @@ pub fn mapZigInstanceToJs(self: *const Local, js_obj_handle: ?*const v8.Object,
.subtype = if (@hasDecl(JsApi.Meta, "subtype")) JsApi.Meta.subype else .node,
};
// Skip setting internal field for the global object (Window)
// Window accessors get the instance from context.page.window instead
// if (resolved.class_id != @import("../webapi/Window.zig").JsApi.Meta.class_id) {
v8.v8__Object__SetInternalField(js_obj.handle, 0, isolate.createExternal(tao));
// }
v8.v8__Object__SetAlignedPointerInInternalField(js_obj.handle, 0, tao);
} else {
// If the struct is empty, we don't need to do all
// the TOA stuff and setting the internal data.

View File

@@ -133,8 +133,8 @@ pub fn fromJS(comptime R: type, js_obj_handle: *const v8.Object) !R {
@compileError("unknown Zig type: " ++ @typeName(R));
}
const internal_field_handle = v8.v8__Object__GetInternalField(js_obj_handle, 0).?;
const tao: *TaggedOpaque = @ptrCast(@alignCast(v8.v8__External__Value(internal_field_handle)));
const tao_ptr = v8.v8__Object__GetAlignedPointerFromInternalField(js_obj_handle, 0).?;
const tao: *TaggedOpaque = @ptrCast(@alignCast(tao_ptr));
const expected_type_index = bridge.JsApiLookup.getId(JsApi);
const prototype_chain = tao.prototype_chain[0..tao.prototype_len];