File tree 1 file changed +16
-3
lines changed
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 {
319
319
script_comp_source .init (script_source , origin , null );
320
320
defer script_comp_source .deinit ();
321
321
322
- const value = v8 .ScriptCompiler .CompileUnboundScript (
322
+ const uboundedscript = v8 .ScriptCompiler .CompileUnboundScript (
323
323
self .isolate ,
324
324
& script_comp_source ,
325
325
.kNoCompileOptions ,
326
326
.kNoCacheNoReason ,
327
327
) catch return error .JSCompile ;
328
328
329
- return .{ .value = value };
329
+ return .{ .inner = uboundedscript };
330
330
}
331
331
332
332
// compile and run a JS script
@@ -459,7 +459,20 @@ pub const JSObject = struct {
459
459
};
460
460
461
461
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
+ }
463
476
};
464
477
465
478
pub const JSValue = struct {
You can’t perform that action at this time.
0 commit comments