lib: replace String global with primordials

PR-URL: https://github.com/nodejs/node/pull/35397
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Pranshu Srivastava <rexagod@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org>
This commit is contained in:
Sebastien Ahkrin 2020-01-06 03:55:31 +01:00 committed by Michaël Zasso
parent 693cc2c1c3
commit b79829c5f5
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
18 changed files with 35 additions and 6 deletions

View File

@ -49,6 +49,8 @@ rules:
message: "Use `const { RegExp } = primordials;` instead of the global." message: "Use `const { RegExp } = primordials;` instead of the global."
- name: Set - name: Set
message: "Use `const { Set } = primordials;` instead of the global." message: "Use `const { Set } = primordials;` instead of the global."
- name: String
message: "Use `const { String } = primordials;` instead of the global."
- name: Symbol - name: Symbol
message: "Use `const { Symbol } = primordials;` instead of the global." message: "Use `const { Symbol } = primordials;` instead of the global."
- name: Uint16Array - name: Uint16Array

View File

@ -29,6 +29,7 @@ const {
ObjectAssign, ObjectAssign,
ObjectKeys, ObjectKeys,
ObjectSetPrototypeOf, ObjectSetPrototypeOf,
String,
Symbol Symbol
} = primordials; } = primordials;

View File

@ -29,6 +29,7 @@ const {
Map, Map,
NumberIsNaN, NumberIsNaN,
RegExpPrototypeTest, RegExpPrototypeTest,
String,
} = primordials; } = primordials;
const { Buffer } = require('buffer'); const { Buffer } = require('buffer');

View File

@ -35,6 +35,7 @@ const {
PromiseResolve, PromiseResolve,
ReflectApply, ReflectApply,
ReflectOwnKeys, ReflectOwnKeys,
String,
Symbol, Symbol,
SymbolFor, SymbolFor,
SymbolAsyncIterator SymbolAsyncIterator

View File

@ -7,6 +7,7 @@ const {
ObjectDefineProperty, ObjectDefineProperty,
ObjectGetPrototypeOf, ObjectGetPrototypeOf,
ObjectKeys, ObjectKeys,
String,
} = primordials; } = primordials;
const { inspect } = require('internal/util/inspect'); const { inspect } = require('internal/util/inspect');

View File

@ -52,6 +52,7 @@ const {
ObjectPrototypeHasOwnProperty, ObjectPrototypeHasOwnProperty,
ReflectGet, ReflectGet,
SafeSet, SafeSet,
String,
} = primordials; } = primordials;
// Set up process.moduleLoadList. // Set up process.moduleLoadList.

View File

