File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff 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
461461pub 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
465478pub const JSValue = struct {
You can’t perform that action at this time.
0 commit comments