File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -302,6 +302,33 @@ pub const Env = struct {
302302 }
303303 }
304304
305+ // compile a JS script
306+ pub fn compile (
307+ self : Env ,
308+ script : []const u8 ,
309+ name : []const u8 ,
310+ ) anyerror ! JSScript {
311+
312+ // compile
313+ const scr_name = v8 .String .initUtf8 (self .isolate , name );
314+ const script_source = v8 .String .initUtf8 (self .isolate , script );
315+
316+ const origin = v8 .ScriptOrigin .initDefault (self .isolate , scr_name .toValue ());
317+
318+ var script_comp_source : v8.ScriptCompilerSource = undefined ;
319+ script_comp_source .init (script_source , origin , null );
320+ defer script_comp_source .deinit ();
321+
322+ const value = v8 .ScriptCompiler .CompileUnboundScript (
323+ self .isolate ,
324+ & script_comp_source ,
325+ .kNoCompileOptions ,
326+ .kNoCacheNoReason ,
327+ ) catch return error .JSCompile ;
328+
329+ return .{ .value = value };
330+ }
331+
305332 // compile and run a JS script
306333 // It doesn't wait for callbacks execution
307334 pub fn exec (
@@ -431,6 +458,10 @@ pub const JSObject = struct {
431458 }
432459};
433460
461+ pub const JSScript = struct {
462+ value : v8.UnboundScript ,
463+ };
464+
434465pub const JSValue = struct {
435466 value : v8.Value ,
436467
You can’t perform that action at this time.
0 commit comments