summaryrefslogtreecommitdiff
path: root/lib/vm.js
diff options
context:
space:
mode:
authorDomenic Denicola <domenic@domenicdenicola.com>2013-08-24 15:45:02 -0400
committerBen Noordhuis <info@bnoordhuis.nl>2013-08-28 12:11:09 +0200
commit9c110d80276282c0f8c63bd4c6973f28e57c9eb5 (patch)
tree58660a14f29f29cb9c9852001d2b83147da6d477 /lib/vm.js
parenta3bf3d10ef4b373870c6bb475f8fd5b6ede953cc (diff)
downloadnode-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.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/vm.js b/lib/vm.js
index c71bb81add..8fee40a8f2 100644
--- a/lib/vm.js
+++ b/lib/vm.js
@@ -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;