Skip to content

Commit 210d4f6

Browse files
authored
Merge pull request #620 from lightpanda-io/upgrade_v8
Upgrade v8
2 parents 3fec6ff + b559506 commit 210d4f6

File tree

6 files changed

+59
-63
lines changed

6 files changed

+59
-63
lines changed

.github/actions/install/action.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ inputs:
1717
zig-v8:
1818
description: 'zig v8 version to install'
1919
required: false
20-
default: 'v0.1.21'
20+
default: 'v0.1.22'
2121
v8:
2222
description: 'v8 version to install'
2323
required: false
24-
default: '11.1.134'
24+
default: '13.6.233.8'
2525
cache-dir:
2626
description: 'cache dir to use'
2727
required: false
@@ -59,11 +59,11 @@ runs:
5959
- name: install v8
6060
shell: bash
6161
run: |
62-
mkdir -p v8/build/${{inputs.arch}}-${{inputs.os}}/debug/ninja/obj/zig/
63-
ln -s ${{ inputs.cache-dir }}/v8/libc_v8.a v8/build/${{inputs.arch}}-${{inputs.os}}/debug/ninja/obj/zig/libc_v8.a
62+
mkdir -p v8/out/debug/obj/zig/
63+
ln -s ${{ inputs.cache-dir }}/v8/libc_v8.a v8/out/debug/obj/zig/libc_v8.a
6464
65-
mkdir -p v8/build/${{inputs.arch}}-${{inputs.os}}/release/ninja/obj/zig/
66-
ln -s ${{ inputs.cache-dir }}/v8/libc_v8.a v8/build/${{inputs.arch}}-${{inputs.os}}/release/ninja/obj/zig/libc_v8.a
65+
mkdir -p v8/out/release/obj/zig/
66+
ln -s ${{ inputs.cache-dir }}/v8/libc_v8.a v8/out/release/obj/zig/libc_v8.a
6767
6868
- name: libiconv
6969
shell: bash

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG ZIG=0.14.0
55
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
66
ARG ARCH=x86_64
77
ARG V8=11.1.134
8-
ARG ZIG_V8=v0.1.21
8+
ARG ZIG_V8=v0.1.22
99

