Skip to content

Commit 6e853e7

Browse files
committed
bootstrap: freeze more intrinsics
1 parent 09c9e5d commit 6e853e7

File tree

2 files changed

+132
-105
lines changed

2 files changed

+132
-105
lines changed

lib/internal/freeze_intrinsics.js

Lines changed: 125 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
'use strict';
2424

2525
const {
26+
AggregateError,
27+
AggregateErrorPrototype,
2628
Array,
2729
ArrayBuffer,
2830
ArrayBufferPrototype,
31+
ArrayIteratorPrototype,
2932
ArrayPrototype,
3033
ArrayPrototypeForEach,
3134
ArrayPrototypePush,
@@ -45,6 +48,8 @@ const {
4548
ErrorPrototype,
4649
EvalError,
4750
EvalErrorPrototype,
51+
FinalizationRegistry,
52+
FinalizationRegistryPrototype,
4853
Float32Array,
4954
Float32ArrayPrototype,
5055
Float64Array,
@@ -84,9 +89,11 @@ const {
8489
Set,
8590
SetPrototype,
8691
String,
92+
StringIteratorPrototype,
8793
StringPrototype,
8894
Symbol,
8995
SymbolIterator,
96+
SymbolMatchAll,
9097
SyntaxError,
9198
SyntaxErrorPrototype,
9299
TypeError,
@@ -105,6 +112,8 @@ const {
105112
URIErrorPrototype,
106113
WeakMap,
107114
WeakMapPrototype,
115+
WeakRef,
116+
WeakRefPrototype,
108117
WeakSet,
109118
WeakSetPrototype,
110119
decodeURI,
@@ -124,52 +133,37 @@ module.exports = function() {
124133
} = require('timers');
125134

126135
const intrinsicPrototypes = [
127-
// Anonymous Intrinsics
128-
// IteratorPrototype
129-
ObjectGetPrototypeOf(
130-
ObjectGetPrototypeOf(new Array()[SymbolIterator]())
131-
),
132-
// ArrayIteratorPrototype
133-
ObjectGetPrototypeOf(new Array()[SymbolIterator]()),
134-
// StringIteratorPrototype
135-
ObjectGetPrototypeOf(new String()[SymbolIterator]()),
136-
// MapIteratorPrototype
137-
ObjectGetPrototypeOf(new Map()[SymbolIterator]()),
138-
// SetIteratorPrototype
139-
ObjectGetPrototypeOf(new Set()[SymbolIterator]()),
140-
// GeneratorFunction
141-
ObjectGetPrototypeOf(function* () {}),
142-
// AsyncFunction
143-
ObjectGetPrototypeOf(async function() {}),
144-
// AsyncGeneratorFunction
145-
ObjectGetPrototypeOf(async function* () {}),
146-
// TypedArray
147-
TypedArrayPrototype,
148-
149-
// 19 Fundamental Objects
150-
ObjectPrototype, // 19.1
151-
FunctionPrototype, // 19.2
152-
BooleanPrototype, // 19.3
136+
// 21 Fundamental Objects
137+
ObjectPrototype, // 20.1
138+
FunctionPrototype, // 20.2
139+
BooleanPrototype, // 20.3
153140

154-
ErrorPrototype, // 19.5
141+
ErrorPrototype, // 20.5
142+
AggregateErrorPrototype,
155143
EvalErrorPrototype,
156144
RangeErrorPrototype,
157145
ReferenceErrorPrototype,
158146
SyntaxErrorPrototype,
159147
TypeErrorPrototype,
160148
URIErrorPrototype,
161149

162-
// 20 Numbers and Dates
163-
NumberPrototype, // 20.1
164-
DatePrototype, // 20.3
150+
// 21 Numbers and Dates
151+
NumberPrototype, // 21.1
152+
BigIntPrototype, // 21.2
153+
DatePrototype, // 21.4
165154

166-
// 21 Text Processing
167-
StringPrototype, // 21.1
168-
RegExpPrototype, // 21.2
155+
// 22 Text Processing
156+
StringPrototype, // 22.1
157+
StringIteratorPrototype, // 22.1.5
158+
RegExpPrototype, // 22.2
159+
// 22.2.7 RegExpStringIteratorPrototype
160+
ObjectGetPrototypeOf(/e/[SymbolMatchAll]()),
169161

170-
// 22 Indexed Collections
171-
ArrayPrototype, // 22.1
162+
// 23 Indexed Collections
163+
ArrayPrototype, // 23.1
164+
ArrayIteratorPrototype, // 23.1.5
172165

166+
TypedArrayPrototype, // 23.2
173167
Int8ArrayPrototype,
174168
Uint8ArrayPrototype,
175169
Uint8ClampedArrayPrototype,
@@ -182,55 +176,52 @@ module.exports = function() {
182176
BigInt64ArrayPrototype,
183177
BigUint64ArrayPrototype,
184178

185-
// 23 Keyed Collections
186-
MapPrototype, // 23.1
187-
SetPrototype, // 23.2
188-
WeakMapPrototype, // 23.3
189-
WeakSetPrototype, // 23.4
190-
191-
// 24 Structured Data
192-
ArrayBufferPrototype, // 24.1
193-
DataViewPrototype, // 24.3
194-
PromisePrototype, // 25.4
179+
// 24 Keyed Collections
180+
MapPrototype, // 24.1
181+
// 24.1.5 MapIteratorPrototype
182+
ObjectGetPrototypeOf(new Map()[SymbolIterator]()),
183+
SetPrototype, // 24.2
184+
// 24.2.5 SetIteratorPrototype
185+
ObjectGetPrototypeOf(new Set()[SymbolIterator]()),
186+
WeakMapPrototype, // 24.3
187+
WeakSetPrototype, // 24.4
188+
189+
// 25 Structured Data
190+
ArrayBufferPrototype, // 25.1
191+
SharedArrayBuffer.prototype, // 25.2
192+
DataViewPrototype, // 25.3
193+
194+
// 26 Managing Memory
195+
WeakRefPrototype, // 26.1
196+
FinalizationRegistryPrototype, // 26.2
197+
198+
// 27 Control Abstraction Objects
199+
// 27.1 Iteration
200+
ObjectGetPrototypeOf(ArrayIteratorPrototype), // 27.1.2 IteratorPrototype
201+
// 27.1.3 AsyncIteratorPrototype
202+
ObjectGetPrototypeOf(ObjectGetPrototypeOf(ObjectGetPrototypeOf(
203+
(async function*() {})()
204+
))),
205+
PromisePrototype, // 27.2
195206

196207
// Other APIs / Web Compatibility
197208
console.Console.prototype,
198-
BigIntPrototype,
199209
WebAssembly.Module.prototype,
200210
WebAssembly.Instance.prototype,
201211
WebAssembly.Table.prototype,
202212
WebAssembly.Memory.prototype,
203213
WebAssembly.CompileError.prototype,
204214
WebAssembly.LinkError.prototype,
205215
WebAssembly.RuntimeError.prototype,
206-
SharedArrayBuffer.prototype,
207216
];
208217
const intrinsics = [
209-
// Anonymous Intrinsics
210-
// ThrowTypeError
218+
// 10.2.4.1 ThrowTypeError
211219
ObjectGetOwnPropertyDescriptor(FunctionPrototype, 'caller').get,
212-
// IteratorPrototype
213-
ObjectGetPrototypeOf(
214-
ObjectGetPrototypeOf(new Array()[SymbolIterator]())
215-
),
216-
// ArrayIteratorPrototype
217-
ObjectGetPrototypeOf(new Array()[SymbolIterator]()),
218-
// StringIteratorPrototype
219-
ObjectGetPrototypeOf(new String()[SymbolIterator]()),
220-
// MapIteratorPrototype
221-
ObjectGetPrototypeOf(new Map()[SymbolIterator]()),
222-
// SetIteratorPrototype
223-
ObjectGetPrototypeOf(new Set()[SymbolIterator]()),
224-
// GeneratorFunction
225-
ObjectGetPrototypeOf(function* () {}),
226-
// AsyncFunction
227-
ObjectGetPrototypeOf(async function() {}),
228-
// AsyncGeneratorFunction
229-
ObjectGetPrototypeOf(async function* () {}),
230-
// TypedArray
231-
TypedArray,
232220

233-
// 18 The Global Object
221+
// 19 The Global Object
222+
// 19.1 Value Properties of the Global Object
223+
globalThis, // eslint-disable-line no-restricted-globals
224+
// 19.2 Function Properties of the Global Object
234225
eval,
235226
// eslint-disable-next-line node-core/prefer-primordials
236227
isFinite,
@@ -240,38 +231,46 @@ module.exports = function() {
240231
parseFloat,
241232
// eslint-disable-next-line node-core/prefer-primordials
242233
parseInt,
234+
// 19.2.6 URI Handling Functions
243235
decodeURI,
244236
decodeURIComponent,
245237
encodeURI,
246238
encodeURIComponent,
247239

248-
// 19 Fundamental Objects
249-
Object, // 19.1
250-
Function, // 19.2
251-
Boolean, // 19.3
252-
Symbol, // 19.4
240+
// 20 Fundamental Objects
241+
Object, // 20.1
242+
Function, // 20.2
243+
Boolean, // 20.3
244+
Symbol, // 20.4
253245

254-
Error, // 19.5
246+
Error, // 20.5
247+
AggregateError,
255248
EvalError,
256249
RangeError,
257250
ReferenceError,
258251
SyntaxError,
259252
TypeError,
260253
URIError,
261254

262-
// 20 Numbers and Dates
263-
Number, // 20.1
255+
// 21 Numbers and Dates
256+
Number, // 21.1
257+
BigInt, // 21.2
264258
// eslint-disable-next-line node-core/prefer-primordials
265-
Math, // 20.2
266-
Date, // 20.3
267-
268-
// 21 Text Processing
269-
String, // 21.1
270-
RegExp, // 21.2
271-
272-
// 22 Indexed Collections
273-
Array, // 22.1
274-
259+
Math, // 21.3
260+
Date, // 21.4
261+
262+
// 22 Text Processing
263+
String, // 22.1
264+
StringIteratorPrototype, // 22.1.5
265+
RegExp, // 22.2
266+
// 22.2.7 RegExpStringIteratorPrototype
267+
ObjectGetPrototypeOf(/e/[SymbolMatchAll]()),
268+
269+
// 23 Indexed Collections
270+
Array, // 23.1
271+
ArrayIteratorPrototype, // 23.1.5
272+
// 23.2 TypedArray
273+
TypedArray,
275274
Int8Array,
276275
Uint8Array,
277276
Uint8ClampedArray,
@@ -284,23 +283,47 @@ module.exports = function() {
284283
BigInt64Array,
285284
BigUint64Array,
286285

287-
// 23 Keyed Collections
288-
Map, // 23.1
289-
Set, // 23.2
290-
WeakMap, // 23.3
291-
WeakSet, // 23.4
292-
293-
// 24 Structured Data
294-
ArrayBuffer, // 24.1
295-
DataView, // 24.3
286+
// 24 Keyed Collections
287+
Map, // 24.1
288+
// 24.1.5 MapIteratorPrototype
289+
ObjectGetPrototypeOf(new Map()[SymbolIterator]()),
290+
Set, // 24.2
291+
// 24.2.5 SetIteratorPrototype
292+
ObjectGetPrototypeOf(new Set()[SymbolIterator]()),
293+
WeakMap, // 24.3
294+
WeakSet, // 24.4
295+
296+
// 25 Structured Data
297+
ArrayBuffer, // 25.1
298+
SharedArrayBuffer, // 25.2
299+
DataView, // 25.3
300+
Atomics, // 25.4
296301
// eslint-disable-next-line node-core/prefer-primordials
297-
JSON, // 24.5
298-
Promise, // 25.4
302+
JSON, // 25.5
303+
304+
// 26 Managing Memory
305+
WeakRef, // 26.1
306+
FinalizationRegistry, // 26.2
307+
308+
// 27 Control Abstraction Objects
309+
// 27.1 Iteration
310+
ObjectGetPrototypeOf(ArrayIteratorPrototype), // 27.1.2 IteratorPrototype
311+
// 27.1.3 AsyncIteratorPrototype
312+
ObjectGetPrototypeOf(ObjectGetPrototypeOf(ObjectGetPrototypeOf(
313+
(async function*() {})()
314+
))),
315+
Promise, // 27.2
316+
// 27.3 GeneratorFunction
317+
ObjectGetPrototypeOf(function* () {}),
318+
// 27.4 AsyncGeneratorFunction
319+
ObjectGetPrototypeOf(async function* () {}),
320+
// 27.7 AsyncFunction
321+
ObjectGetPrototypeOf(async function() {}),
299322

300-
// 26 Reflection
323+
// 28 Reflection
301324
// eslint-disable-next-line node-core/prefer-primordials
302-
Reflect, // 26.1
303-
Proxy, // 26.2
325+
Reflect, // 28.1
326+
Proxy, // 28.2
304327

305328
// B.2.1
306329
escape,
@@ -314,10 +337,7 @@ module.exports = function() {
314337
setInterval,
315338
setTimeout,
316339
console,
317-
BigInt,
318-
Atomics,
319340
WebAssembly,
320-
SharedArrayBuffer,
321341
];
322342

323343
if (typeof Intl !== 'undefined') {

test/parallel/test-freeze-intrinsics.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@ assert.throws(
3030
assert.strictEqual(Object.getOwnPropertyDescriptor(o, 'toString').enumerable,
3131
true);
3232
}
33+
34+
// Ensure we can not override globalThis
35+
{
36+
assert.throws(() => { globalThis.globalThis = null; },
37+
{ name: 'TypeError' });
38+
assert.notStrictEqual(globalThis, null);
39+
}

0 commit comments

Comments
 (0)