Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Node.js is Cancer

Name: Anonymous 2011-10-03 7:05

Name: Anonymous 2011-10-03 11:13

WEB2.0 SANDBOX TECHNOLOGY
vm.runInNewContext(code, [sandbox], [filename])

vm.runInNewContext compiles code to run in sandbox as if it were loaded from filename, then runs it and returns the result. Running code does not have access to local scope and the object sandbox will be used as the global object for code. sandbox and filename are optional.

Example: compile and execute code that increments a global variable and sets a new one. These globals are contained in the sandbox.

var util = require('util'),
    vm = require('vm'),
    sandbox = {
      animal: 'cat',
      count: 2
    };

vm.runInNewContext('count += 1; name = "kitty"', sandbox, 'myfile.vm');
console.log(util.inspect(sandbox));

// { animal: 'cat', count: 3, name: 'kitty' }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List