|
@ -2,7 +2,7 @@ |
|
|
|
|
|
|
|
|
`Script` class compiles and runs JavaScript code. You can access this class with: |
|
|
`Script` class compiles and runs JavaScript code. You can access this class with: |
|
|
|
|
|
|
|
|
var Script = process.binding('evals').Script; |
|
|
var Script = require('javascript').Script; |
|
|
|
|
|
|
|
|
New JavaScript code can be compiled and run immediately or compiled, saved, and run later. |
|
|
New JavaScript code can be compiled and run immediately or compiled, saved, and run later. |
|
|
|
|
|
|
|
@ -16,7 +16,7 @@ Example of using `Script.runInThisContext` and `eval` to run the same code: |
|
|
|
|
|
|
|
|
var localVar = 123, |
|
|
var localVar = 123, |
|
|
usingscript, evaled, |
|
|
usingscript, evaled, |
|
|
Script = process.binding('evals').Script; |
|
|
Script = require('javascript').Script; |
|
|
|
|
|
|
|
|
usingscript = Script.runInThisContext('localVar = 1;', |
|
|
usingscript = Script.runInThisContext('localVar = 1;', |
|
|
'myfile.js'); |
|
|
'myfile.js'); |
|
@ -47,7 +47,7 @@ Example: compile and execute code that increments a global variable and sets a n |
|
|
These globals are contained in the sandbox. |
|
|
These globals are contained in the sandbox. |
|
|
|
|
|
|
|
|
var util = require('util'), |
|
|
var util = require('util'), |
|
|
Script = process.binding('evals').Script, |
|
|
Script = require('javascript').Script, |
|
|
sandbox = { |
|
|
sandbox = { |
|
|
animal: 'cat', |
|
|
animal: 'cat', |
|
|
count: 2 |
|
|
count: 2 |
|
@ -88,7 +88,7 @@ Running code does not have access to local scope, but does have access to the `g |
|
|
|
|
|
|
|
|
Example of using `script.runInThisContext` to compile code once and run it multiple times: |
|
|
Example of using `script.runInThisContext` to compile code once and run it multiple times: |
|
|
|
|
|
|
|
|
var Script = process.binding('evals').Script, |
|
|
var Script = require('javascript').Script, |
|
|
scriptObj, i; |
|
|
scriptObj, i; |
|
|
|
|
|
|
|
|
globalVar = 0; |
|
|
globalVar = 0; |
|
@ -114,7 +114,7 @@ Example: compile code that increments a global variable and sets one, then execu |
|
|
These globals are contained in the sandbox. |
|
|
These globals are contained in the sandbox. |
|
|
|
|
|
|
|
|
var util = require('util'), |
|
|
var util = require('util'), |
|
|
Script = process.binding('evals').Script, |
|
|
Script = require('javascript').Script, |
|
|
scriptObj, i, |
|
|
scriptObj, i, |
|
|
sandbox = { |
|
|
sandbox = { |
|
|
animal: 'cat', |
|
|
animal: 'cat', |
|
|