File tree 2 files changed +32
-1
lines changed
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 {
302
302
}
303
303
}
304
304
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
+
305
332
// compile and run a JS script
306
333
// It doesn't wait for callbacks execution
307
334
pub fn exec (
@@ -431,6 +458,10 @@ pub const JSObject = struct {
431
458
}
432
459
};
433
460
461
+ pub const JSScript = struct {
462
+ value : v8.UnboundScript ,
463
+ };
464
+
434
465
pub const JSValue = struct {
435
466
value : v8.Value ,
436
467
You can’t perform that action at this time.
0 commit comments