Skip to content

Commit 292915a

Browse files
aduh95danielleadams
authored andcommitted
bootstrap: refactor to use more primordials
PR-URL: #35999 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe>
1 parent f73b8d8 commit 292915a

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

‎lib/internal/bootstrap/loaders.js‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,18 @@
4444
/* global process, getLinkedBinding, getInternalBinding, primordials */
4545

4646
const{
47+
ArrayPrototypeMap,
48+
ArrayPrototypePush,
4749
Error,
48-
Map,
4950
ObjectCreate,
5051
ObjectDefineProperty,
5152
ObjectKeys,
5253
ObjectPrototypeHasOwnProperty,
5354
ReflectGet,
55+
SafeMap,
5456
SafeSet,
5557
String,
58+
StringPrototypeStartsWith,
5659
TypeError,
5760
}=primordials;
5861

@@ -135,7 +138,7 @@ let internalBinding;
135138
letmod=bindingObj[module];
136139
if(typeofmod!=='object'){
137140
mod=bindingObj[module]=getInternalBinding(module);
138-
moduleLoadList.push(`Internal Binding ${module}`);
141+
ArrayPrototypePush(moduleLoadList,`Internal Binding ${module}`);
139142
}
140143
returnmod;
141144
};
@@ -163,12 +166,14 @@ class NativeModule {
163166
* A map from the module IDs to the module instances.
164167
* @type {Map<string, NativeModule>}
165168
*/
166-
staticmap=newMap(moduleIds.map((id)=>[id,newNativeModule(id)]));
169+
staticmap=newSafeMap(
170+
ArrayPrototypeMap(moduleIds,(id)=>[id,newNativeModule(id)])
171+
);
167172

168173
constructor(id){
169174
this.filename=`${id}.js`;
170175
this.id=id;
171-
this.canBeRequiredByUsers=!id.startsWith('internal/');
176+
this.canBeRequiredByUsers=!StringPrototypeStartsWith(id,'internal/');
172177

173178
// The CJS exports object of the module.
174179
this.exports={};
@@ -221,7 +226,7 @@ class NativeModule {
221226
if(!this.exportKeys){
222227
// When using --expose-internals, we do not want to reflect the named
223228
// exports from core modules as this can trigger unnecessary getters.
224-
constinternal=this.id.startsWith('internal/');
229+
constinternal=StringPrototypeStartsWith(this.id,'internal/');
225230
this.exportKeys=internal ? [] : ObjectKeys(this.exports);
226231
}
227232
this.getESMFacade();
@@ -271,7 +276,7 @@ class NativeModule {
271276
this.loading=true;
272277

273278
try{
274-
constrequireFn=this.id.startsWith('internal/deps/') ?
279+
constrequireFn=StringPrototypeStartsWith(this.id,'internal/deps/') ?
275280
requireWithFallbackInDeps : nativeModuleRequire;
276281

277282
constfn=compileFunction(id);
@@ -282,7 +287,7 @@ class NativeModule {
282287
this.loading=false;
283288
}
284289

285-
moduleLoadList.push(`NativeModule ${id}`);
290+
ArrayPrototypePush(moduleLoadList,`NativeModule ${id}`);
286291
returnthis.exports;
287292
}
288293
}

‎lib/internal/bootstrap/node.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
setupPrepareStackTrace();
4040

4141
const{
42+
FunctionPrototypeCall,
4243
JSONParse,
4344
ObjectDefineProperty,
4445
ObjectGetPrototypeOf,
@@ -299,7 +300,7 @@ function setupProcessObject() {
299300
constEventEmitter=require('events');
300301
constorigProcProto=ObjectGetPrototypeOf(process);
301302
ObjectSetPrototypeOf(origProcProto,EventEmitter.prototype);
302-
EventEmitter.call(process);
303+
FunctionPrototypeCall(EventEmitter,process);
303304
ObjectDefineProperty(process,SymbolToStringTag,{
304305
enumerable: false,
305306
writable: true,

‎lib/internal/bootstrap/pre_execution.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
'use strict';
22

33
const{
4-
Map,
54
NumberParseInt,
65
ObjectDefineProperty,
6+
SafeMap,
77
SafeWeakMap,
8+
StringPrototypeStartsWith,
89
}=primordials;
910

1011
const{
@@ -96,7 +97,8 @@ function patchProcessObject(expandArgv1) {
9697
});
9798
process.argv[0]=process.execPath;
9899

99-
if(expandArgv1&&process.argv[1]&&!process.argv[1].startsWith('-')){
100+
if(expandArgv1&&process.argv[1]&&
101+
!StringPrototypeStartsWith(process.argv[1],'-')){
100102
// Expand process.argv[1] into a full path.
101103
constpath=require('path');
102104
try{
@@ -357,7 +359,7 @@ function initializePolicy() {
357359
if(experimentalPolicy){
358360
process.emitWarning('Policies are experimental.',
359361
'ExperimentalWarning');
360-
const{ pathToFileURL,URL}=require('url');
362+
const{ pathToFileURL,URL}=require('internal/url');
361363
// URL here as it is slightly different parsing
362364
// no bare specifiers for now
363365
letmanifestURL;
@@ -374,7 +376,7 @@ function initializePolicy() {
374376
if(experimentalPolicyIntegrity){
375377
constSRI=require('internal/policy/sri');
376378
const{ createHash, timingSafeEqual }=require('crypto');
377-
constrealIntegrities=newMap();
379+
constrealIntegrities=newSafeMap();
378380
constintegrityEntries=SRI.parse(experimentalPolicyIntegrity);
379381
letfoundMatch=false;
380382
for(leti=0;i<integrityEntries.length;i++){

0 commit comments

Comments
 (0)