Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/vm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
'use strict';

const binding = process.binding('contextify');
const Script = binding.ContextifyScript;
const WeakScript = binding.ContextifyScript;

// Hold compiled script here to survival from GC for Node modules.
// Otherwise the links from console will be invalid shortly.
// See https://github.com/nwjs/nw.js/issues/4269
const compiledScripts = new Set();

function Script(code, options) {
var script = new WeakScript(code, options);
compiledScripts.add(script);
return script;
}

// The binding provides a few useful primitives:
// - ContextifyScript(code, { filename = "evalmachine.anonymous",
Expand All @@ -13,7 +24,7 @@ const Script = binding.ContextifyScript;
// - isContext(sandbox)
// From this we build the entire documented API.

Script.prototype.runInNewContext = function(sandbox, options) {
WeakScript.prototype.runInNewContext = function(sandbox, options) {
var context = exports.createContext(sandbox);
return this.runInContext(context, options);
};
Expand Down