Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: use more global primordials #35397

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ 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: 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
Expand All @@ -43,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/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const {
BigInt,
Float32Array,
Float64Array,
MathFloor,
Number,
} = primordials;
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
6 changes: 4 additions & 2 deletions lib/internal/http2/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const {
ObjectCreate,
ObjectKeys,
Set,
String,
StringFromCharCode,
StringPrototypeToLowerCase,
Symbol,
} = primordials;
Expand Down Expand Up @@ -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 = '';
Expand Down
1 change: 1 addition & 0 deletions lib/internal/process/per_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
const {
ArrayIsArray,
BigUint64Array,
Float64Array,
NumberMAX_SAFE_INTEGER,
ObjectDefineProperties,
ObjectDefineProperty,
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
4 changes: 4 additions & 0 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ const {
DatePrototypeToString,
ErrorPrototypeToString,
Float32Array,
Float64Array,
FunctionPrototypeCall,
FunctionPrototypeToString,
Int8Array,
Int16Array,
Int32Array,
JSONStringify,
Map,
MapPrototype,
Expand Down Expand Up @@ -46,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
2 changes: 2 additions & 0 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

const {
ArrayIsArray,
Float64Array,
JSONStringify,
MathMax,
ObjectCreate,
ObjectEntries,
Promise,
PromiseResolve,
String,
Symbol,
SymbolFor,
} = primordials;
Expand Down
1 change: 1 addition & 0 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'use strict';

const {
Float64Array,
ObjectDefineProperties,
SymbolToPrimitive,
} = 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),
'.'
);
Comment on lines +151 to +154
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb @Trott I made the change, but I don't really like how the code looks like (that's why I'm currently only pushing for use of static primordials)...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instance method primordials are used often in the node codebase; imo "how it looks" is only relevant once robustness against user code is assured.

}

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