From d787a444c5f54d468703b1d316e4e22a59ea7033 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 13 Nov 2010 15:18:10 -0800 Subject: [PATCH] Use require('javascript') instead of process.binding('evals') --- doc/api/script.markdown | 10 +++++----- lib/javascript.js | 3 +++ test/simple/test-querystring.js | 2 +- test/simple/test-script-context.js | 2 +- test/simple/test-script-new.js | 2 +- test/simple/test-script-static-context.js | 2 +- test/simple/test-script-static-new.js | 2 +- test/simple/test-script-static-this.js | 2 +- test/simple/test-script-this.js | 2 +- 9 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 lib/javascript.js diff --git a/doc/api/script.markdown b/doc/api/script.markdown index a0983fa8e5..7f87e5568e 100644 --- a/doc/api/script.markdown +++ b/doc/api/script.markdown @@ -2,7 +2,7 @@ `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. @@ -16,7 +16,7 @@ Example of using `Script.runInThisContext` and `eval` to run the same code: var localVar = 123, usingscript, evaled, - Script = process.binding('evals').Script; + Script = require('javascript').Script; usingscript = Script.runInThisContext('localVar = 1;', '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. var util = require('util'), - Script = process.binding('evals').Script, + Script = require('javascript').Script, sandbox = { animal: 'cat', 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: - var Script = process.binding('evals').Script, + var Script = require('javascript').Script, scriptObj, i; 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. var util = require('util'), - Script = process.binding('evals').Script, + Script = require('javascript').Script, scriptObj, i, sandbox = { animal: 'cat', diff --git a/lib/javascript.js b/lib/javascript.js new file mode 100644 index 0000000000..9d5d9845aa --- /dev/null +++ b/lib/javascript.js @@ -0,0 +1,3 @@ +var binding = process.binding('evals'); + +exports.Script = binding.Script; diff --git a/test/simple/test-querystring.js b/test/simple/test-querystring.js index 680f828c64..27fe388edc 100644 --- a/test/simple/test-querystring.js +++ b/test/simple/test-querystring.js @@ -55,7 +55,7 @@ var qsWeirdObjects = [ ]; } -var Script = process.binding('evals').Script; +var Script = require('javascript').Script; var foreignObject = Script.runInContext('({"foo": ["bar", "baz"]})', Script.createContext()); var qsNoMungeTestCases = [ diff --git a/test/simple/test-script-context.js b/test/simple/test-script-context.js index 40a46c7009..610ceaf165 100644 --- a/test/simple/test-script-context.js +++ b/test/simple/test-script-context.js @@ -1,7 +1,7 @@ common = require("../common"); assert = common.assert -var Script = process.binding('evals').Script; +var Script = require('javascript').Script; var script = new Script('"passed";'); common.debug('run in a new empty context'); diff --git a/test/simple/test-script-new.js b/test/simple/test-script-new.js index f622aa5039..ff5ae3ce02 100644 --- a/test/simple/test-script-new.js +++ b/test/simple/test-script-new.js @@ -1,7 +1,7 @@ common = require("../common"); assert = common.assert -var Script = process.binding('evals').Script; +var Script = require('javascript').Script; common.debug('run a string'); var script = new Script('"passed";'); common.debug('script created'); diff --git a/test/simple/test-script-static-context.js b/test/simple/test-script-static-context.js index 90df3c2df6..a8c106e4f3 100644 --- a/test/simple/test-script-static-context.js +++ b/test/simple/test-script-static-context.js @@ -1,7 +1,7 @@ common = require("../common"); assert = common.assert -var Script = process.binding('evals').Script; +var Script = require('javascript').Script; common.debug('run in a new empty context'); var context = Script.createContext(); diff --git a/test/simple/test-script-static-new.js b/test/simple/test-script-static-new.js index 0046f04796..a8f12090a2 100644 --- a/test/simple/test-script-static-new.js +++ b/test/simple/test-script-static-new.js @@ -1,7 +1,7 @@ common = require("../common"); assert = common.assert -var Script = process.binding('evals').Script; +var Script = require('javascript').Script; common.debug('run a string'); var result = Script.runInNewContext('"passed";'); diff --git a/test/simple/test-script-static-this.js b/test/simple/test-script-static-this.js index ed1a631aef..cd48b709e6 100644 --- a/test/simple/test-script-static-this.js +++ b/test/simple/test-script-static-this.js @@ -1,7 +1,7 @@ common = require("../common"); assert = common.assert -var Script = process.binding('evals').Script; +var Script = require('javascript').Script; common.debug('run a string'); var result = Script.runInThisContext('"passed";'); diff --git a/test/simple/test-script-this.js b/test/simple/test-script-this.js index 0cc8ce9314..2e071a912d 100644 --- a/test/simple/test-script-this.js +++ b/test/simple/test-script-this.js @@ -1,7 +1,7 @@ common = require("../common"); assert = common.assert -var Script = process.binding('evals').Script; +var Script = require('javascript').Script; common.debug('run a string'); var script = new Script('"passed";');