summaryrefslogtreecommitdiff
path: root/lib/module.js
diff options
context:
space:
mode:
authorSebastian Van Sande <sebastian@vansande.org>2017-04-04 11:58:15 +0200
committerAnna Henningsen <anna@addaleax.net>2017-04-19 19:56:18 +0200
commitf97156623a140c3bbeee91a038bb727f39fc5948 (patch)
tree5a5649c0964a4e7b51ccf97668fa7e01ad639a0b /lib/module.js
parenta2843f2cf9556557da93dcc2c81b072dfe1c6759 (diff)
downloadandroid-node-v8-f97156623a140c3bbeee91a038bb727f39fc5948.tar.gz
android-node-v8-f97156623a140c3bbeee91a038bb727f39fc5948.tar.bz2
android-node-v8-f97156623a140c3bbeee91a038bb727f39fc5948.zip
module: standardize strip shebang behaviour
When loading a module, Node needs to finds the end of a shebang comment by searching for a \r or \n character. This behaviour is now standardized into a dedicated internal module function Refs: https://github.com/nodejs/node/issues/12180 PR-URL: https://github.com/nodejs/node/pull/12202 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/module.js')
-rw-r--r--lib/module.js29
1 files changed, 2 insertions, 27 deletions
diff --git a/lib/module.js b/lib/module.js
index fe83cd0ecb..c4576a4bbd 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -537,33 +537,8 @@ var resolvedArgv;
// the file.
// Returns exception, if any.
Module.prototype._compile = function(content, filename) {
- // Remove shebang
- var contLen = content.length;
- if (contLen >= 2) {
- if (content.charCodeAt(0) === 35/*#*/ &&
- content.charCodeAt(1) === 33/*!*/) {
- if (contLen === 2) {
- // Exact match
- content = '';
- } else {
- // Find end of shebang line and slice it off
- var i = 2;
- for (; i < contLen; ++i) {
- var code = content.charCodeAt(i);
- if (code === 10/*\n*/ || code === 13/*\r*/)
- break;
- }
- if (i === contLen)
- content = '';
- else {
- // Note that this actually includes the newline character(s) in the
- // new output. This duplicates the behavior of the regular expression
- // that was previously used to replace the shebang line
- content = content.slice(i);
- }
- }
- }
- }
+
+ content = internalModule.stripShebang(content);
// create wrapper function
var wrapper = Module.wrap(content);