Browse Source

Use require('javascript') instead of process.binding('evals')

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
d787a444c5
  1. 10
      doc/api/script.markdown
  2. 3
      lib/javascript.js
  3. 2
      test/simple/test-querystring.js
  4. 2
      test/simple/test-script-context.js
  5. 2
      test/simple/test-script-new.js
  6. 2
      test/simple/test-script-static-context.js
  7. 2
      test/simple/test-script-static-new.js
  8. 2
      test/simple/test-script-static-this.js
  9. 2
      test/simple/test-script-this.js

10
doc/api/script.markdown

@ -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',

3
lib/javascript.js

@ -0,0 +1,3 @@
var binding = process.binding('evals');
exports.Script = binding.Script;

2
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 foreignObject = Script.runInContext('({"foo": ["bar", "baz"]})', Script.createContext());
var qsNoMungeTestCases = [ var qsNoMungeTestCases = [

2
test/simple/test-script-context.js

@ -1,7 +1,7 @@
common = require("../common"); common = require("../common");
assert = common.assert assert = common.assert
var Script = process.binding('evals').Script; var Script = require('javascript').Script;
var script = new Script('"passed";'); var script = new Script('"passed";');
common.debug('run in a new empty context'); common.debug('run in a new empty context');

2
test/simple/test-script-new.js

@ -1,7 +1,7 @@
common = require("../common"); common = require("../common");
assert = common.assert assert = common.assert
var Script = process.binding('evals').Script; var Script = require('javascript').Script;
common.debug('run a string'); common.debug('run a string');
var script = new Script('"passed";'); var script = new Script('"passed";');
common.debug('script created'); common.debug('script created');

2
test/simple/test-script-static-context.js

@ -1,7 +1,7 @@
common = require("../common"); common = require("../common");
assert = common.assert assert = common.assert
var Script = process.binding('evals').Script; var Script = require('javascript').Script;
common.debug('run in a new empty context'); common.debug('run in a new empty context');
var context = Script.createContext(); var context = Script.createContext();

2
test/simple/test-script-static-new.js

@ -1,7 +1,7 @@
common = require("../common"); common = require("../common");
assert = common.assert assert = common.assert
var Script = process.binding('evals').Script; var Script = require('javascript').Script;
common.debug('run a string'); common.debug('run a string');
var result = Script.runInNewContext('"passed";'); var result = Script.runInNewContext('"passed";');

2
test/simple/test-script-static-this.js

@ -1,7 +1,7 @@
common = require("../common"); common = require("../common");
assert = common.assert assert = common.assert
var Script = process.binding('evals').Script; var Script = require('javascript').Script;
common.debug('run a string'); common.debug('run a string');
var result = Script.runInThisContext('"passed";'); var result = Script.runInThisContext('"passed";');

2
test/simple/test-script-this.js

@ -1,7 +1,7 @@
common = require("../common"); common = require("../common");
assert = common.assert assert = common.assert
var Script = process.binding('evals').Script; var Script = require('javascript').Script;
common.debug('run a string'); common.debug('run a string');
var script = new Script('"passed";'); var script = new Script('"passed";');

Loading…
Cancel
Save