Skip to content

Commit 7f7f474

Browse files
authored
Merge pull request #886 from lightpanda-io/scriptcompiler-compile
use ScriptCompiler to compile script
2 parents d08fd29 + eb14ac3 commit 7f7f474

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

.github/actions/install/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ inputs:
1717
zig-v8:
1818
description: 'zig v8 version to install'
1919
required: false
20-
default: 'v0.1.27'
20+
default: 'v0.1.28'
2121
v8:
2222
description: 'v8 version to install'
2323
required: false

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ARG MINISIG=0.12
44
ARG ZIG=0.14.1
55
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
66
ARG V8=13.6.233.8
7-
ARG ZIG_V8=v0.1.27
7+
ARG ZIG_V8=v0.1.28
88
ARG TARGETPLATFORM
99

1010
RUN apt-get update -yq && \

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/dd087771378ea854452bcb010309fa9ffe5a9cac.tar.gz",
17-
.hash = "v8-0.0.0-xddH66e8AwBL3O_A8yWQYQIyfMbKHFNVQr_NqM6YjU11",
16+
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/10025d52cb1d33434f18634c326e67038fd927d5.tar.gz",
17+
.hash = "v8-0.0.0-xddH6-vCAwCtIRfzEw1zKu0TnMbDrFltZ8I0x-PALyIh",
1818
},
1919
//.v8 = .{ .path = "../zig-v8-fork" },
2020
//.tigerbeetle_io = .{ .path = "../tigerbeetle-io" },

src/runtime/js.zig

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -747,18 +747,9 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
747747
}
748748

749749
pub fn exec(self: *JsContext, src: []const u8, name: ?[]const u8) !Value {
750-
const isolate = self.isolate;
751750
const v8_context = self.v8_context;
752751

753-
var origin: ?v8.ScriptOrigin = null;
754-
if (name) |n| {
755-
const scr_name = v8.String.initUtf8(isolate, n);
756-
origin = v8.ScriptOrigin.initDefault(scr_name.toValue());
757-
}
758-
const scr_js = v8.String.initUtf8(isolate, src);
759-
const scr = v8.Script.compile(v8_context, scr_js, origin) catch {
760-
return error.CompilationError;
761-
};
752+
const scr = try compileScript(self.isolate, v8_context, src, name);
762753

763754
const value = scr.run(v8_context) catch {
764755
return error.ExecutionError;
@@ -2035,6 +2026,25 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
20352026
};
20362027
}
20372028

2029+
fn compileScript(isolate: v8.Isolate, ctx: v8.Context, src: []const u8, name: ?[]const u8) !v8.Script {
2030+
// compile
2031+
const script_name = v8.String.initUtf8(isolate, name orelse "anonymous");
2032+
const script_source = v8.String.initUtf8(isolate, src);
2033+
2034+
const origin = v8.ScriptOrigin.initDefault(script_name.toValue());
2035+
2036+
var script_comp_source: v8.ScriptCompilerSource = undefined;
2037+
v8.ScriptCompilerSource.init(&script_comp_source, script_source, origin, null);
2038+
defer script_comp_source.deinit();
2039+
2040+
return v8.ScriptCompiler.compile(
2041+
ctx,
2042+
&script_comp_source,
2043+
.kNoCompileOptions,
2044+
.kNoCacheNoReason,
2045+
) catch return error.CompilationError;
2046+
}
2047+
20382048
fn compileModule(isolate: v8.Isolate, src: []const u8, name: []const u8) !v8.Module {
20392049
// compile
20402050
const script_name = v8.String.initUtf8(isolate, name);

0 commit comments

Comments
 (0)