20
20
// https://github.com/tc39/proposal-ses/blob/e5271cc42a257a05dcae2fd94713ed2f46c08620/shim/src/freeze.js
21
21
22
22
/* global WebAssembly, SharedArrayBuffer, console */
23
- /* eslint-disable no-restricted-globals */
24
23
'use strict' ;
25
24
25
+ const {
26
+ Array,
27
+ ArrayBuffer,
28
+ ArrayPrototypeForEach,
29
+ BigInt,
30
+ BigInt64Array,
31
+ BigUint64Array,
32
+ Boolean,
33
+ DataView,
34
+ Date,
35
+ Error,
36
+ EvalError,
37
+ Float32Array,
38
+ Float64Array,
39
+ Function,
40
+ Int16Array,
41
+ Int32Array,
42
+ Int8Array,
43
+ JSON ,
44
+ Map,
45
+ Math,
46
+ Number,
47
+ Object,
48
+ ObjectDefineProperty,
49
+ ObjectFreeze,
50
+ ObjectGetOwnPropertyDescriptor,
51
+ ObjectGetOwnPropertyDescriptors,
52
+ ObjectGetOwnPropertyNames,
53
+ ObjectGetOwnPropertySymbols,
54
+ ObjectGetPrototypeOf,
55
+ ObjectPrototypeHasOwnProperty,
56
+ Promise,
57
+ RangeError,
58
+ ReferenceError,
59
+ Reflect,
60
+ ReflectOwnKeys,
61
+ RegExp,
62
+ Set,
63
+ String,
64
+ Symbol,
65
+ SymbolIterator,
66
+ SyntaxError,
67
+ TypeError,
68
+ Uint16Array,
69
+ Uint32Array,
70
+ Uint8Array,
71
+ Uint8ClampedArray,
72
+ URIError,
73
+ WeakMap,
74
+ WeakSet,
75
+ } = primordials ;
76
+
26
77
module . exports = function ( ) {
27
- const {
28
- defineProperty,
29
- freeze,
30
- getOwnPropertyDescriptor,
31
- getOwnPropertyDescriptors,
32
- getOwnPropertyNames,
33
- getOwnPropertySymbols,
34
- getPrototypeOf,
35
- } = Object ;
36
- const objectHasOwnProperty = Object . prototype . hasOwnProperty ;
37
- const { ownKeys } = Reflect ;
38
78
const {
39
79
clearImmediate,
40
80
clearInterval,
@@ -47,25 +87,25 @@ module.exports = function() {
47
87
const intrinsicPrototypes = [
48
88
// Anonymous Intrinsics
49
89
// IteratorPrototype
50
- getPrototypeOf (
51
- getPrototypeOf ( new Array ( ) [ Symbol . iterator ] ( ) )
90
+ ObjectGetPrototypeOf (
91
+ ObjectGetPrototypeOf ( new Array ( ) [ SymbolIterator ] ( ) )
52
92
) ,
53
93
// ArrayIteratorPrototype
54
- getPrototypeOf ( new Array ( ) [ Symbol . iterator ] ( ) ) ,
94
+ ObjectGetPrototypeOf ( new Array ( ) [ SymbolIterator ] ( ) ) ,
55
95
// StringIteratorPrototype
56
- getPrototypeOf ( new String ( ) [ Symbol . iterator ] ( ) ) ,
96
+ ObjectGetPrototypeOf ( new String ( ) [ SymbolIterator ] ( ) ) ,
57
97
// MapIteratorPrototype
58
- getPrototypeOf ( new Map ( ) [ Symbol . iterator ] ( ) ) ,
98
+ ObjectGetPrototypeOf ( new Map ( ) [ SymbolIterator ] ( ) ) ,
59
99
// SetIteratorPrototype
60
- getPrototypeOf ( new Set ( ) [ Symbol . iterator ] ( ) ) ,
100
+ ObjectGetPrototypeOf ( new Set ( ) [ SymbolIterator ] ( ) ) ,
61
101
// GeneratorFunction
62
- getPrototypeOf ( function * ( ) { } ) ,
102
+ ObjectGetPrototypeOf ( function * ( ) { } ) ,
63
103
// AsyncFunction
64
- getPrototypeOf ( async function ( ) { } ) ,
104
+ ObjectGetPrototypeOf ( async function ( ) { } ) ,
65
105
// AsyncGeneratorFunction
66
- getPrototypeOf ( async function * ( ) { } ) ,
106
+ ObjectGetPrototypeOf ( async function * ( ) { } ) ,
67
107
// TypedArray
68
- getPrototypeOf ( Uint8Array ) ,
108
+ ObjectGetPrototypeOf ( Uint8Array ) ,
69
109
70
110
// 19 Fundamental Objects
71
111
Object . prototype , // 19.1
@@ -129,33 +169,37 @@ module.exports = function() {
129
169
const intrinsics = [
130
170
// Anonymous Intrinsics
131
171
// ThrowTypeError
132
- getOwnPropertyDescriptor ( Function . prototype , 'caller' ) . get ,
172
+ ObjectGetOwnPropertyDescriptor ( Function . prototype , 'caller' ) . get ,
133
173
// IteratorPrototype
134
- getPrototypeOf (
135
- getPrototypeOf ( new Array ( ) [ Symbol . iterator ] ( ) )
174
+ ObjectGetPrototypeOf (
175
+ ObjectGetPrototypeOf ( new Array ( ) [ SymbolIterator ] ( ) )
136
176
) ,
137
177
// ArrayIteratorPrototype
138
- getPrototypeOf ( new Array ( ) [ Symbol . iterator ] ( ) ) ,
178
+ ObjectGetPrototypeOf ( new Array ( ) [ SymbolIterator ] ( ) ) ,
139
179
// StringIteratorPrototype
140
- getPrototypeOf ( new String ( ) [ Symbol . iterator ] ( ) ) ,
180
+ ObjectGetPrototypeOf ( new String ( ) [ SymbolIterator ] ( ) ) ,
141
181
// MapIteratorPrototype
142
- getPrototypeOf ( new Map ( ) [ Symbol . iterator ] ( ) ) ,
182
+ ObjectGetPrototypeOf ( new Map ( ) [ SymbolIterator ] ( ) ) ,
143
183
// SetIteratorPrototype
144
- getPrototypeOf ( new Set ( ) [ Symbol . iterator ] ( ) ) ,
184
+ ObjectGetPrototypeOf ( new Set ( ) [ SymbolIterator ] ( ) ) ,
145
185
// GeneratorFunction
146
- getPrototypeOf ( function * ( ) { } ) ,
186
+ ObjectGetPrototypeOf ( function * ( ) { } ) ,
147
187
// AsyncFunction
148
- getPrototypeOf ( async function ( ) { } ) ,
188
+ ObjectGetPrototypeOf ( async function ( ) { } ) ,
149
189
// AsyncGeneratorFunction
150
- getPrototypeOf ( async function * ( ) { } ) ,
190
+ ObjectGetPrototypeOf ( async function * ( ) { } ) ,
151
191
// TypedArray
152
- getPrototypeOf ( Uint8Array ) ,
192
+ ObjectGetPrototypeOf ( Uint8Array ) ,
153
193
154
194
// 18 The Global Object
155
195
eval ,
196
+ // eslint-disable-next-line node-core/prefer-primordials
156
197
isFinite ,
198
+ // eslint-disable-next-line node-core/prefer-primordials
157
199
isNaN ,
200
+ // eslint-disable-next-line node-core/prefer-primordials
158
201
parseFloat ,
202
+ // eslint-disable-next-line node-core/prefer-primordials
159
203
parseInt ,
160
204
decodeURI ,
161
205
decodeURIComponent ,
@@ -289,16 +333,16 @@ module.exports = function() {
289
333
// Object are verified before being enqueued,
290
334
// therefore this is a valid candidate.
291
335
// Throws if this fails (strict mode).
292
- freeze ( obj ) ;
336
+ ObjectFreeze ( obj ) ;
293
337
294
338
// We rely upon certain commitments of Object.freeze and proxies here
295
339
296
340
// Get stable/immutable outbound links before a Proxy has a chance to do
297
341
// something sneaky.
298
- const proto = getPrototypeOf ( obj ) ;
299
- const descs = getOwnPropertyDescriptors ( obj ) ;
342
+ const proto = ObjectGetPrototypeOf ( obj ) ;
343
+ const descs = ObjectGetOwnPropertyDescriptors ( obj ) ;
300
344
enqueue ( proto ) ;
301
- ownKeys ( descs ) . forEach ( ( name ) => {
345
+ ArrayPrototypeForEach ( ReflectOwnKeys ( descs ) , ( name ) => {
302
346
// TODO: Uncurried form
303
347
// TODO: getOwnPropertyDescriptors is guaranteed to return well-formed
304
348
// descriptors, but they still inherit from Object.prototype. If
@@ -378,10 +422,10 @@ module.exports = function() {
378
422
`Cannot assign to read only property '${ prop } ' of object '${ obj } '`
379
423
) ;
380
424
}
381
- if ( objectHasOwnProperty . call ( this , prop ) ) {
425
+ if ( ObjectPrototypeHasOwnProperty ( this , prop ) ) {
382
426
this [ prop ] = newValue ;
383
427
} else {
384
- defineProperty ( this , prop , {
428
+ ObjectDefineProperty ( this , prop , {
385
429
value : newValue ,
386
430
writable : true ,
387
431
enumerable : true ,
@@ -390,7 +434,7 @@ module.exports = function() {
390
434
}
391
435
}
392
436
393
- defineProperty ( obj , prop , {
437
+ ObjectDefineProperty ( obj , prop , {
394
438
get : getter ,
395
439
set : setter ,
396
440
enumerable : desc . enumerable ,
@@ -403,14 +447,14 @@ module.exports = function() {
403
447
if ( ! obj ) {
404
448
return ;
405
449
}
406
- const descs = getOwnPropertyDescriptors ( obj ) ;
450
+ const descs = ObjectGetOwnPropertyDescriptors ( obj ) ;
407
451
if ( ! descs ) {
408
452
return ;
409
453
}
410
- getOwnPropertyNames ( obj ) . forEach ( ( prop ) => {
454
+ ArrayPrototypeForEach ( ObjectGetOwnPropertyNames ( obj ) , ( prop ) => {
411
455
return enableDerivedOverride ( obj , prop , descs [ prop ] ) ;
412
456
} ) ;
413
- getOwnPropertySymbols ( obj ) . forEach ( ( prop ) => {
457
+ ArrayPrototypeForEach ( ObjectGetOwnPropertySymbols ( obj ) , ( prop ) => {
414
458
return enableDerivedOverride ( obj , prop , descs [ prop ] ) ;
415
459
} ) ;
416
460
}
0 commit comments