@ -21,6 +21,7 @@ const {
NumberIsInteger, NumberIsInteger,
ObjectDefineProperty, ObjectDefineProperty,
ObjectKeys, ObjectKeys,
String,
StringPrototypeStartsWith, StringPrototypeStartsWith,
Symbol, Symbol,
SymbolFor, SymbolFor,

View File

@ -9,6 +9,7 @@ const {
ObjectAssign, ObjectAssign,
ObjectDefineProperties, ObjectDefineProperties,
ObjectDefineProperty, ObjectDefineProperty,
String,
Symbol, Symbol,
SymbolFor, SymbolFor,
SymbolToStringTag, SymbolToStringTag,

View File

@ -8,6 +8,8 @@ const {
ObjectCreate, ObjectCreate,
ObjectKeys, ObjectKeys,
Set, Set,
String,
StringFromCharCode,
StringPrototypeToLowerCase, StringPrototypeToLowerCase,
Symbol, Symbol,
} = primordials; } = primordials;
@ -459,8 +461,8 @@ const assertValidPseudoHeaderTrailer = hideStackFrames((key) => {
}); });
const emptyArray = []; const emptyArray = [];
const kNeverIndexFlag = String.fromCharCode(NGHTTP2_NV_FLAG_NO_INDEX); const kNeverIndexFlag = StringFromCharCode(NGHTTP2_NV_FLAG_NO_INDEX);
const kNoHeaderFlags = String.fromCharCode(NGHTTP2_NV_FLAG_NONE); const kNoHeaderFlags = StringFromCharCode(NGHTTP2_NV_FLAG_NONE);
function mapToHeaders(map, function mapToHeaders(map,
assertValuePseudoHeader = assertValidPseudoHeader) { assertValuePseudoHeader = assertValidPseudoHeader) {
let ret = ''; let ret = '';

View File

@ -3,6 +3,7 @@
const { const {
ArrayIsArray, ArrayIsArray,
Error, Error,
String,
} = primordials; } = primordials;
const assert = require('internal/assert'); const assert = require('internal/assert');

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const { const {
String,
Symbol, Symbol,
} = primordials; } = primordials;

View File

@ -11,6 +11,7 @@ const {
ObjectKeys, ObjectKeys,
ReflectGetOwnPropertyDescriptor, ReflectGetOwnPropertyDescriptor,
ReflectOwnKeys, ReflectOwnKeys,
String,
Symbol, Symbol,
SymbolIterator, SymbolIterator,
SymbolToStringTag, SymbolToStringTag,

View File

@ -49,6 +49,7 @@ const {
Set, Set,
SetPrototype, SetPrototype,
SetPrototypeValues, SetPrototypeValues,
String,
StringPrototypeValueOf, StringPrototypeValueOf,
SymbolPrototypeToString, SymbolPrototypeToString,
SymbolPrototypeValueOf, SymbolPrototypeValueOf,

View File

@ -5,6 +5,7 @@ const {
NumberIsInteger, NumberIsInteger,
NumberMAX_SAFE_INTEGER, NumberMAX_SAFE_INTEGER,
NumberMIN_SAFE_INTEGER, NumberMIN_SAFE_INTEGER,
String,
} = primordials; } = primordials;
const { const {

View File

@ -11,6 +11,7 @@ const {
ObjectEntries, ObjectEntries,
Promise, Promise,
PromiseResolve, PromiseResolve,
String,
Symbol, Symbol,
SymbolFor, SymbolFor,
} = primordials; } = primordials;

View File

@ -29,6 +29,7 @@ const {
MathAbs, MathAbs,
ObjectCreate, ObjectCreate,
ObjectKeys, ObjectKeys,
String,
} = primordials; } = primordials;
const { Buffer } = require('buffer'); const { Buffer } = require('buffer');

View File

@ -26,6 +26,10 @@ const {
ArrayIsArray, ArrayIsArray,
ObjectDefineProperty, ObjectDefineProperty,
ObjectFreeze, ObjectFreeze,
StringFromCharCode,
StringPrototypeCharCodeAt,
StringPrototypeReplace,
StringPrototypeSplit,
} = primordials; } = primordials;
const { const {
@ -137,11 +141,17 @@ function unfqdn(host) {
return host.replace(/[.]$/, ''); return host.replace(/[.]$/, '');
} }
function splitHost(host) {
// String#toLowerCase() is locale-sensitive so we use // String#toLowerCase() is locale-sensitive so we use
// a conservative version that only lowercases A-Z. // a conservative version that only lowercases A-Z.
const replacer = (c) => String.fromCharCode(32 + c.charCodeAt(0)); function toLowerCase(c) {
return unfqdn(host).replace(/[A-Z]/g, replacer).split('.'); return StringFromCharCode(32 + StringPrototypeCharCodeAt(c, 0));
}
function splitHost(host) {
return StringPrototypeSplit(
StringPrototypeReplace(unfqdn(host), /[A-Z]/g, toLowerCase),
'.'
);
} }
function check(hostParts, pattern, wildcards) { function check(hostParts, pattern, wildcards) {

View File

@ -4,6 +4,7 @@ const {
ArrayPrototypePush, ArrayPrototypePush,
FunctionPrototypeBind, FunctionPrototypeBind,
ObjectEntries, ObjectEntries,
String,
Symbol, Symbol,
} = primordials; } = primordials;