40
40
'use strict' ;
41
41
42
42
// This file is compiled as if it's wrapped in a function with arguments
43
- // passed by node::LoadEnvironment ()
43
+ // passed by node::RunBootstrapping ()
44
44
/* global process, getBinding, getLinkedBinding, getInternalBinding */
45
- /* global debugBreak, experimentalModules, exposeInternals */
45
+ /* global experimentalModules, exposeInternals, primordials */
46
46
47
- if ( debugBreak )
48
- debugger ; // eslint-disable-line no-debugger
49
-
50
- const {
51
- apply : ReflectApply ,
52
- deleteProperty : ReflectDeleteProperty ,
53
- get : ReflectGet ,
54
- getOwnPropertyDescriptor : ReflectGetOwnPropertyDescriptor ,
55
- has : ReflectHas ,
56
- set : ReflectSet ,
57
- } = Reflect ;
58
47
const {
59
- prototype : {
60
- hasOwnProperty : ObjectHasOwnProperty ,
61
- } ,
62
- create : ObjectCreate ,
63
- defineProperty : ObjectDefineProperty ,
64
- keys : ObjectKeys ,
65
- } = Object ;
48
+ Reflect,
49
+ Object,
50
+ ObjectPrototype,
51
+ SafeSet
52
+ } = primordials ;
66
53
67
54
// Set up process.moduleLoadList.
68
55
const moduleLoadList = [ ] ;
69
- ObjectDefineProperty ( process , 'moduleLoadList' , {
56
+ Object . defineProperty ( process , 'moduleLoadList' , {
70
57
value : moduleLoadList ,
71
58
configurable : true ,
72
59
enumerable : true ,
@@ -78,7 +65,7 @@ ObjectDefineProperty(process, 'moduleLoadList', {
78
65
// that are whitelisted for access via process.binding()... This is used
79
66
// to provide a transition path for modules that are being moved over to
80
67
// internalBinding.
81
- const internalBindingWhitelist = [
68
+ const internalBindingWhitelist = new SafeSet ( [
82
69
'async_wrap' ,
83
70
'buffer' ,
84
71
'cares_wrap' ,
@@ -108,20 +95,17 @@ const internalBindingWhitelist = [
108
95
'uv' ,
109
96
'v8' ,
110
97
'zlib'
111
- ] ;
112
- // We will use a lazy loaded SafeSet in internalBindingWhitelistHas
113
- // for checking existence in this list.
114
- let internalBindingWhitelistSet ;
98
+ ] ) ;
115
99
116
100
// Set up process.binding() and process._linkedBinding().
117
101
{
118
- const bindingObj = ObjectCreate ( null ) ;
102
+ const bindingObj = Object . create ( null ) ;
119
103
120
104
process . binding = function binding ( module ) {
121
105
module = String ( module ) ;
122
106
// Deprecated specific process.binding() modules, but not all, allow
123
107
// selective fallback to internalBinding for the deprecated ones.
124
- if ( internalBindingWhitelistHas ( module ) ) {
108
+ if ( internalBindingWhitelist . has ( module ) ) {
125
109
return internalBinding ( module ) ;
126
110
}
127
111
let mod = bindingObj [ module ] ;
@@ -144,7 +128,7 @@ let internalBindingWhitelistSet;
144
128
// Set up internalBinding() in the closure.
145
129
let internalBinding ;
146
130
{
147
- const bindingObj = ObjectCreate ( null ) ;
131
+ const bindingObj = Object . create ( null ) ;
148
132
internalBinding = function internalBinding ( module ) {
149
133
let mod = bindingObj [ module ] ;
150
134
if ( typeof mod !== 'object' ) {
@@ -245,8 +229,8 @@ NativeModule.requireWithFallbackInDeps = function(request) {
245
229
} ;
246
230
247
231
const getOwn = ( target , property , receiver ) => {
248
- return ReflectApply ( ObjectHasOwnProperty , target , [ property ] ) ?
249
- ReflectGet ( target , property , receiver ) :
232
+ return Reflect . apply ( ObjectPrototype . hasOwnProperty , target , [ property ] ) ?
233
+ Reflect . get ( target , property , receiver ) :
250
234
undefined ;
251
235
} ;
252
236
@@ -255,12 +239,12 @@ const getOwn = (target, property, receiver) => {
255
239
// as the entire namespace (module.exports) and wrapped in a proxy such
256
240
// that APMs and other behavior are still left intact.
257
241
NativeModule . prototype . proxifyExports = function ( ) {
258
- this . exportKeys = ObjectKeys ( this . exports ) ;
242
+ this . exportKeys = Object . keys ( this . exports ) ;
259
243
260
244
const update = ( property , value ) => {
261
245
if ( this . reflect !== undefined &&
262
- ReflectApply ( ObjectHasOwnProperty ,
263
- this . reflect . exports , [ property ] ) )
246
+ Reflect . apply ( ObjectPrototype . hasOwnProperty ,
247
+ this . reflect . exports , [ property ] ) )
264
248
this . reflect . exports [ property ] . set ( value ) ;
265
249
} ;
266
250
@@ -269,12 +253,12 @@ NativeModule.prototype.proxifyExports = function() {
269
253
defineProperty : ( target , prop , descriptor ) => {
270
254
// Use `Object.defineProperty` instead of `Reflect.defineProperty`
271
255
// to throw the appropriate error if something goes wrong.
272
- ObjectDefineProperty ( target , prop , descriptor ) ;
256
+ Object . defineProperty ( target , prop , descriptor ) ;
273
257
if ( typeof descriptor . get === 'function' &&
274
- ! ReflectHas ( handler , 'get' ) ) {
258
+ ! Reflect . has ( handler , 'get' ) ) {
275
259
handler . get = ( target , prop , receiver ) => {
276
- const value = ReflectGet ( target , prop , receiver ) ;
277
- if ( ReflectApply ( ObjectHasOwnProperty , target , [ prop ] ) )
260
+ const value = Reflect . get ( target , prop , receiver ) ;
261
+ if ( Reflect . apply ( ObjectPrototype . hasOwnProperty , target , [ prop ] ) )
278
262
update ( prop , value ) ;
279
263
return value ;
280
264
} ;
@@ -283,15 +267,15 @@ NativeModule.prototype.proxifyExports = function() {
283
267
return true ;
284
268
} ,
285
269
deleteProperty : ( target , prop ) => {
286
- if ( ReflectDeleteProperty ( target , prop ) ) {
270
+ if ( Reflect . deleteProperty ( target , prop ) ) {
287
271
update ( prop , undefined ) ;
288
272
return true ;
289
273
}
290
274
return false ;
291
275
} ,
292
276
set : ( target , prop , value , receiver ) => {
293
- const descriptor = ReflectGetOwnPropertyDescriptor ( target , prop ) ;
294
- if ( ReflectSet ( target , prop , value , receiver ) ) {
277
+ const descriptor = Reflect . getOwnPropertyDescriptor ( target , prop ) ;
278
+ if ( Reflect . set ( target , prop , value , receiver ) ) {
295
279
if ( descriptor && typeof descriptor . set === 'function' ) {
296
280
for ( const key of this . exportKeys ) {
297
281
update ( key , getOwn ( target , key , receiver ) ) ;
@@ -319,7 +303,7 @@ NativeModule.prototype.compile = function() {
319
303
NativeModule . require ;
320
304
321
305
const fn = compileFunction ( id ) ;
322
- fn ( this . exports , requireFn , this , process , internalBinding ) ;
306
+ fn ( this . exports , requireFn , this , process , internalBinding , primordials ) ;
323
307
324
308
if ( experimentalModules && this . canBeRequiredByUsers ) {
325
309
this . proxifyExports ( ) ;
@@ -344,13 +328,5 @@ if (process.env.NODE_V8_COVERAGE) {
344
328
}
345
329
}
346
330
347
- function internalBindingWhitelistHas ( name ) {
348
- if ( ! internalBindingWhitelistSet ) {
349
- const { SafeSet } = NativeModule . require ( 'internal/safe_globals' ) ;
350
- internalBindingWhitelistSet = new SafeSet ( internalBindingWhitelist ) ;
351
- }
352
- return internalBindingWhitelistSet . has ( name ) ;
353
- }
354
-
355
331
// This will be passed to internal/bootstrap/node.js.
356
332
return loaderExports ;
0 commit comments