2020// https://github.com/tc39/proposal-ses/blob/e5271cc42a257a05dcae2fd94713ed2f46c08620/shim/src/freeze.js
2121
2222/* global WebAssembly, SharedArrayBuffer, console */
23- /* eslint-disable no-restricted-globals */
2423'use strict' ;
2524
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+
2677module . 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 ;
3878 const {
3979 clearImmediate,
4080 clearInterval,
@@ -47,25 +87,25 @@ module.exports = function() {
4787 const intrinsicPrototypes = [
4888 // Anonymous Intrinsics
4989 // IteratorPrototype
50- getPrototypeOf (
51- getPrototypeOf ( new Array ( ) [ Symbol . iterator ] ( ) )
90+ ObjectGetPrototypeOf (
91+ ObjectGetPrototypeOf ( new Array ( ) [ SymbolIterator ] ( ) )
5292 ) ,
5393 // ArrayIteratorPrototype
54- getPrototypeOf ( new Array ( ) [ Symbol . iterator ] ( ) ) ,
94+ ObjectGetPrototypeOf ( new Array ( ) [ SymbolIterator ] ( ) ) ,
5595 // StringIteratorPrototype
56- getPrototypeOf ( new String ( ) [ Symbol . iterator ] ( ) ) ,
96+ ObjectGetPrototypeOf ( new String ( ) [ SymbolIterator ] ( ) ) ,
5797 // MapIteratorPrototype
58- getPrototypeOf ( new Map ( ) [ Symbol . iterator ] ( ) ) ,
98+ ObjectGetPrototypeOf ( new Map ( ) [ SymbolIterator ] ( ) ) ,
5999 // SetIteratorPrototype
60- getPrototypeOf ( new Set ( ) [ Symbol . iterator ] ( ) ) ,
100+ ObjectGetPrototypeOf ( new Set ( ) [ SymbolIterator ] ( ) ) ,
61101 // GeneratorFunction
62- getPrototypeOf ( function * ( ) { } ) ,
102+ ObjectGetPrototypeOf ( function * ( ) { } ) ,
63103 // AsyncFunction
64- getPrototypeOf ( async function ( ) { } ) ,
104+ ObjectGetPrototypeOf ( async function ( ) { } ) ,
65105 // AsyncGeneratorFunction
66- getPrototypeOf ( async function * ( ) { } ) ,
106+ ObjectGetPrototypeOf ( async function * ( ) { } ) ,
67107 // TypedArray
68- getPrototypeOf ( Uint8Array ) ,
108+ ObjectGetPrototypeOf ( Uint8Array ) ,
69109
70110 // 19 Fundamental Objects
71111 Object . prototype , // 19.1
@@ -129,33 +169,37 @@ module.exports = function() {
129169 const intrinsics = [
130170 // Anonymous Intrinsics
131171 // ThrowTypeError
132- getOwnPropertyDescriptor ( Function . prototype , 'caller' ) . get ,
172+ ObjectGetOwnPropertyDescriptor ( Function . prototype , 'caller' ) . get ,
133173 // IteratorPrototype
134- getPrototypeOf (
135- getPrototypeOf ( new Array ( ) [ Symbol . iterator ] ( ) )
174+ ObjectGetPrototypeOf (
175+ ObjectGetPrototypeOf ( new Array ( ) [ SymbolIterator ] ( ) )
136176 ) ,
137177 // ArrayIteratorPrototype
138- getPrototypeOf ( new Array ( ) [ Symbol . iterator ] ( ) ) ,
178+ ObjectGetPrototypeOf ( new Array ( ) [ SymbolIterator ] ( ) ) ,
139179 // StringIteratorPrototype
140- getPrototypeOf ( new String ( ) [ Symbol . iterator ] ( ) ) ,
180+ ObjectGetPrototypeOf ( new String ( ) [ SymbolIterator ] ( ) ) ,
141181 // MapIteratorPrototype
142- getPrototypeOf ( new Map ( ) [ Symbol . iterator ] ( ) ) ,
182+ ObjectGetPrototypeOf ( new Map ( ) [ SymbolIterator ] ( ) ) ,
143183 // SetIteratorPrototype
144- getPrototypeOf ( new Set ( ) [ Symbol . iterator ] ( ) ) ,
184+ ObjectGetPrototypeOf ( new Set ( ) [ SymbolIterator ] ( ) ) ,
145185 // GeneratorFunction
146- getPrototypeOf ( function * ( ) { } ) ,
186+ ObjectGetPrototypeOf ( function * ( ) { } ) ,
147187 // AsyncFunction
148- getPrototypeOf ( async function ( ) { } ) ,
188+ ObjectGetPrototypeOf ( async function ( ) { } ) ,
149189 // AsyncGeneratorFunction
150- getPrototypeOf ( async function * ( ) { } ) ,
190+ ObjectGetPrototypeOf ( async function * ( ) { } ) ,
151191 // TypedArray
152- getPrototypeOf ( Uint8Array ) ,
192+ ObjectGetPrototypeOf ( Uint8Array ) ,
153193
154194 // 18 The Global Object
155195 eval ,
196+ // eslint-disable-next-line node-core/prefer-primordials
156197 isFinite ,
198+ // eslint-disable-next-line node-core/prefer-primordials
157199 isNaN ,
200+ // eslint-disable-next-line node-core/prefer-primordials
158201 parseFloat ,
202+ // eslint-disable-next-line node-core/prefer-primordials
159203 parseInt ,
160204 decodeURI ,
161205 decodeURIComponent ,
@@ -289,16 +333,16 @@ module.exports = function() {
289333 // Object are verified before being enqueued,
290334 // therefore this is a valid candidate.
291335 // Throws if this fails (strict mode).
292- freeze ( obj ) ;
336+ ObjectFreeze ( obj ) ;
293337
294338 // We rely upon certain commitments of Object.freeze and proxies here
295339
296340 // Get stable/immutable outbound links before a Proxy has a chance to do
297341 // something sneaky.
298- const proto = getPrototypeOf ( obj ) ;
299- const descs = getOwnPropertyDescriptors ( obj ) ;
342+ const proto = ObjectGetPrototypeOf ( obj ) ;
343+ const descs = ObjectGetOwnPropertyDescriptors ( obj ) ;
300344 enqueue ( proto ) ;
301- ownKeys ( descs ) . forEach ( ( name ) => {
345+ ArrayPrototypeForEach ( ReflectOwnKeys ( descs ) , ( name ) => {
302346 // TODO: Uncurried form
303347 // TODO: getOwnPropertyDescriptors is guaranteed to return well-formed
304348 // descriptors, but they still inherit from Object.prototype. If
@@ -378,10 +422,10 @@ module.exports = function() {
378422 `Cannot assign to read only property '${ prop } ' of object '${ obj } '`
379423 ) ;
380424 }
381- if ( objectHasOwnProperty . call ( this , prop ) ) {
425+ if ( ObjectPrototypeHasOwnProperty ( this , prop ) ) {
382426 this [ prop ] = newValue ;
383427 } else {
384- defineProperty ( this , prop , {
428+ ObjectDefineProperty ( this , prop , {
385429 value : newValue ,
386430 writable : true ,
387431 enumerable : true ,
@@ -390,7 +434,7 @@ module.exports = function() {
390434 }
391435 }
392436
393- defineProperty ( obj , prop , {
437+ ObjectDefineProperty ( obj , prop , {
394438 get : getter ,
395439 set : setter ,
396440 enumerable : desc . enumerable ,
@@ -403,14 +447,14 @@ module.exports = function() {
403447 if ( ! obj ) {
404448 return ;
405449 }
406- const descs = getOwnPropertyDescriptors ( obj ) ;
450+ const descs = ObjectGetOwnPropertyDescriptors ( obj ) ;
407451 if ( ! descs ) {
408452 return ;
409453 }
410- getOwnPropertyNames ( obj ) . forEach ( ( prop ) => {
454+ ArrayPrototypeForEach ( ObjectGetOwnPropertyNames ( obj ) , ( prop ) => {
411455 return enableDerivedOverride ( obj , prop , descs [ prop ] ) ;
412456 } ) ;
413- getOwnPropertySymbols ( obj ) . forEach ( ( prop ) => {
457+ ArrayPrototypeForEach ( ObjectGetOwnPropertySymbols ( obj ) , ( prop ) => {
414458 return enableDerivedOverride ( obj , prop , descs [ prop ] ) ;
415459 } ) ;
416460 }
0 commit comments