Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
Wrap filename with protocol
Browse files Browse the repository at this point in the history
This makes it easy to browser the files in devtools, see electron/electron#811.
  • Loading branch information
zcbenz committed Nov 14, 2014
1 parent d269503 commit 8c26bda
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/module.js
Expand Up @@ -27,6 +27,12 @@ var assert = require('assert').ok;
var fs = NativeModule.require('fs');


function wrapFilename(filename) {
if (!global.window || !global.window.location) return filename;
return global.window.location.origin + filename;
}


// If obj.hasOwnProperty has been overridden, then calling
// obj.hasOwnProperty(prop) will break.
// See: https://github.com/joyent/node/issues/1707
Expand Down Expand Up @@ -431,7 +437,7 @@ Module.prototype._compile = function(content, filename) {
sandbox.global = sandbox;
sandbox.root = root;

return runInNewContext(content, sandbox, { filename: filename });
return runInNewContext(content, sandbox, { filename: wrapFilename(filename) });
}

debug('load root module');
Expand All @@ -442,13 +448,13 @@ Module.prototype._compile = function(content, filename) {
global.__dirname = dirname;
global.module = self;

return runInThisContext(content, { filename: filename });
return runInThisContext(content, { filename: wrapFilename(filename) });
}

// create wrapper function
var wrapper = Module.wrap(content);

var compiledWrapper = runInThisContext(wrapper, { filename: filename });
var compiledWrapper = runInThisContext(wrapper, { filename: wrapFilename(filename) });
if (global.v8debug) {
if (!resolvedArgv) {
// we enter the repl if we're not given a filename argument.
Expand Down

0 comments on commit 8c26bda

Please sign in to comment.