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: more global primordials #35499

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
24 changes: 24 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ rules:
- error
- name: Array
message: "Use `const { Array } = primordials;` instead of the global."
- name: ArrayBuffer
message: "Use `const { ArrayBuffer } = primordials;` instead of the global."
- name: BigInt
message: "Use `const { BigInt } = primordials;` instead of the global."
- name: BigInt64Array
Expand All @@ -21,6 +23,8 @@ rules:
message: "Use `const { Boolean } = primordials;` instead of the global."
- name: Error
message: "Use `const { Error } = primordials;` instead of the global."
- name: EvalError
message: "Use `const { EvalError } = primordials;` instead of the global."
- name: Float32Array
message: "Use `const { Float32Array } = primordials;` instead of the global."
- name: Float64Array
Expand All @@ -43,6 +47,10 @@ rules:
message: "Use `const { Object } = primordials;` instead of the global."
- name: Promise
message: "Use `const { Promise } = primordials;` instead of the global."
- name: RangeError
message: "Use `const { RangeError } = primordials;` instead of the global."
- name: ReferenceError
message: "Use `const { ReferenceError } = primordials;` instead of the global."
- name: Reflect
message: "Use `const { Reflect } = primordials;` instead of the global."
- name: RegExp
Expand All @@ -53,12 +61,28 @@ rules:
message: "Use `const { String } = primordials;` instead of the global."
- name: Symbol
message: "Use `const { Symbol } = primordials;` instead of the global."
- name: SyntaxError
message: "Use `const { SyntaxError } = primordials;` instead of the global."
- name: TypeError
message: "Use `const { TypeError } = primordials;` instead of the global."
- name: URIError
message: "Use `const { URIError } = primordials;` instead of the global."
- name: Uint16Array
message: "Use `const { Uint16Array } = primordials;` instead of the global."
- name: Uint32Array
message: "Use `const { Uint32Array } = primordials;` instead of the global."
- name: Uint8Array
message: "Use `const { Uint8Array } = primordials;` instead of the global."
- name: Uint8ClampedArray
message: "Use `const { Uint8ClampedArray } = primordials;` instead of the global."
- name: WeakMap
message: "Use `const { WeakMap } = primordials;` instead of the global."
- name: WeakSet
message: "Use `const { WeakSet } = primordials;` instead of the global."
- name: parseFloat
message: "Use `const { NumberParseFloat } = primordials;` instead of the global."
- name: parseInt
message: "Use `const { NumberParseInt } = primordials;` instead of the global."
no-restricted-syntax:
# Config copied from .eslintrc.js
- error
Expand Down
3 changes: 2 additions & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const {
ObjectSetPrototypeOf,
SymbolSpecies,
SymbolToPrimitive,
Uint8Array,
Uint8ArrayPrototype,
} = primordials;

Expand Down Expand Up @@ -387,7 +388,7 @@ function SlowBuffer(length) {
return createUnsafeBuffer(length);
}

ObjectSetPrototypeOf(SlowBuffer.prototype, Uint8Array.prototype);
ObjectSetPrototypeOf(SlowBuffer.prototype, Uint8ArrayPrototype);
ObjectSetPrototypeOf(SlowBuffer, Uint8Array);

