diff options
author | Domenic Denicola <domenic@domenicdenicola.com> | 2013-08-24 15:45:02 -0400 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-08-28 12:11:09 +0200 |
commit | 9c110d80276282c0f8c63bd4c6973f28e57c9eb5 (patch) | |
tree | 58660a14f29f29cb9c9852001d2b83147da6d477 /lib/vm.js | |
parent | a3bf3d10ef4b373870c6bb475f8fd5b6ede953cc (diff) | |
download | node-new-9c110d80276282c0f8c63bd4c6973f28e57c9eb5.tar.gz |
vm: add isContext; prevent double-contextifying
Previously, calling `vm.createContext(o)` repeatedly on the same `o`
would cause new C++ `ContextifyContext`s to be created and stored on
`o`, while the previous resident went off into leaked-memory limbo.
Now, repeatedly trying to contextify a sandbox will do nothing after
the first time.
To detect this, an independently-useful `vm.isContext(sandbox)` export
was added.
Diffstat (limited to 'lib/vm.js')
-rw-r--r-- | lib/vm.js | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -28,6 +28,7 @@ var util = require('util'); // - runInThisContext() // - runInContext(sandbox, [timeout]) // - makeContext(sandbox) +// - isContext(sandbox) // From this we build the entire documented API. Script.prototype.runInNewContext = function(initSandbox, timeout, disp) { @@ -44,10 +45,11 @@ exports.createScript = function(code, filename, disp) { exports.createContext = function(initSandbox) { if (util.isUndefined(initSandbox)) { initSandbox = {}; + } else if (binding.isContext(initSandbox)) { + return initSandbox; } binding.makeContext(initSandbox); - return initSandbox; }; @@ -65,3 +67,5 @@ exports.runInThisContext = function(code, filename, timeout, disp) { var script = exports.createScript(code, filename, disp); return script.runInThisContext(timeout, disp); }; + +exports.isContext = binding.isContext; |