diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index d5715aa9f8c666..d939c2911d0df3 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -44,15 +44,18 @@ /* global process, getLinkedBinding, getInternalBinding, primordials */ const { + ArrayPrototypeMap, + ArrayPrototypePush, Error, - Map, ObjectCreate, ObjectDefineProperty, ObjectKeys, ObjectPrototypeHasOwnProperty, ReflectGet, + SafeMap, SafeSet, String, + StringPrototypeStartsWith, TypeError, } = primordials; @@ -135,7 +138,7 @@ let internalBinding; let mod = bindingObj[module]; if (typeof mod !== 'object') { mod = bindingObj[module] = getInternalBinding(module); - moduleLoadList.push(`Internal Binding ${module}`); + ArrayPrototypePush(moduleLoadList, `Internal Binding ${module}`); } return mod; }; @@ -163,12 +166,14 @@ class NativeModule { * A map from the module IDs to the module instances. * @type {Map} */ - static map = new Map(moduleIds.map((id) => [id, new NativeModule(id)])); + static map = new SafeMap( + ArrayPrototypeMap(moduleIds, (id) => [id, new NativeModule(id)]) + ); constructor(id) { this.filename = `${id}.js`; this.id = id; - this.canBeRequiredByUsers = !id.startsWith('internal/'); + this.canBeRequiredByUsers = !StringPrototypeStartsWith(id, 'internal/'); // The CJS exports object of the module. this.exports = {}; @@ -221,7 +226,7 @@ class NativeModule { if (!this.exportKeys) { // When using --expose-internals, we do not want to reflect the named // exports from core modules as this can trigger unnecessary getters. - const internal = this.id.startsWith('internal/'); + const internal = StringPrototypeStartsWith(this.id, 'internal/'); this.exportKeys = internal ? [] : ObjectKeys(this.exports); } this.getESMFacade(); @@ -271,7 +276,7 @@ class NativeModule { this.loading = true; try { - const requireFn = this.id.startsWith('internal/deps/') ? + const requireFn = StringPrototypeStartsWith(this.id, 'internal/deps/') ? requireWithFallbackInDeps : nativeModuleRequire; const fn = compileFunction(id); @@ -282,7 +287,7 @@ class NativeModule { this.loading = false; } - moduleLoadList.push(`NativeModule ${id}`); + ArrayPrototypePush(moduleLoadList, `NativeModule ${id}`); return this.exports; } } diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 6d6ca2af629c41..2705f8b50a658d 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -39,6 +39,7 @@ setupPrepareStackTrace(); const { + FunctionPrototypeCall, JSONParse, ObjectDefineProperty, ObjectGetPrototypeOf, @@ -271,7 +272,7 @@ function setupProcessObject() { const EventEmitter = require('events'); const origProcProto = ObjectGetPrototypeOf(process); ObjectSetPrototypeOf(origProcProto, EventEmitter.prototype); - EventEmitter.call(process); + FunctionPrototypeCall(EventEmitter, process); ObjectDefineProperty(process, SymbolToStringTag, { enumerable: false, writable: true, diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 9689e2a9edf695..c76add4621b614 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -1,10 +1,11 @@ 'use strict'; const { - Map, NumberParseInt, ObjectDefineProperty, + SafeMap, SafeWeakMap, + StringPrototypeStartsWith, } = primordials; const { @@ -90,7 +91,8 @@ function patchProcessObject(expandArgv1) { }); process.argv[0] = process.execPath; - if (expandArgv1 && process.argv[1] && !process.argv[1].startsWith('-')) { + if (expandArgv1 && process.argv[1] && + !StringPrototypeStartsWith(process.argv[1], '-')) { // Expand process.argv[1] into a full path. const path = require('path'); try { @@ -351,7 +353,7 @@ function initializePolicy() { if (experimentalPolicy) { process.emitWarning('Policies are experimental.', 'ExperimentalWarning'); - const { pathToFileURL, URL } = require('url'); + const { pathToFileURL, URL } = require('internal/url'); // URL here as it is slightly different parsing // no bare specifiers for now let manifestURL; @@ -368,7 +370,7 @@ function initializePolicy() { if (experimentalPolicyIntegrity) { const SRI = require('internal/policy/sri'); const { createHash, timingSafeEqual } = require('crypto'); - const realIntegrities = new Map(); + const realIntegrities = new SafeMap(); const integrityEntries = SRI.parse(experimentalPolicyIntegrity); let foundMatch = false; for (let i = 0; i < integrityEntries.length; i++) {