1010
RUN apt-get update -yq && \
1111
apt-get install -yq xz-utils \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ For Debian/Ubuntu based Linux:
161161
sudo apt install xz-utils \
162162
python3 ca-certificates git \
163163
pkg-config libglib2.0-dev \
164-
gperf libexpat1-dev \
164+
gperf libexpat1-dev unzip \
165165
cmake clang
166166
```
167167

build.zig

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,29 +158,25 @@ fn common(b: *std.Build, opts: *std.Build.Step.Options, step: *std.Build.Step.Co
158158
mod.addImport("v8", v8_mod);
159159
}
160160

161-
const mode_str: []const u8 = if (mod.optimize.? == .Debug) "debug" else "release";
162-
163-
// FIXME: we are tied to native v8 builds, currently:
164-
// - aarch64-macos
165-
// - x86_64-linux
166-
const os = target.result.os.tag;
167-
const arch = target.result.cpu.arch;
168-
switch (os) {
169-
.macos => {},
170-
.linux => {
171-
// TODO: why do we need it? It should be linked already when we built v8
172-
mod.link_libcpp = true;
173-
},
174-
else => return error.OsNotSupported,
175-
}
176-
177161
const lib_path = try std.fmt.allocPrint(
178162
mod.owner.allocator,
179-
"v8/build/{s}-{s}/{s}/ninja/obj/zig/libc_v8.a",
180-
.{ @tagName(arch), @tagName(os), mode_str },
163+
"v8/out/{s}/obj/zig/libc_v8.a",
164+
.{if (mod.optimize.? == .Debug) "debug" else "release"},
181165
);
166+
mod.link_libcpp = true;
182167
mod.addObjectFile(mod.owner.path(lib_path));
168+
169+
switch (target.result.os.tag) {
170+
.macos => {
171+
// v8 has a dependency, abseil-cpp, which, on Mac, uses CoreFoundation
172+
mod.addSystemFrameworkPath(.{ .cwd_relative = "/System/Library/Frameworks" });
173+
mod.linkFramework("CoreFoundation", .{});
174+
},
175+
else => {},
176+
}
177+
183178
mod.addImport("build_info", opts.createModule());
179+
mod.addObjectFile(mod.owner.path(lib_path));
184180
}
185181

186182
fn moduleNetSurf(b: *std.Build, step: *std.Build.Step.Compile, target: std.Build.ResolvedTarget) !void {

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
.hash = "tigerbeetle_io-0.0.0-ViLgxpyRBAB5BMfIcj3KMXfbJzwARs9uSl8aRy2OXULd",
1414
},
1515
.v8 = .{
16-
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/fc764e7d29bc1514924e8df09255a057e03d453a.tar.gz",
17-
.hash = "v8-0.0.0-xddH6zUZIQBJf109L94sC-mWH1NJXWCnOJGJttKtfasI",
16+
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/4809111f930293c6d5082971ad7ffc3d822b6f37.tar.gz",
17+
.hash = "v8-0.0.0-xddH632xAwAjF7ieh48tjbMpu7fVVGr3r3aLwmBbFvPk",
1818
},
1919
//.v8 = .{ .path = "../zig-v8-fork" },
2020
//.tigerbeetle_io = .{ .path = "../tigerbeetle-io" },

src/runtime/js.zig

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
594594
var origin: ?v8.ScriptOrigin = null;
595595
if (name) |n| {
596596
const scr_name = v8.String.initUtf8(isolate, n);
597-
origin = v8.ScriptOrigin.initDefault(self.isolate, scr_name.toValue());
597+
origin = v8.ScriptOrigin.initDefault(scr_name.toValue());
598598
}
599599
const scr_js = v8.String.initUtf8(isolate, src);
600600
const scr = v8.Script.compile(context, scr_js, origin) catch {
@@ -1142,7 +1142,6 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
11421142
const script_source = v8.String.initUtf8(isolate, src);
11431143

11441144
const origin = v8.ScriptOrigin.init(
1145-
isolate,
11461145
script_name.toValue(),
11471146
0, // resource_line_offset
11481147
0, // resource_column_offset
@@ -1201,14 +1200,15 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
12011200
if (@hasDecl(Struct, "get_symbol_toStringTag") == false) {
12021201
// If this WAS defined, then we would have created it in generateProperty.
12031202
// But if it isn't, we create a default one
1204-
const key = v8.Symbol.getToStringTag(isolate).toName();
1205-
template_proto.setGetter(key, struct {
1206-
fn stringTag(_: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) void {
1207-
const info = v8.PropertyCallbackInfo.initFromV8(raw_info);
1203+
const string_tag_callback = v8.FunctionTemplate.initCallback(isolate, struct {
1204+
fn stringTag(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void {
1205+
const info = v8.FunctionCallbackInfo.initFromV8(raw_info);
12081206
const class_name = v8.String.initUtf8(info.getIsolate(), comptime classNameForStruct(Struct));
12091207
info.getReturnValue().set(class_name);
12101208
}
12111209
}.stringTag);
1210+
const key = v8.Symbol.getToStringTag(isolate).toName();
1211+
template_proto.setAccessorGetter(key, string_tag_callback);
12121212
}
12131213

12141214
generateIndexer(Struct, template_proto);
@@ -1309,9 +1309,9 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
13091309
js_name = v8.String.initUtf8(isolate, name).toName();
13101310
}
13111311

1312-
const getter_callback = struct {
1313-
fn callback(_: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) void {
1314-
const info = v8.PropertyCallbackInfo.initFromV8(raw_info);
1312+
const getter_callback = v8.FunctionTemplate.initCallback(isolate, struct {
1313+
fn callback(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void {
1314+
const info = v8.FunctionCallbackInfo.initFromV8(raw_info);
13151315
var caller = Caller(Self, State).init(info);
13161316
defer caller.deinit();
13171317

@@ -1320,28 +1320,30 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
13201320
caller.handleError(Struct, named_function, err, info);
13211321
};
13221322
}
1323-
}.callback;
1323+
}.callback);
13241324

13251325
const setter_name = "set_" ++ name;
13261326
if (@hasDecl(Struct, setter_name) == false) {
1327-
template_proto.setGetter(js_name, getter_callback);
1327+
template_proto.setAccessorGetter(js_name, getter_callback);
13281328
return;
13291329
}
13301330

1331-
const setter_callback = struct {
1332-
fn callback(_: ?*const v8.C_Name, raw_value: ?*const v8.C_Value, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) void {
1333-
const info = v8.PropertyCallbackInfo.initFromV8(raw_info);
1331+
const setter_callback = v8.FunctionTemplate.initCallback(isolate, struct {
1332+
fn callback(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void {
1333+
const info = v8.FunctionCallbackInfo.initFromV8(raw_info);
13341334
var caller = Caller(Self, State).init(info);
13351335
defer caller.deinit();
13361336

1337-
const js_value = v8.Value{ .handle = raw_value.? };
1337+
std.debug.assert(info.length() == 1);
1338+
const js_value = info.getArg(0);
13381339
const named_function = comptime NamedFunction.init(Struct, "set_" ++ name);
13391340
caller.setter(Struct, named_function, js_value, info) catch |err| {
13401341
caller.handleError(Struct, named_function, err, info);
13411342
};
13421343
}
1343-
}.callback;
1344-
template_proto.setGetterAndSetter(js_name, getter_callback, setter_callback);
1344+
}.callback);
1345+
1346+
template_proto.setAccessorGetterAndSetter(js_name, getter_callback, setter_callback);
13451347
}
13461348

13471349
fn generateIndexer(comptime Struct: type, template_proto: v8.ObjectTemplate) void {
@@ -1350,14 +1352,15 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
13501352
}
13511353
const configuration = v8.IndexedPropertyHandlerConfiguration{
13521354
.getter = struct {
1353-
fn callback(idx: u32, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) void {
1355+
fn callback(idx: u32, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 {
13541356
const info = v8.PropertyCallbackInfo.initFromV8(raw_info);
13551357
var caller = Caller(Self, State).init(info);
13561358
defer caller.deinit();
13571359

13581360
const named_function = comptime NamedFunction.init(Struct, "indexed_get");
1359-
caller.getIndex(Struct, named_function, idx, info) catch |err| {
1361+
return caller.getIndex(Struct, named_function, idx, info) catch |err| blk: {
13601362
caller.handleError(Struct, named_function, err, info);
1363+
break :blk v8.Intercepted.No;
13611364
};
13621365
}
13631366
}.callback,
@@ -1379,14 +1382,15 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
13791382
}
13801383
const configuration = v8.NamedPropertyHandlerConfiguration{
13811384
.getter = struct {
1382-
fn callback(c_name: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) void {
1385+
fn callback(c_name: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 {
13831386
const info = v8.PropertyCallbackInfo.initFromV8(raw_info);
13841387
var caller = Caller(Self, State).init(info);
13851388
defer caller.deinit();
13861389

13871390
const named_function = comptime NamedFunction.init(Struct, "named_get");
1388-
caller.getNamedIndex(Struct, named_function, .{ .handle = c_name.? }, info) catch |err| {
1391+
return caller.getNamedIndex(Struct, named_function, .{ .handle = c_name.? }, info) catch |err| blk: {
13891392
caller.handleError(Struct, named_function, err, info);
1393+
break :blk v8.Intercepted.No;
13901394
};
13911395
}
13921396
}.callback,
@@ -1762,7 +1766,7 @@ fn Caller(comptime E: type, comptime State: type) type {
17621766
info.getReturnValue().set(try self.zigValueToJs(res));
17631767
}
17641768

1765-
fn getter(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, info: v8.PropertyCallbackInfo) !void {
1769+
fn getter(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, info: v8.FunctionCallbackInfo) !void {
17661770
const func = @field(Struct, named_function.name);
17671771
const Getter = @TypeOf(func);
17681772
if (@typeInfo(Getter).@"fn".return_type == null) {
@@ -1788,7 +1792,7 @@ fn Caller(comptime E: type, comptime State: type) type {
17881792
info.getReturnValue().set(try self.zigValueToJs(res));
17891793
}
17901794

1791-
fn setter(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, js_value: v8.Value, info: v8.PropertyCallbackInfo) !void {
1795+
fn setter(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, js_value: v8.Value, info: v8.FunctionCallbackInfo) !void {
17921796
const func = @field(Struct, named_function.name);
17931797
comptime assertSelfReceiver(Struct, named_function);
17941798

@@ -1820,7 +1824,7 @@ fn Caller(comptime E: type, comptime State: type) type {
18201824
_ = @call(.auto, func, args);
18211825
}
18221826

1823-
fn getIndex(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, idx: u32, info: v8.PropertyCallbackInfo) !void {
1827+
fn getIndex(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, idx: u32, info: v8.PropertyCallbackInfo) !u8 {
18241828
const func = @field(Struct, named_function.name);
18251829
const IndexedGet = @TypeOf(func);
18261830
if (@typeInfo(IndexedGet).@"fn".return_type == null) {
@@ -1849,15 +1853,13 @@ fn Caller(comptime E: type, comptime State: type) type {
18491853

18501854
const res = @call(.auto, func, args);
18511855
if (has_value == false) {
1852-
// for an indexed parameter, say nodes[10000], we should return
1853-
// undefined, not null, if the index is out of rante
1854-
info.getReturnValue().set(try self.zigValueToJs({}));
1855-
} else {
1856-
info.getReturnValue().set(try self.zigValueToJs(res));
1856+
return v8.Intercepted.No;
18571857
}
1858+
info.getReturnValue().set(try self.zigValueToJs(res));
1859+
return v8.Intercepted.Yes;
18581860
}
18591861

1860-
fn getNamedIndex(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, name: v8.Name, info: v8.PropertyCallbackInfo) !void {
1862+
fn getNamedIndex(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, name: v8.Name, info: v8.PropertyCallbackInfo) !u8 {
18611863
const func = @field(Struct, named_function.name);
18621864
const NamedGet = @TypeOf(func);
18631865
if (@typeInfo(NamedGet).@"fn".return_type == null) {
@@ -1885,12 +1887,10 @@ fn Caller(comptime E: type, comptime State: type) type {
18851887

18861888
const res = @call(.auto, func, args);
18871889
if (has_value == false) {
1888-
// for an indexed parameter, say nodes[10000], we should return
1889-
// undefined, not null, if the index is out of rante
1890-
info.getReturnValue().set(try self.zigValueToJs({}));
1891-
} else {
1892-
info.getReturnValue().set(try self.zigValueToJs(res));
1890+
return v8.Intercepted.No;
18931891
}
1892+
info.getReturnValue().set(try self.zigValueToJs(res));
1893+
return v8.Intercepted.Yes;
18941894
}
18951895

18961896
fn nameToString(self: *Self, name: v8.Name) ![]const u8 {

0 commit comments

Comments
 (0)