summaryrefslogtreecommitdiff
path: root/node.gyp
diff options
context:
space:
mode:
authorDomenic Denicola <domenic@domenicdenicola.com>2013-07-27 00:34:12 -0400
committerisaacs <i@izs.me>2013-08-21 15:52:23 -0700
commit7afdba6e0bc3b69c2bf5fdbd59f938ac8f7a64c5 (patch)
treec1a5a28e08784720c7de7cb98cf73f0bb3748db3 /node.gyp
parent3602d4c23bd8beccd925161adf5459068aec23e3 (diff)
downloadnodejs-7afdba6e0bc3b69c2bf5fdbd59f938ac8f7a64c5.tar.gz
nodejs-7afdba6e0bc3b69c2bf5fdbd59f938ac8f7a64c5.tar.bz2
nodejs-7afdba6e0bc3b69c2bf5fdbd59f938ac8f7a64c5.zip
vm, core, module: re-do vm to fix known issues
As documented in #3042 and in [1], the existing vm implementation has many problems. All of these are solved by @brianmcd's [contextify][2] package. This commit uses contextify as a conceptual base and its code core to overhaul the vm module and fix its many edge cases and caveats. Functionally, this fixes #3042. In particular: - A context is now indistinguishable from the object it is based on (the "sandbox"). A context is simply a sandbox that has been marked by the vm module, via `vm.createContext`, with special internal information that allows scripts to be run inside of it. - Consequently, items added to the context from anywhere are immediately visible to all code that can access that context, both inside and outside the virtual machine. This commit also smooths over the API very slightly: - Parameter defaults are now uniformly triggered via `undefined`, per ES6 semantics and previous discussion at [3]. - Several undocumented and problematic features have been removed, e.g. the conflation of `vm.Script` with `vm` itself, and the fact that `Script` instances also had all static `vm` methods. The API is now exactly as documented (although arguably the existence of the `vm.Script` export is not yet documented, just the `Script` class itself). In terms of implementation, this replaces node_script.cc with node_contextify.cc, which is derived originally from [4] (see [5]) but has since undergone extensive modifications and iterations to expose the most useful C++ API and use the coding conventions and utilities of Node core. The bindings exposed by `process.binding('contextify')` (node_contextify.cc) replace those formerly exposed by `process.binding('evals')` (node_script.cc). They are: - ContextifyScript(code, [filename]), with methods: - runInThisContext() - runInContext(sandbox, [timeout]) - makeContext(sandbox) From this, the vm.js file builds the entire documented vm module API. node.js and module.js were modified to use this new native binding, or the vm module itself where possible. This introduces an extra line or two into the stack traces of module compilation (and thus into most stack traces), explaining the changed tests. The tests were also updated slightly, with all vm-related simple tests consolidated as test/simple/test-vm-* (some of them were formerly test/simple/test-script-*). At the same time they switched from `common.debug` to `console.error` and were updated to use `assert.throws` instead of rolling their own error-testing methods. New tests were also added, of course, demonstrating the new capabilities and fixes. [1]: http://nodejs.org/docs/v0.10.16/api/vm.html#vm_caveats [2]: https://github.com/brianmcd/contextify [3]: https://github.com/joyent/node/issues/5323#issuecomment-20250726 [4]: https://github.com/kkoopa/contextify/blob/bf123f3ef960f0943d1e30bda02e3163a004e964/src/contextify.cc [5]: https://gist.github.com/domenic/6068120
Diffstat (limited to 'node.gyp')
-rw-r--r--node.gyp4
1 files changed, 2 insertions, 2 deletions
diff --git a/node.gyp b/node.gyp
index d6aefae26..f42ba46e6 100644
--- a/node.gyp
+++ b/node.gyp
@@ -94,13 +94,13 @@
'src/node.cc',
'src/node_buffer.cc',
'src/node_constants.cc',
+ 'src/node_contextify.cc',
'src/node_extensions.cc',
'src/node_file.cc',
'src/node_http_parser.cc',
'src/node_javascript.cc',
'src/node_main.cc',
'src/node_os.cc',
- 'src/node_script.cc',
'src/node_stat_watcher.cc',
'src/node_watchdog.cc',
'src/node_zlib.cc',
@@ -120,13 +120,13 @@
'src/node.h',
'src/node_buffer.h',
'src/node_constants.h',
+ 'src/node_contextify.h',
'src/node_extensions.h',
'src/node_file.h',
'src/node_http_parser.h',
'src/node_javascript.h',
'src/node_os.h',
'src/node_root_certs.h',
- 'src/node_script.h',
'src/node_version.h',
'src/node_watchdog.h',
'src/node_wrap.h',