A class for holding precompiled scripts, and running them in specific sandboxes.

Constructor

new(code:String, ?options:Null<ScriptOptions>)

Creating a new Script compiles code but does not run it. Instead, the created Script object represents this compiled code.

This script can be run later many times using methods below.

The returned script is not bound to any global object. It is bound before each run, just for that run.

Methods

runInContext(contextifiedSandbox:VmContext<Dynamic>, ?options:Null<ScriptRunOptions>):Dynamic

Similar to Vm.runInContext but a method of a precompiled Script object. runInContext runs script's compiled code in contextifiedSandbox and returns the result. Running code does not have access to local scope.

runInNewContext(?sandbox:{}):Dynamic

runInNewContext(sandbox:{}, ?options:Null<ScriptRunOptions>):Dynamic

Similar to Vm.runInNewContext but a method of a precompiled Script object. runInNewContext contextifies sandbox if passed or creates a new contextified sandbox if it's omitted, and then runs script's compiled code with the sandbox as the global object and returns the result. Running code does not have access to local scope.

runInThisContext(?options:Null<ScriptRunOptions>):Dynamic

Similar to Vm.runInThisContext but a method of a precompiled Script object. runInThisContext runs the code of script and returns the result. Running code does not have access to local scope, but does have access to the current global object.