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."
- 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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 = '';

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,6 +26,10 @@ const {
ArrayIsArray,
ObjectDefineProperty,
ObjectFreeze,
StringFromCharCode,
StringPrototypeCharCodeAt,
StringPrototypeReplace,
StringPrototypeSplit,
} = primordials;
const {
@ -137,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) => String.fromCharCode(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) {

View File

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