function allocate(size) {
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 @@ -53,6 +53,7 @@ const {
ReflectGet,
SafeSet,
String,
TypeError,
} = primordials;

// Set up process.moduleLoadList.
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {
Map,
NumberParseInt,
ObjectDefineProperty,
SafeWeakMap,
} = primordials;
Expand Down Expand Up @@ -327,7 +328,7 @@ function setupChildProcessIpcChannel() {
if (process.env.NODE_CHANNEL_FD) {
const assert = require('internal/assert');

const fd = parseInt(process.env.NODE_CHANNEL_FD, 10);
const fd = NumberParseInt(process.env.NODE_CHANNEL_FD, 10);
assert(fd >= 0);

// Make sure it's not accidentally inherited by child processes.
Expand Down
1 change: 1 addition & 0 deletions lib/internal/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
Float64Array,
MathFloor,
Number,
Uint8Array,
} = primordials;

const {
Expand Down
1 change: 1 addition & 0 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
ObjectDefineProperty,
ObjectSetPrototypeOf,
Symbol,
Uint8Array,
} = primordials;

const {
Expand Down
5 changes: 3 additions & 2 deletions lib/internal/dns/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {
ArrayIsArray,
NumberParseInt,
} = primordials;

const errors = require('internal/errors');
Expand Down Expand Up @@ -79,7 +80,7 @@ class Resolver {

if (ipVersion !== 0) {
const port =
parseInt(serv.replace(addrSplitRE, '$2')) || IANA_DNS_PORT;
NumberParseInt(serv.replace(addrSplitRE, '$2')) || IANA_DNS_PORT;
targos marked this conversation as resolved.
Show resolved Hide resolved
return newSet.push([ipVersion, match[1], port]);
}
}
Expand All @@ -94,7 +95,7 @@ class Resolver {
ipVersion = isIP(hostIP);

if (ipVersion !== 0) {
return newSet.push([ipVersion, hostIP, parseInt(port)]);
return newSet.push([ipVersion, hostIP, NumberParseInt(port)]);
targos marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/internal/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const {
ObjectGetOwnPropertyDescriptors,
Symbol,
SymbolToStringTag,
Uint32Array,
Uint8Array,
} = primordials;

const {
Expand Down
6 changes: 6 additions & 0 deletions lib/internal/error_serdes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Buffer = require('buffer').Buffer;
const {
ArrayPrototypeForEach,
Error,
EvalError,
FunctionPrototypeCall,
ObjectAssign,
ObjectCreate,
Expand All @@ -13,8 +14,13 @@ const {
ObjectGetPrototypeOf,
ObjectKeys,
ObjectPrototypeToString,
RangeError,
ReferenceError,
SafeSet,
SymbolToStringTag,
SyntaxError,
TypeError,
URIError,
} = primordials;

const kSerializedError = 0;
Expand Down
6 changes: 5 additions & 1 deletion lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ const {
NumberIsInteger,
ObjectDefineProperty,
ObjectKeys,
RangeError,
String,
StringPrototypeStartsWith,
Symbol,
SymbolFor,
SyntaxError,
TypeError,
URIError,
WeakMap,
} = primordials;

Expand Down Expand Up @@ -81,7 +85,7 @@ const maybeOverridePrepareStackTrace = (globalThis, error, trace) => {
// https://crbug.com/v8/7848
// `globalThis` is the global that contains the constructor which
// created `error`.
if (typeof globalThis.Error.prepareStackTrace === 'function') {
if (typeof globalThis.Error?.prepareStackTrace === 'function') {
return globalThis.Error.prepareStackTrace(error, trace);
}
// We still have legacy usage that depends on the main context's `Error`
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const {
ReflectGetPrototypeOf,
Set,
Symbol,
Uint32Array,
Uint8Array,
} = primordials;

const {
Expand Down
1 change: 1 addition & 0 deletions lib/internal/per_context/domexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
SafeWeakMap,
SafeMap,
SymbolToStringTag,
TypeError,
} = primordials;

class ERR_INVALID_THIS extends TypeError {
Expand Down
6 changes: 6 additions & 0 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ primordials.SafePromise = makeSafe(
'Boolean',
'Date',
'Error',
'EvalError',
'Float32Array',
'Float64Array',
'Function',
Expand All @@ -134,10 +135,15 @@ primordials.SafePromise = makeSafe(
'Map',
'Number',
'Object',
'RangeError',
'ReferenceError',
'RegExp',
'Set',
'String',
'Symbol',
'SyntaxError',
'TypeError',
'URIError',
'Uint16Array',
'Uint32Array',
'Uint8Array',
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 @@ -18,6 +18,7 @@ const {
SetPrototype,
SetPrototypeHas,
StringPrototypeReplace,
Uint32Array,
} = primordials;

const {
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const {
Number,
NumberIsNaN,
NumberParseInt,
ObjectCreate,
} = primordials;

Expand All @@ -25,7 +26,7 @@ function createRepl(env, opts, cb) {
...opts
};

if (parseInt(env.NODE_NO_READLINE)) {
if (NumberParseInt(env.NODE_NO_READLINE)) {
opts.terminal = false;
}

Expand Down
1 change: 1 addition & 0 deletions lib/internal/streams/buffer_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {
SymbolIterator,
Uint8Array,
} = primordials;

const { Buffer } = require('buffer');
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
const {
NumberIsInteger,
NumberIsNaN,
NumberParseInt,
ObjectDefineProperties,
ObjectKeys,
ObjectSetPrototypeOf,
Expand Down Expand Up @@ -388,7 +389,7 @@ Readable.prototype.read = function(n) {
if (n === undefined) {
n = NaN;
} else if (!NumberIsInteger(n)) {
n = parseInt(n, 10);
n = NumberParseInt(n, 10);
}
const state = this._readableState;
const nOrig = n;
Expand Down
1 change: 1 addition & 0 deletions lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
StringPrototypeValueOf,
SymbolPrototypeValueOf,
SymbolToStringTag,
Uint8Array,
} = primordials;

const { compare } = internalBinding('buffer');
Expand Down
14 changes: 11 additions & 3 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const {
MathSqrt,
Number,
NumberIsNaN,
NumberParseFloat,
NumberParseInt,
NumberPrototypeValueOf,
Object,
ObjectAssign,
Expand Down Expand Up @@ -56,6 +58,10 @@ const {
SymbolIterator,
SymbolToStringTag,
Uint16Array,
Uint32Array,
Uint8Array,
Uint8ArrayPrototype,
Uint8ClampedArray,
uncurryThis,
} = primordials;

Expand Down Expand Up @@ -136,7 +142,7 @@ const mapSizeGetter = uncurryThis(
ObjectGetOwnPropertyDescriptor(MapPrototype, 'size').get);
const typedArraySizeGetter = uncurryThis(
ObjectGetOwnPropertyDescriptor(
ObjectGetPrototypeOf(Uint8Array.prototype), 'length').get);
ObjectGetPrototypeOf(Uint8ArrayPrototype), 'length').get);

let hexSlice;

Expand Down Expand Up @@ -1950,15 +1956,17 @@ function formatWithOptionsInternal(inspectOptions, ...args) {
} else if (typeof tempInteger === 'symbol') {
tempStr = 'NaN';
} else {
tempStr = formatNumber(stylizeNoColor, parseInt(tempInteger));
tempStr = formatNumber(stylizeNoColor,
NumberParseInt(tempInteger));
}
break;
case 102: // 'f'
const tempFloat = args[++a];
if (typeof tempFloat === 'symbol') {
tempStr = 'NaN';
} else {
tempStr = formatNumber(stylizeNoColor, parseFloat(tempFloat));
tempStr = formatNumber(stylizeNoColor,
NumberParseFloat(tempFloat));
}
break;
case 99: // 'c'
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/util/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ const {
ObjectGetOwnPropertyDescriptor,
ObjectGetPrototypeOf,
SymbolToStringTag,
Uint8ArrayPrototype,
uncurryThis,
} = primordials;

const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8Array.prototype);
const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8ArrayPrototype);

const TypedArrayProto_toStringTag =
uncurryThis(
Expand Down
3 changes: 2 additions & 1 deletion 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,
NumberParseInt,
String,
} = primordials;

Expand Down Expand Up @@ -65,7 +66,7 @@ function parseFileMode(value, name, def) {
if (!octalReg.test(value)) {
throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc);
}
return parseInt(value, 8);
return NumberParseInt(value, 8);
}

throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc);
Expand Down
1 change: 1 addition & 0 deletions lib/internal/vm/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
ObjectSetPrototypeOf,
SafePromise,
Symbol,
TypeError,
WeakMap,
} = primordials;

Expand Down
1 change: 1 addition & 0 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
String,
Symbol,
SymbolFor,
Uint32Array,
} = primordials;

const EventEmitter = require('events');
Expand Down
Loading