Skip to content

Commit 30c6b3e

Browse files
Sebastien-AhkrinBethGriggs
authored andcommitted
lib: replace String global with primordials
PR-URL: #35397 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Pranshu Srivastava <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]>
1 parent ebf3900 commit 30c6b3e

18 files changed

+32
-4
lines changed

lib/.eslintrc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ rules:
4949
message: "Use `const { RegExp } = primordials;` instead of the global."
5050
- name: Set
5151
message: "Use `const { Set } = primordials;` instead of the global."
52+
- name: String
53+
message: "Use `const { String } = primordials;` instead of the global."
5254
- name: Symbol
5355
message: "Use `const { Symbol } = primordials;` instead of the global."
5456
- name: Uint16Array

lib/_http_client.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
ObjectAssign,
3030
ObjectKeys,
3131
ObjectSetPrototypeOf,
32+
String,
3233
Symbol
3334
} = primordials;
3435

lib/assert.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
Map,
3030
NumberIsNaN,
3131
RegExpPrototypeTest,
32+
String,
3233
} = primordials;
3334

3435
const { Buffer } = require('buffer');

lib/events.js

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const {
3535
PromiseResolve,
3636
ReflectApply,
3737
ReflectOwnKeys,
38+
String,
3839
Symbol,
3940
SymbolFor,
4041
SymbolAsyncIterator

lib/internal/assert/assertion_error.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
ObjectDefineProperty,
88
ObjectGetPrototypeOf,
99
ObjectKeys,
10+
String,
1011
} = primordials;
1112

1213
const { inspect } = require('internal/util/inspect');

lib/internal/bootstrap/loaders.js

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const {
5252
ObjectPrototypeHasOwnProperty,
5353
ReflectGet,
5454
SafeSet,
55+
String,
5556
} = primordials;
5657

5758
// Set up process.moduleLoadList.

lib/internal/errors.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const {
2121
NumberIsInteger,
2222
ObjectDefineProperty,
2323
ObjectKeys,
24+
String,
2425
StringPrototypeStartsWith,
2526
Symbol,
2627
SymbolFor,

lib/internal/event_target.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
NumberIsInteger,
99
Object,
1010
ObjectDefineProperty,
11+
String,
1112
Symbol,
1213
SymbolFor,
1314
SymbolToStringTag,

lib/internal/http2/util.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
ObjectCreate,
99
ObjectKeys,
1010
Set,
11+
String,
1112
Symbol,
1213
} = primordials;
1314

lib/internal/process/warning.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const {
44
ArrayIsArray,
55
Error,
6+
String,
67
} = primordials;
78

89
const assert = require('internal/assert');

lib/internal/readline/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {
4+
String,
45
Symbol,
56
} = primordials;
67

lib/internal/url.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
ObjectKeys,
1212
ReflectGetOwnPropertyDescriptor,
1313
ReflectOwnKeys,
14+
String,
1415
Symbol,
1516
SymbolIterator,
1617
SymbolToStringTag,

lib/internal/util/inspect.js

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const {
4949
Set,
5050
SetPrototype,
5151
SetPrototypeValues,
52+
String,
5253
StringPrototypeValueOf,
5354
SymbolPrototypeToString,
5455
SymbolPrototypeValueOf,

lib/internal/validators.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
NumberIsInteger,
66
NumberMAX_SAFE_INTEGER,
77
NumberMIN_SAFE_INTEGER,
8+
String,
89
} = primordials;
910

1011
const {

lib/internal/worker.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
ObjectEntries,
1212
Promise,
1313
PromiseResolve,
14+
String,
1415
Symbol,
1516
SymbolFor,
1617
} = primordials;

lib/querystring.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
MathAbs,
3030
ObjectCreate,
3131
ObjectKeys,
32+
String,
3233
} = primordials;
3334

3435
const { Buffer } = require('buffer');

lib/tls.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const {
2626
ArrayIsArray,
2727
ObjectDefineProperty,
2828
ObjectFreeze,
29+
StringFromCharCode,
30+
StringPrototypeCharCodeAt,
31+
StringPrototypeReplace,
32+
StringPrototypeSplit,
2933
} = primordials;
3034

3135
const {
@@ -137,11 +141,17 @@ function unfqdn(host) {
137141
return host.replace(/[.]$/, '');
138142
}
139143

144+
// String#toLowerCase() is locale-sensitive so we use
145+
// a conservative version that only lowercases A-Z.
146+
function toLowerCase(c) {
147+
return StringFromCharCode(32 + StringPrototypeCharCodeAt(c, 0));
148+
}
149+
140150
function splitHost(host) {
141-
// String#toLowerCase() is locale-sensitive so we use
142-
// a conservative version that only lowercases A-Z.
143-
const replacer = (c) => String.fromCharCode(32 + c.charCodeAt(0));
144-
return unfqdn(host).replace(/[A-Z]/g, replacer).split('.');
151+
return StringPrototypeSplit(
152+
StringPrototypeReplace(unfqdn(host), /[A-Z]/g, toLowerCase),
153+
'.'
154+
);
145155
}
146156

147157
function check(hostParts, pattern, wildcards) {

lib/wasi.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
ArrayPrototypePush,
55
FunctionPrototypeBind,
66
ObjectEntries,
7+
String,
78
Symbol,
89
} = primordials;
910

0 commit comments

Comments
 (0)