Skip to content
Merged
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
19 changes: 12 additions & 7 deletions lib/internal/bootstrap/loaders.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;

Expand DownExpand Up@@ -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;
};
Expand DownExpand Up@@ -163,12 +166,14 @@ class NativeModule {
* A map from the module IDs to the module instances.
* @type {Map<string, NativeModule>}
*/
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 = {};
Expand DownExpand Up@@ -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();
Expand DownExpand Up@@ -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);
Expand All@@ -282,7 +287,7 @@ class NativeModule {
this.loading = false;
}

moduleLoadList.push(`NativeModule ${id}`);
ArrayPrototypePush(moduleLoadList, `NativeModule ${id}`);
return this.exports;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/bootstrap/node.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,6 +39,7 @@
setupPrepareStackTrace();

const {
FunctionPrototypeCall,
JSONParse,
ObjectDefineProperty,
ObjectGetPrototypeOf,
Expand DownExpand Up@@ -299,7 +300,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,
Expand Down
10 changes: 6 additions & 4 deletions lib/internal/bootstrap/pre_execution.js
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
'use strict';

const {
Map,
NumberParseInt,
ObjectDefineProperty,
SafeMap,
SafeWeakMap,
StringPrototypeStartsWith,
} = primordials;

const {
Expand DownExpand Up@@ -96,7 +97,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 {
Expand DownExpand Up@@ -357,7 +359,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;
Expand All@@ -374,7 +376,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++) {
Expand Down