mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
Merge pull request #886 from lightpanda-io/scriptcompiler-compile
use ScriptCompiler to compile script
This commit is contained in:
2
.github/actions/install/action.yml
vendored
2
.github/actions/install/action.yml
vendored
@@ -17,7 +17,7 @@ inputs:
|
||||
zig-v8:
|
||||
description: 'zig v8 version to install'
|
||||
required: false
|
||||
default: 'v0.1.27'
|
||||
default: 'v0.1.28'
|
||||
v8:
|
||||
description: 'v8 version to install'
|
||||
required: false
|
||||
|
||||
@@ -4,7 +4,7 @@ ARG MINISIG=0.12
|
||||
ARG ZIG=0.14.1
|
||||
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
|
||||
ARG V8=13.6.233.8
|
||||
ARG ZIG_V8=v0.1.27
|
||||
ARG ZIG_V8=v0.1.28
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
RUN apt-get update -yq && \
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
.hash = "tigerbeetle_io-0.0.0-ViLgxpyRBAB5BMfIcj3KMXfbJzwARs9uSl8aRy2OXULd",
|
||||
},
|
||||
.v8 = .{
|
||||
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/dd087771378ea854452bcb010309fa9ffe5a9cac.tar.gz",
|
||||
.hash = "v8-0.0.0-xddH66e8AwBL3O_A8yWQYQIyfMbKHFNVQr_NqM6YjU11",
|
||||
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/10025d52cb1d33434f18634c326e67038fd927d5.tar.gz",
|
||||
.hash = "v8-0.0.0-xddH6-vCAwCtIRfzEw1zKu0TnMbDrFltZ8I0x-PALyIh",
|
||||
},
|
||||
//.v8 = .{ .path = "../zig-v8-fork" },
|
||||
//.tigerbeetle_io = .{ .path = "../tigerbeetle-io" },
|
||||
|
||||
@@ -747,18 +747,9 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
|
||||
}
|
||||
|
||||
pub fn exec(self: *JsContext, src: []const u8, name: ?[]const u8) !Value {
|
||||
const isolate = self.isolate;
|
||||
const v8_context = self.v8_context;
|
||||
|
||||
var origin: ?v8.ScriptOrigin = null;
|
||||
if (name) |n| {
|
||||
const scr_name = v8.String.initUtf8(isolate, n);
|
||||
origin = v8.ScriptOrigin.initDefault(scr_name.toValue());
|
||||
}
|
||||
const scr_js = v8.String.initUtf8(isolate, src);
|
||||
const scr = v8.Script.compile(v8_context, scr_js, origin) catch {
|
||||
return error.CompilationError;
|
||||
};
|
||||
const scr = try compileScript(self.isolate, v8_context, src, name);
|
||||
|
||||
const value = scr.run(v8_context) catch {
|
||||
return error.ExecutionError;
|
||||
@@ -2035,6 +2026,25 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
fn compileScript(isolate: v8.Isolate, ctx: v8.Context, src: []const u8, name: ?[]const u8) !v8.Script {
|
||||
// compile
|
||||
const script_name = v8.String.initUtf8(isolate, name orelse "anonymous");
|
||||
const script_source = v8.String.initUtf8(isolate, src);
|
||||
|
||||
const origin = v8.ScriptOrigin.initDefault(script_name.toValue());
|
||||
|
||||
var script_comp_source: v8.ScriptCompilerSource = undefined;
|
||||
v8.ScriptCompilerSource.init(&script_comp_source, script_source, origin, null);
|
||||
defer script_comp_source.deinit();
|
||||
|
||||
return v8.ScriptCompiler.compile(
|
||||
ctx,
|
||||
&script_comp_source,
|
||||
.kNoCompileOptions,
|
||||
.kNoCacheNoReason,
|
||||
) catch return error.CompilationError;
|
||||
}
|
||||
|
||||
fn compileModule(isolate: v8.Isolate, src: []const u8, name: []const u8) !v8.Module {
|
||||
// compile
|
||||
const script_name = v8.String.initUtf8(isolate, name);
|
||||
|
||||
Reference in New Issue
Block a user