Skip to content

Commit

Permalink
lib: replace String global with primordials
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
Sebastien-Ahkrin authored and BethGriggs committed Oct 13, 2020
1 parent ebf3900 commit 30c6b3e
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
ObjectAssign,
ObjectKeys,
ObjectSetPrototypeOf,
String,
Symbol
} = primordials;

Expand Down
1 change: 1 addition & 0 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
Map,
NumberIsNaN,
RegExpPrototypeTest,
String,
} = primordials;

const { Buffer } = require('buffer');
Expand Down
1 change: 1 addition & 0 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const {
PromiseResolve,
ReflectApply,
ReflectOwnKeys,
String,
Symbol,
SymbolFor,
SymbolAsyncIterator
Expand Down
1 change: 1 addition & 0 deletions lib/internal/assert/assertion_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
ObjectDefineProperty,
ObjectGetPrototypeOf,
ObjectKeys,
String,
} = primordials;

const { inspect } = require('internal/util/inspect');
Expand Down
1 change: 1 addition & 0 deletions lib/internal/bootstrap/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const {
ObjectPrototypeHasOwnProperty,
ReflectGet,
SafeSet,
String,
} = primordials;

// Set up process.moduleLoadList.
Expand Down
1 change: 1 addition & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
NumberIsInteger,
ObjectDefineProperty,
ObjectKeys,
String,
StringPrototypeStartsWith,
Symbol,
SymbolFor,
Expand Down
1 change: 1 addition & 0 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
NumberIsInteger,
Object,
ObjectDefineProperty,
String,
Symbol,
SymbolFor,
SymbolToStringTag,
Expand Down
1 change: 1 addition & 0 deletions lib/internal/http2/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
ObjectCreate,
ObjectKeys,
Set,
String,
Symbol,
} = primordials;

Expand Down
1 change: 1 addition & 0 deletions lib/internal/process/warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const {
ArrayIsArray,
Error,
String,
} = primordials;

const assert = require('internal/assert');
Expand Down
1 change: 1 addition & 0 deletions lib/internal/readline/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const {
String,
Symbol,
} = primordials;

Expand Down
1 change: 1 addition & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
ObjectKeys,
ReflectGetOwnPropertyDescriptor,
ReflectOwnKeys,
String,
Symbol,
SymbolIterator,
SymbolToStringTag,
Expand Down
1 change: 1 addition & 0 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const {
Set,
SetPrototype,
SetPrototypeValues,
String,
StringPrototypeValueOf,
SymbolPrototypeToString,
SymbolPrototypeValueOf,
Expand Down
1 change: 1 addition & 0 deletions lib/internal/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
NumberIsInteger,
NumberMAX_SAFE_INTEGER,
NumberMIN_SAFE_INTEGER,
String,
} = primordials;

const {
Expand Down
1 change: 1 addition & 0 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
ObjectEntries,
Promise,
PromiseResolve,
String,
Symbol,
SymbolFor,
} = primordials;
Expand Down
1 change: 1 addition & 0 deletions lib/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
MathAbs,
ObjectCreate,
ObjectKeys,
String,
} = primordials;

const { Buffer } = require('buffer');
Expand Down
18 changes: 14 additions & 4 deletions lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const {
ArrayIsArray,
ObjectDefineProperty,
ObjectFreeze,
StringFromCharCode,
StringPrototypeCharCodeAt,
StringPrototypeReplace,
StringPrototypeSplit,
} = primordials;

const {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lib/wasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
ArrayPrototypePush,
FunctionPrototypeBind,
ObjectEntries,
String,
Symbol,
} = primordials;

Expand Down

0 comments on commit 30c6b3e

Please sign in to comment.