From c7b492a4604f5f7131efec21f84b1cb3e8c25e12 Mon Sep 17 00:00:00 2001 From: Sebastien Ahkrin Date: Mon, 6 Jan 2020 03:26:38 +0100 Subject: [PATCH 1/5] lib: replace Float64Array global with primordials --- lib/.eslintrc.yaml | 2 ++ lib/internal/buffer.js | 1 + lib/internal/process/per_thread.js | 1 + lib/internal/util/inspect.js | 1 + lib/internal/worker.js | 1 + lib/os.js | 1 + 6 files changed, 7 insertions(+) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 97cc264c8ff804..afa71051799947 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -23,6 +23,8 @@ rules: message: "Use `const { Error } = primordials;` instead of the global." - name: Float32Array message: "Use `const { Float32Array } = primordials;` instead of the global." + - name: Float64Array + message: "Use `const { Float64Array } = primordials;` instead of the global." - name: Int16Array message: "Use `const { Int16Array } = primordials;` instead of the global." - name: JSON diff --git a/lib/internal/buffer.js b/lib/internal/buffer.js index f76f40830b4867..5b2a4a508d14e5 100644 --- a/lib/internal/buffer.js +++ b/lib/internal/buffer.js @@ -3,6 +3,7 @@ const { BigInt, Float32Array, + Float64Array, MathFloor, Number, } = primordials; diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 1107694d173570..1005d841a283f4 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -7,6 +7,7 @@ const { ArrayIsArray, BigUint64Array, + Float64Array, NumberMAX_SAFE_INTEGER, ObjectDefineProperties, ObjectDefineProperty, diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 102d6f0f153d6a..4b1ffa68891f95 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -12,6 +12,7 @@ const { DatePrototypeToString, ErrorPrototypeToString, Float32Array, + Float64Array, FunctionPrototypeCall, FunctionPrototypeToString, Int16Array, diff --git a/lib/internal/worker.js b/lib/internal/worker.js index a2450f95179336..c04484b3d8de3a 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -4,6 +4,7 @@ const { ArrayIsArray, + Float64Array, JSONStringify, MathMax, ObjectCreate, diff --git a/lib/os.js b/lib/os.js index 395a372a00f71f..dc0d08376f2da0 100644 --- a/lib/os.js +++ b/lib/os.js @@ -22,6 +22,7 @@ 'use strict'; const { + Float64Array, ObjectDefineProperties, SymbolToPrimitive, } = primordials; From 9f8afc9f01538e15efef5d306f6394979f4651b9 Mon Sep 17 00:00:00 2001 From: Sebastien Ahkrin Date: Mon, 6 Jan 2020 03:39:26 +0100 Subject: [PATCH 2/5] lib: replace Int32Array global with primordials --- lib/.eslintrc.yaml | 2 ++ lib/internal/util/inspect.js | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index afa71051799947..02d160d09386c9 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -27,6 +27,8 @@ rules: message: "Use `const { Float64Array } = primordials;` instead of the global." - name: Int16Array message: "Use `const { Int16Array } = primordials;` instead of the global." + - name: Int32Array + message: "Use `const { Int32Array } = primordials;` instead of the global." - name: JSON message: "Use `const { JSON } = primordials;` instead of the global." - name: Map diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 4b1ffa68891f95..a90e0e12112d03 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -16,6 +16,7 @@ const { FunctionPrototypeCall, FunctionPrototypeToString, Int16Array, + Int32Array, JSONStringify, Map, MapPrototype, From f52be60daf38c210b674ba340d89b118354dee40 Mon Sep 17 00:00:00 2001 From: Sebastien Ahkrin Date: Mon, 6 Jan 2020 03:42:18 +0100 Subject: [PATCH 3/5] lib: replace Int8Array global with primordials --- lib/.eslintrc.yaml | 2 ++ lib/internal/util/inspect.js | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 02d160d09386c9..02d70f83f9c62f 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -29,6 +29,8 @@ rules: message: "Use `const { Int16Array } = primordials;` instead of the global." - name: Int32Array message: "Use `const { Int32Array } = primordials;` instead of the global." + - name: Int8Array + message: "Use `const { Int8Array } = primordials;` instead of the global." - name: JSON message: "Use `const { JSON } = primordials;` instead of the global." - name: Map diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index a90e0e12112d03..a979539025373e 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -15,6 +15,7 @@ const { Float64Array, FunctionPrototypeCall, FunctionPrototypeToString, + Int8Array, Int16Array, Int32Array, JSONStringify, From 180af477574a259e4533de473d8b1a962e47bfd5 Mon Sep 17 00:00:00 2001 From: Sebastien Ahkrin Date: Mon, 6 Jan 2020 03:55:31 +0100 Subject: [PATCH 4/5] lib: replace String global with primordials --- lib/.eslintrc.yaml | 2 ++ lib/_http_client.js | 1 + lib/assert.js | 1 + lib/events.js | 1 + lib/internal/assert/assertion_error.js | 1 + lib/internal/bootstrap/loaders.js | 1 + lib/internal/errors.js | 1 + lib/internal/event_target.js | 1 + lib/internal/http2/util.js | 6 ++++-- lib/internal/process/warning.js | 1 + lib/internal/readline/utils.js | 1 + lib/internal/url.js | 1 + lib/internal/util/inspect.js | 1 + lib/internal/validators.js | 1 + lib/internal/worker.js | 1 + lib/querystring.js | 1 + lib/tls.js | 3 ++- lib/wasi.js | 1 + 18 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 02d70f83f9c62f..0f34afff0814a6 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -49,6 +49,8 @@ rules: message: "Use `const { RegExp } = primordials;` instead of the global." - name: Set message: "Use `const { Set } = primordials;` instead of the global." + - name: String + message: "Use `const { String } = primordials;` instead of the global." - name: Symbol message: "Use `const { Symbol } = primordials;` instead of the global." - name: Uint16Array diff --git a/lib/_http_client.js b/lib/_http_client.js index 30ab9016844a1d..0aae57aed4e3a5 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -29,6 +29,7 @@ const { ObjectAssign, ObjectKeys, ObjectSetPrototypeOf, + String, Symbol } = primordials; diff --git a/lib/assert.js b/lib/assert.js index 6ad672d698602d..08ef18240925ba 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -29,6 +29,7 @@ const { Map, NumberIsNaN, RegExpPrototypeTest, + String, } = primordials; const { Buffer } = require('buffer'); diff --git a/lib/events.js b/lib/events.js index c1343acbf31451..7d3ee54018d0cb 100644 --- a/lib/events.js +++ b/lib/events.js @@ -35,6 +35,7 @@ const { PromiseResolve, ReflectApply, ReflectOwnKeys, + String, Symbol, SymbolFor, SymbolAsyncIterator diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index 3c2150c69e4e09..c89219eef82224 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -7,6 +7,7 @@ const { ObjectDefineProperty, ObjectGetPrototypeOf, ObjectKeys, + String, } = primordials; const { inspect } = require('internal/util/inspect'); diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index c4ef1d12a2974c..127ef67c36eb64 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -52,6 +52,7 @@ const { ObjectPrototypeHasOwnProperty, ReflectGet, SafeSet, + String, } = primordials; // Set up process.moduleLoadList. diff --git a/lib/internal/errors.js b/lib/internal/errors.js index ff4cea13b61cae..314c06c7b78f03 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -21,6 +21,7 @@ const { NumberIsInteger, ObjectDefineProperty, ObjectKeys, + String, StringPrototypeStartsWith, Symbol, SymbolFor, diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 8f0657c8d5b193..afaadc564396ff 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -8,6 +8,7 @@ const { NumberIsInteger, Object, ObjectDefineProperty, + String, Symbol, SymbolFor, SymbolToStringTag, diff --git a/lib/internal/http2/util.js b/lib/internal/http2/util.js index 93994ca29ea0e5..b3fdf420c8c2b5 100644 --- a/lib/internal/http2/util.js +++ b/lib/internal/http2/util.js @@ -8,6 +8,8 @@ const { ObjectCreate, ObjectKeys, Set, + String, + StringFromCharCode, StringPrototypeToLowerCase, Symbol, } = primordials; @@ -459,8 +461,8 @@ const assertValidPseudoHeaderTrailer = hideStackFrames((key) => { }); const emptyArray = []; -const kNeverIndexFlag = String.fromCharCode(NGHTTP2_NV_FLAG_NO_INDEX); -const kNoHeaderFlags = String.fromCharCode(NGHTTP2_NV_FLAG_NONE); +const kNeverIndexFlag = StringFromCharCode(NGHTTP2_NV_FLAG_NO_INDEX); +const kNoHeaderFlags = StringFromCharCode(NGHTTP2_NV_FLAG_NONE); function mapToHeaders(map, assertValuePseudoHeader = assertValidPseudoHeader) { let ret = ''; diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index e2d41eac73bbf1..2822ef22f1f05a 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -3,6 +3,7 @@ const { ArrayIsArray, Error, + String, } = primordials; const assert = require('internal/assert'); diff --git a/lib/internal/readline/utils.js b/lib/internal/readline/utils.js index d75b64dd46beac..408d12d01e151d 100644 --- a/lib/internal/readline/utils.js +++ b/lib/internal/readline/utils.js @@ -1,6 +1,7 @@ 'use strict'; const { + String, Symbol, } = primordials; diff --git a/lib/internal/url.js b/lib/internal/url.js index f56e006e90a63c..3c464ffbd638f6 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -11,6 +11,7 @@ const { ObjectKeys, ReflectGetOwnPropertyDescriptor, ReflectOwnKeys, + String, Symbol, SymbolIterator, SymbolToStringTag, diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index a979539025373e..2a9bb18fdf6009 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -49,6 +49,7 @@ const { Set, SetPrototype, SetPrototypeValues, + String, StringPrototypeValueOf, SymbolPrototypeToString, SymbolPrototypeValueOf, diff --git a/lib/internal/validators.js b/lib/internal/validators.js index f9509a48827d76..2ef7d653d98fba 100644 --- a/lib/internal/validators.js +++ b/lib/internal/validators.js @@ -5,6 +5,7 @@ const { NumberIsInteger, NumberMAX_SAFE_INTEGER, NumberMIN_SAFE_INTEGER, + String, } = primordials; const { diff --git a/lib/internal/worker.js b/lib/internal/worker.js index c04484b3d8de3a..c89c8cd4e27b08 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -11,6 +11,7 @@ const { ObjectEntries, Promise, PromiseResolve, + String, Symbol, SymbolFor, } = primordials; diff --git a/lib/querystring.js b/lib/querystring.js index 4d196633dcf2c7..04a21e8d07f24f 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -29,6 +29,7 @@ const { MathAbs, ObjectCreate, ObjectKeys, + String, } = primordials; const { Buffer } = require('buffer'); diff --git a/lib/tls.js b/lib/tls.js index 2ccbe409c96c2d..b876884807767d 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -26,6 +26,7 @@ const { ArrayIsArray, ObjectDefineProperty, ObjectFreeze, + StringFromCharCode, } = primordials; const { @@ -140,7 +141,7 @@ function unfqdn(host) { function splitHost(host) { // String#toLowerCase() is locale-sensitive so we use // a conservative version that only lowercases A-Z. - const replacer = (c) => String.fromCharCode(32 + c.charCodeAt(0)); + const replacer = (c) => StringFromCharCode(32 + c.charCodeAt(0)); return unfqdn(host).replace(/[A-Z]/g, replacer).split('.'); } diff --git a/lib/wasi.js b/lib/wasi.js index a764a1745ab0a9..072f19be9235ae 100644 --- a/lib/wasi.js +++ b/lib/wasi.js @@ -4,6 +4,7 @@ const { ArrayPrototypePush, FunctionPrototypeBind, ObjectEntries, + String, Symbol, } = primordials; From 04bc26cd40a68d5951c6df4aff46c88b84399cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Fri, 2 Oct 2020 09:34:24 +0200 Subject: [PATCH 5/5] fixup! lib: replace String global with primordials --- lib/tls.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/tls.js b/lib/tls.js index b876884807767d..a46031ad7da90e 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -27,6 +27,9 @@ const { ObjectDefineProperty, ObjectFreeze, StringFromCharCode, + StringPrototypeCharCodeAt, + StringPrototypeReplace, + StringPrototypeSplit, } = primordials; const { @@ -138,11 +141,17 @@ function unfqdn(host) { return host.replace(/[.]$/, ''); } +// String#toLowerCase() is locale-sensitive so we use +// a conservative version that only lowercases A-Z. +function toLowerCase(c) { + return StringFromCharCode(32 + StringPrototypeCharCodeAt(c, 0)); +} + function splitHost(host) { - // String#toLowerCase() is locale-sensitive so we use - // a conservative version that only lowercases A-Z. - const replacer = (c) => StringFromCharCode(32 + c.charCodeAt(0)); - return unfqdn(host).replace(/[A-Z]/g, replacer).split('.'); + return StringPrototypeSplit( + StringPrototypeReplace(unfqdn(host), /[A-Z]/g, toLowerCase), + '.' + ); } function check(hostParts, pattern, wildcards) {