From 8c26bda40f090fa37a3249097853b22abef4f158 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 14 Nov 2014 17:16:44 +0800 Subject: [PATCH] Wrap filename with protocol This makes it easy to browser the files in devtools, see atom/atom-shell#811. --- lib/module.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/module.js b/lib/module.js index be12a76ea9..9646555986 100644 --- a/lib/module.js +++ b/lib/module.js @@ -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 @@ -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'); @@ -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.