summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSergey Golovin <golovim@gmail.com>2018-02-19 21:13:54 +0300
committerRuben Bridgewater <ruben@bridgewater.de>2018-02-22 15:15:43 +0000
commit070a82e82c917492bf306e546cef55ffb3ca8359 (patch)
treeac812a50bd1bab9a9e1d3c57ba8f571313ebde4f /lib
parent13cb056e4cfce7419148eb089205735fb12bcd9f (diff)
downloadandroid-node-v8-070a82e82c917492bf306e546cef55ffb3ca8359.tar.gz
android-node-v8-070a82e82c917492bf306e546cef55ffb3ca8359.tar.bz2
android-node-v8-070a82e82c917492bf306e546cef55ffb3ca8359.zip
module: replace "magic" numbers by constants
- add new constants - replace numbers by constants PR-URL: https://github.com/nodejs/node/pull/18869 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matheus Marchini <matheus@sthima.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/constants.js4
-rw-r--r--lib/internal/module.js13
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/internal/constants.js b/lib/internal/constants.js
index d059dbc7ef..93bf926a84 100644
--- a/lib/internal/constants.js
+++ b/lib/internal/constants.js
@@ -14,6 +14,10 @@ module.exports = {
CHAR_COLON: 58, /* : */
CHAR_QUESTION_MARK: 63, /* ? */
CHAR_UNDERSCORE: 95, /* _ */
+ CHAR_LINE_FEED: 10, /* \n */
+ CHAR_CARRIAGE_RETURN: 13, /* \r */
+ CHAR_EXCLAMATION_MARK: 33, /* ! */
+ CHAR_HASH: 35, /* # */
// Digits
CHAR_0: 48, /* 0 */
diff --git a/lib/internal/module.js b/lib/internal/module.js
index c3dede40fa..6e2fb15268 100644
--- a/lib/internal/module.js
+++ b/lib/internal/module.js
@@ -2,6 +2,13 @@
const errors = require('internal/errors');
+const {
+ CHAR_LINE_FEED,
+ CHAR_CARRIAGE_RETURN,
+ CHAR_EXCLAMATION_MARK,
+ CHAR_HASH,
+} = require('internal/constants');
+
// Invoke with makeRequireFunction(module) where |module| is the Module object
// to use as the context for the require() function.
function makeRequireFunction(mod) {
@@ -65,8 +72,8 @@ function stripShebang(content) {
// Remove shebang
var contLen = content.length;
if (contLen >= 2) {
- if (content.charCodeAt(0) === 35/*#*/ &&
- content.charCodeAt(1) === 33/*!*/) {
+ if (content.charCodeAt(0) === CHAR_HASH &&
+ content.charCodeAt(1) === CHAR_EXCLAMATION_MARK) {
if (contLen === 2) {
// Exact match
content = '';
@@ -75,7 +82,7 @@ function stripShebang(content) {
var i = 2;
for (; i < contLen; ++i) {
var code = content.charCodeAt(i);
- if (code === 10/*\n*/ || code === 13/*\r*/)
+ if (code === CHAR_LINE_FEED || code === CHAR_CARRIAGE_RETURN)
break;
}
if (i === contLen)