Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken links generated from Node modules in DevTools #4

Open
wants to merge 1 commit into
base: nw13
Choose a base branch
from
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