Skip to content

Commit edaabde

Browse files
committed
expose JSScript as unbound script
1 parent 22856a3 commit edaabde

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/engines/v8/v8.zig

+16-3
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,14 @@ pub const Env = struct {
319319
script_comp_source.init(script_source, origin, null);
320320
defer script_comp_source.deinit();
321321

322-
const value = v8.ScriptCompiler.CompileUnboundScript(
322+
const uboundedscript = v8.ScriptCompiler.CompileUnboundScript(
323323
self.isolate,
324324
&script_comp_source,
325325
.kNoCompileOptions,
326326
.kNoCacheNoReason,
327327
) catch return error.JSCompile;
328328

329-
return .{ .value = value };
329+
return .{ .inner = uboundedscript };
330330
}
331331

332332
// compile and run a JS script
@@ -459,7 +459,20 @@ pub const JSObject = struct {
459459
};
460460

461461
pub const JSScript = struct {
462-
value: v8.UnboundScript,
462+
inner: v8.UnboundScript,
463+
464+
// Bind the unbounded script to the current context and run it.
465+
pub fn run(self: JSScript, env: Env) anyerror!JSValue {
466+
if (env.js_ctx == null) {
467+
return error.EnvNotStarted;
468+
}
469+
470+
const scr = self.inner.bindToCurrentContext() catch return error.JSExec;
471+
472+
// run
473+
const value = scr.run(env.js_ctx.?) catch return error.JSExec;
474+
return .{ .value = value };
475+
}
463476
};
464477

465478
pub const JSValue = struct {

0 commit comments

Comments
 (0)