Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nodejs/node-v0.x-archive
base: 3602d4c23bd8
Choose a base ref
...
head repository: nodejs/node-v0.x-archive
compare: eef552774e1c
Choose a head ref
  • 2 commits
  • 28 files changed
  • 2 contributors

Commits on Aug 21, 2013

  1. 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]: #5323 (comment)
    [4]: https://github.com/kkoopa/contextify/blob/bf123f3ef960f0943d1e30bda02e3163a004e964/src/contextify.cc
    [5]: https://gist.github.com/domenic/6068120
    domenic authored and isaacs committed Aug 21, 2013
    Copy the full SHA
    7afdba6 View commit details
    Browse the repository at this point in the history

Commits on Aug 22, 2013

  1. vm: Put back display_errors flag

    This is an important part of the repl use-case.
    
    TODO: The arg parsing in vm.runIn*Context() is rather wonky.
    It would be good to move more of that into the Script class,
    and/or an options object.
    isaacs committed Aug 22, 2013
    Copy the full SHA
    eef5527 View commit details
    Browse the repository at this point in the history