Skip to content

Commit 386776d

Browse files
committed
bootstrap: freeze more intrinsics
1 parent 7216eb6 commit 386776d

File tree

2 files changed

+126
-91
lines changed

2 files changed

+126
-91
lines changed

lib/internal/freeze_intrinsics.js

Lines changed: 119 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
'use strict';
2424

2525
const {
26+
AggregateError,
27+
AggregateErrorPrototype,
2628
Array,
2729
ArrayBuffer,
2830
ArrayBufferPrototype,
@@ -45,6 +47,8 @@ const {
4547
ErrorPrototype,
4648
EvalError,
4749
EvalErrorPrototype,
50+
FinalizationRegistry,
51+
FinalizationRegistryPrototype,
4852
Float32Array,
4953
Float32ArrayPrototype,
5054
Float64Array,
@@ -87,6 +91,7 @@ const {
8791
StringPrototype,
8892
Symbol,
8993
SymbolIterator,
94+
SymbolMatchAll,
9095
SyntaxError,
9196
SyntaxErrorPrototype,
9297
TypeError,
@@ -105,6 +110,8 @@ const {
105110
URIErrorPrototype,
106111
WeakMap,
107112
WeakMapPrototype,
113+
WeakRef,
114+
WeakRefPrototype,
108115
WeakSet,
109116
WeakSetPrototype,
110117
decodeURI,
@@ -125,51 +132,43 @@ module.exports = function() {
125132

126133
const intrinsicPrototypes = [
127134
// Anonymous Intrinsics
128-
// IteratorPrototype
129-
ObjectGetPrototypeOf(
130-
ObjectGetPrototypeOf(new Array()[SymbolIterator]())
131-
),
132-
// ArrayIteratorPrototype
135+
// 23.1.5 ArrayIteratorPrototype
133136
ObjectGetPrototypeOf(new Array()[SymbolIterator]()),
134-
// StringIteratorPrototype
137+
// 22.1.5 StringIteratorPrototype
135138
ObjectGetPrototypeOf(new String()[SymbolIterator]()),
136-
// MapIteratorPrototype
139+
// 24.1.5 MapIteratorPrototype
137140
ObjectGetPrototypeOf(new Map()[SymbolIterator]()),
138-
// SetIteratorPrototype
141+
// 24.2.5 SetIteratorPrototype
139142
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,
148143

149-
// 19 Fundamental Objects
150-
ObjectPrototype, // 19.1
151-
FunctionPrototype, // 19.2
152-
BooleanPrototype, // 19.3
144+
// 21 Fundamental Objects
145+
ObjectPrototype, // 20.1
146+
FunctionPrototype, // 20.2
147+
BooleanPrototype, // 20.3
153148

154-
ErrorPrototype, // 19.5
149+
ErrorPrototype, // 20.5
150+
AggregateErrorPrototype,
155151
EvalErrorPrototype,
156152
RangeErrorPrototype,
157153
ReferenceErrorPrototype,
158154
SyntaxErrorPrototype,
159155
TypeErrorPrototype,
160156
URIErrorPrototype,
161157

162-
// 20 Numbers and Dates
163-
NumberPrototype, // 20.1
164-
DatePrototype, // 20.3
158+
// 21 Numbers and Dates
159+
NumberPrototype, // 21.1
160+
BigIntPrototype, // 21.2
161+
DatePrototype, // 21.4
165162

166-
// 21 Text Processing
167-
StringPrototype, // 21.1
168-
RegExpPrototype, // 21.2
163+
// 22 Text Processing
164+
StringPrototype, // 22.1
165+
RegExpPrototype, // 22.2
166+
ObjectGetPrototypeOf(/e/[SymbolMatchAll]()), // 22.2.7 RegExpStringIteratorPrototype
169167

170-
// 22 Indexed Collections
171-
ArrayPrototype, // 22.1
168+
// 23 Indexed Collections
169+
ArrayPrototype, // 23.1
172170

171+
TypedArrayPrototype, // 23.2
173172
Int8ArrayPrototype,
174173
Uint8ArrayPrototype,
175174
Uint8ClampedArrayPrototype,
@@ -182,55 +181,60 @@ module.exports = function() {
182181
BigInt64ArrayPrototype,
183182
BigUint64ArrayPrototype,
184183

185-
// 23 Keyed Collections
186-
MapPrototype, // 23.1
187-
SetPrototype, // 23.2
188-
WeakMapPrototype, // 23.3
189-
WeakSetPrototype, // 23.4
184+
// 24 Keyed Collections
185+
MapPrototype, // 24.1
186+
SetPrototype, // 24.2
187+
WeakMapPrototype, // 24.3
188+
WeakSetPrototype, // 24.4
190189

191-
// 24 Structured Data
192-
ArrayBufferPrototype, // 24.1
193-
DataViewPrototype, // 24.3
194-
PromisePrototype, // 25.4
190+
// 25 Structured Data
191+
ArrayBufferPrototype, // 25.1
192+
SharedArrayBuffer.prototype, // 25.2
193+
DataViewPrototype, // 25.3
194+
195+
// 26 Managing Memory
196+
WeakRefPrototype, // 26.1
197+
FinalizationRegistryPrototype, // 26.2
198+
199+
// 27 Control Abstraction Objects
200+
// 27.1 Iteration
201+
// IteratorPrototype
202+
ObjectGetPrototypeOf(
203+
ObjectGetPrototypeOf(new Array()[SymbolIterator]())
204+
),
205+
// AsyncIteratorPrototype
206+
ObjectGetPrototypeOf(ObjectGetPrototypeOf(ObjectGetPrototypeOf(
207+
(async function*() {})()
208+
))),
209+
PromisePrototype, // 27.2
195210

196211
// Other APIs / Web Compatibility
197212
console.Console.prototype,
198-
BigIntPrototype,
199213
WebAssembly.Module.prototype,
200214
WebAssembly.Instance.prototype,
201215
WebAssembly.Table.prototype,
202216
WebAssembly.Memory.prototype,
203217
WebAssembly.CompileError.prototype,
204218
WebAssembly.LinkError.prototype,
205219
WebAssembly.RuntimeError.prototype,
206-
SharedArrayBuffer.prototype,
207220
];
208221
const intrinsics = [
209222
// Anonymous Intrinsics
210-
// ThrowTypeError
223+
// 10.2.4.1 ThrowTypeError
211224
ObjectGetOwnPropertyDescriptor(FunctionPrototype, 'caller').get,
212-
// IteratorPrototype
213-
ObjectGetPrototypeOf(
214-
ObjectGetPrototypeOf(new Array()[SymbolIterator]())
215-
),
216-
// ArrayIteratorPrototype
225+
// 23.1.5 ArrayIteratorPrototype
217226
ObjectGetPrototypeOf(new Array()[SymbolIterator]()),
218-
// StringIteratorPrototype
227+
// 22.1.5 StringIteratorPrototype
219228
ObjectGetPrototypeOf(new String()[SymbolIterator]()),
220-
// MapIteratorPrototype
229+
// 24.1.5 MapIteratorPrototype
221230
ObjectGetPrototypeOf(new Map()[SymbolIterator]()),
222-
// SetIteratorPrototype
231+
// 24.2.5 SetIteratorPrototype
223232
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,
232233

233-
// 18 The Global Object
234+
// 19 The Global Object
235+
// 19.1 Value Properties of the Global Object
236+
globalThis, // eslint-disable-line no-restricted-globals
237+
// 19.2 Function Properties of the Global Object
234238
eval,
235239
// eslint-disable-next-line node-core/prefer-primordials
236240
isFinite,
@@ -240,38 +244,42 @@ module.exports = function() {
240244
parseFloat,
241245
// eslint-disable-next-line node-core/prefer-primordials
242246
parseInt,
247+
// 19.2.6 URI Handling Functions
243248
decodeURI,
244249
decodeURIComponent,
245250
encodeURI,
246251
encodeURIComponent,
247252

248-
// 19 Fundamental Objects
249-
Object, // 19.1
250-
Function, // 19.2
251-
Boolean, // 19.3
252-
Symbol, // 19.4
253+
// 20 Fundamental Objects
254+
Object, // 20.1
255+
Function, // 20.2
256+
Boolean, // 20.3
257+
Symbol, // 20.4
253258

254-
Error, // 19.5
259+
Error, // 20.5
260+
AggregateError,
255261
EvalError,
256262
RangeError,
257263
ReferenceError,
258264
SyntaxError,
259265
TypeError,
260266
URIError,
261267

262-
// 20 Numbers and Dates
263-
Number, // 20.1
268+
// 21 Numbers and Dates
269+
Number, // 21.1
270+
BigInt, // 21.2
264271
// eslint-disable-next-line node-core/prefer-primordials
265-
Math, // 20.2
266-
Date, // 20.3
272+
Math, // 21.3
273+
Date, // 21.4
267274

268-
// 21 Text Processing
269-
String, // 21.1
270-
RegExp, // 21.2
271-
272-
// 22 Indexed Collections
273-
Array, // 22.1
275+
// 22 Text Processing
276+
String, // 22.1
277+
RegExp, // 22.2
274278

279+
// 23 Indexed Collections
280+
Array, // 23.1
281+
// 23.2 TypedArray
282+
TypedArray,
275283
Int8Array,
276284
Uint8Array,
277285
Uint8ClampedArray,
@@ -284,23 +292,46 @@ module.exports = function() {
284292
BigInt64Array,
285293
BigUint64Array,
286294

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
295+
// 24 Keyed Collections
296+
Map, // 24.1
297+
Set, // 24.2
298+
WeakMap, // 24.3
299+
WeakSet, // 24.4
300+
301+
// 25 Structured Data
302+
ArrayBuffer, // 25.1
303+
SharedArrayBuffer, // 25.2
304+
DataView, // 25.3
305+
Atomics, // 25.4
296306
// eslint-disable-next-line node-core/prefer-primordials
297-
JSON, // 24.5
298-
Promise, // 25.4
307+
JSON, // 25.5
308+
309+
// 26 Managing Memory
310+
WeakRef, // 26.1
311+
FinalizationRegistry, // 26.2
312+
313+
// 27 Control Abstraction Objects
314+
// 27.1 Iteration
315+
// IteratorPrototype
316+
ObjectGetPrototypeOf(
317+
ObjectGetPrototypeOf(new Array()[SymbolIterator]())
318+
),
319+
// AsyncIteratorPrototype
320+
ObjectGetPrototypeOf(ObjectGetPrototypeOf(ObjectGetPrototypeOf(
321+
(async function*() {})()
322+
))),
323+
Promise, // 27.2
324+
// 27.3 GeneratorFunction
325+
ObjectGetPrototypeOf(function* () {}),
326+
// 27.4 AsyncGeneratorFunction
327+
ObjectGetPrototypeOf(async function* () {}),
328+
// 27.7 AsyncFunction
329+
ObjectGetPrototypeOf(async function() {}),
299330

300-
// 26 Reflection
331+
// 28 Reflection
301332
// eslint-disable-next-line node-core/prefer-primordials
302-
Reflect, // 26.1
303-
Proxy, // 26.2
333+
Reflect, // 28.1
334+
Proxy, // 28.2
304335

305336
// B.2.1
306337
escape,
@@ -314,10 +345,7 @@ module.exports = function() {
314345
setInterval,
315346
setTimeout,
316347
console,
317-
BigInt,
318-
Atomics,
319348
WebAssembly,
320-
SharedArrayBuffer,
321349
];
322350

323351
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)