@@ -22,7 +22,7 @@ test('scope behavior - lookup behavior', t => {
22
22
t . is ( evaluate ( 'globalThis' ) , undefined ) ;
23
23
t . is ( evaluate ( 'eval' ) , undefined ) ;
24
24
t . is ( evaluate ( 'realmGlobalProp' ) , undefined ) ;
25
- t . throws ( ( ) => evaluate ( 'missingProp' ) , { instanceOf : ReferenceError } ) ;
25
+ t . is ( evaluate ( 'missingProp' ) , undefined ) ;
26
26
27
27
t . is ( evaluate ( 'globalProp' ) , globalObject . globalProp ) ;
28
28
t . is ( evaluate ( 'lexicalProp' ) , moduleLexicals . lexicalProp ) ;
@@ -279,39 +279,35 @@ test('scope behavior - strict vs sloppy locally non-existing global set', t => {
279
279
t . notThrows ( ( ) => evaluateSloppy ( 'missingRealmGlobalProp = 456' ) ) ;
280
280
} ) ;
281
281
282
- test ( 'scope behavior - realm globalThis property info leak' , t => {
282
+ test ( 'scope behavior - no realm globalThis property info leak' , t => {
283
283
t . plan ( 8 ) ;
284
284
285
285
const globalObject = { } ;
286
286
const { safeEvaluate : evaluate } = makeSafeEvaluator ( {
287
287
globalObject,
288
288
} ) ;
289
289
290
- t . is ( evaluate ( 'typeof missingRealmGlobalProp' ) , 'undefined' ) ;
291
- t . is ( evaluate ( 'typeof eventuallyAssignedRealmGlobalProp' ) , 'undefined' ) ;
292
- t . throws ( ( ) => evaluate ( 'missingRealmGlobalProp' ) , {
293
- instanceOf : ReferenceError ,
294
- } ) ;
295
- t . throws ( ( ) => evaluate ( 'eventuallyAssignedRealmGlobalProp' ) , {
296
- instanceOf : ReferenceError ,
297
- } ) ;
290
+ const unvaryingAssertions = ( ) => {
291
+ t . is ( evaluate ( 'typeof missingRealmGlobalProp' ) , 'undefined' ) ;
292
+ t . is ( evaluate ( 'typeof eventuallyAssignedRealmGlobalProp' ) , 'undefined' ) ;
293
+ // Known loss of fidelity to native Hardened JavaScript: we expect a
294
+ // ReferenceError for accessing a missing lexical name.
295
+ t . is ( evaluate ( 'missingRealmGlobalProp' ) , undefined ) ;
296
+ t . is ( evaluate ( 'eventuallyAssignedRealmGlobalProp' ) , undefined ) ;
297
+ } ;
298
+
299
+ unvaryingAssertions ( ) ;
298
300
299
301
globalThis . eventuallyAssignedRealmGlobalProp = { } ;
300
302
t . teardown ( ( ) => {
301
303
delete globalThis . eventuallyAssignedRealmGlobalProp ;
302
304
} ) ;
303
305
304
- t . is ( evaluate ( 'typeof missingRealmGlobalProp' ) , 'undefined' ) ;
305
- t . is ( evaluate ( 'typeof eventuallyAssignedRealmGlobalProp' ) , 'undefined' ) ;
306
- t . throws ( ( ) => evaluate ( 'missingRealmGlobalProp' ) , {
307
- instanceOf : ReferenceError ,
308
- } ) ;
309
- // Known compromise in fidelity of the emulated script environment:
310
- t . is ( evaluate ( 'eventuallyAssignedRealmGlobalProp' ) , undefined ) ;
306
+ unvaryingAssertions ( ) ;
311
307
} ) ;
312
308
313
309
test ( 'scope behavior - Symbol.unscopables fidelity test' , t => {
314
- t . plan ( 33 ) ;
310
+ t . plan ( 41 ) ;
315
311
316
312
const globalObject = {
317
313
Symbol,
@@ -325,81 +321,49 @@ test('scope behavior - Symbol.unscopables fidelity test', t => {
325
321
globalObject,
326
322
} ) ;
327
323
328
- // Known compromise in fidelity of the emulated script environment:
329
- t . is ( evaluate ( 'typeof localProp' ) , 'undefined' ) ;
330
- t . is ( evaluate ( 'typeof eventuallyAssignedLocalProp' ) , 'undefined' ) ;
331
- t . is ( evaluate ( 'typeof missingRealmGlobalProp' ) , 'undefined' ) ;
332
- t . is ( evaluate ( 'typeof eventuallyAssignedRealmGlobalProp' ) , 'undefined' ) ;
324
+ const unvaryingAssertions = ( ) => {
325
+ t . is ( evaluate ( 'typeof localProp' ) , 'undefined' ) ;
326
+ t . is ( evaluate ( 'typeof eventuallyAssignedLocalProp' ) , 'undefined' ) ;
327
+ t . is ( evaluate ( 'typeof missingRealmGlobalProp' ) , 'undefined' ) ;
328
+ t . is ( evaluate ( 'typeof eventuallyAssignedRealmGlobalProp' ) , 'undefined' ) ;
333
329
334
- // Known compromise in fidelity of the emulated script environment:
335
- t . throws ( ( ) => evaluate ( 'localProp' ) , {
336
- instanceOf : ReferenceError ,
337
- } ) ;
338
- t . throws ( ( ) => evaluate ( 'eventuallyAssignedLocalProp' ) , {
339
- instanceOf : ReferenceError ,
340
- } ) ;
341
- t . throws ( ( ) => evaluate ( 'missingRealmGlobalProp' ) , {
342
- instanceOf : ReferenceError ,
343
- } ) ;
344
- t . throws ( ( ) => evaluate ( 'eventuallyAssignedRealmGlobalProp' ) , {
345
- instanceOf : ReferenceError ,
346
- } ) ;
330
+ // Known compromise in fidelity of the emulated script environment:
331
+ // In a native Hardened JavaScript, we would expect these to throw
332
+ // ReferenceError.
333
+ t . is ( evaluate ( 'localProp' ) , undefined ) ;
334
+ t . is ( evaluate ( 'eventuallyAssignedLocalProp' ) , undefined ) ;
335
+ t . is ( evaluate ( 'missingRealmGlobalProp' ) , undefined ) ;
336
+ t . is ( evaluate ( 'eventuallyAssignedRealmGlobalProp' ) , undefined ) ;
337
+ } ;
347
338
339
+ unvaryingAssertions ( ) ;
340
+
341
+ // Compartment should not be sensitive to existence of a host globalThis
342
+ // property.
348
343
globalThis . eventuallyAssignedRealmGlobalProp = { } ;
349
344
t . teardown ( ( ) => {
350
345
delete globalThis . eventuallyAssignedRealmGlobalProp ;
351
346
} ) ;
352
347
353
- // Known compromise in fidelity of the emulated script environment:
354
- t . is ( evaluate ( 'typeof localProp' ) , 'undefined' ) ;
355
- t . is ( evaluate ( 'typeof eventuallyAssignedLocalProp' ) , 'undefined' ) ;
356
- t . is ( evaluate ( 'typeof missingRealmGlobalProp' ) , 'undefined' ) ;
357
- t . is ( evaluate ( 'typeof eventuallyAssignedRealmGlobalProp' ) , 'undefined' ) ;
358
-
359
- // Known compromise in fidelity of the emulated script environment:
360
- t . throws ( ( ) => evaluate ( 'localProp' ) , {
361
- instanceOf : ReferenceError ,
362
- } ) ;
363
- t . throws ( ( ) => evaluate ( 'eventuallyAssignedLocalProp' ) , {
364
- instanceOf : ReferenceError ,
365
- } ) ;
366
- t . throws ( ( ) => evaluate ( 'missingRealmGlobalProp' ) , {
367
- instanceOf : ReferenceError ,
368
- } ) ;
369
- // Known compromise in fidelity of the emulated script environment:
370
- t . is ( evaluate ( 'eventuallyAssignedRealmGlobalProp' ) , undefined ) ;
348
+ unvaryingAssertions ( ) ;
371
349
372
350
evaluate (
373
351
'this[Symbol.unscopables] = { eventuallyAssignedRealmGlobalProp: true, localProp: true, eventuallyAssignedLocalProp: true }' ,
374
352
) ;
375
353
// after property is created on globalObject, assignment is evaluated to
376
354
// test if it is affected by the Symbol.unscopables configuration
377
355
globalObject . eventuallyAssignedLocalProp = null ;
378
- // Known compromise in fidelity of the emulated script environment:
379
- t . throws ( ( ) => evaluate ( 'eventuallyAssignedLocalProp = {}' ) , {
380
- instanceOf : ReferenceError ,
381
- } ) ;
382
356
383
- // Known compromise in fidelity of the emulated script environment:
384
- t . is ( evaluate ( 'typeof localProp' ) , 'undefined' ) ;
385
- // Known compromise in fidelity of the emulated script environment:
386
- t . is ( evaluate ( 'typeof eventuallyAssignedLocalProp' ) , 'undefined' ) ;
387
- t . is ( evaluate ( 'typeof missingRealmGlobalProp' ) , 'undefined' ) ;
388
- t . is ( evaluate ( 'typeof eventuallyAssignedRealmGlobalProp' ) , 'undefined' ) ;
357
+ unvaryingAssertions ( ) ;
389
358
390
- // Known compromise in fidelity of the emulated script environment:
391
- t . throws ( ( ) => evaluate ( 'localProp' ) , {
392
- instanceOf : ReferenceError ,
393
- } ) ;
394
- // Known compromise in fidelity of the emulated script environment:
395
- t . throws ( ( ) => evaluate ( 'eventuallyAssignedLocalProp' ) , {
396
- instanceOf : ReferenceError ,
397
- } ) ;
398
- t . throws ( ( ) => evaluate ( 'missingRealmGlobalProp' ) , {
359
+ // Known compromise in fidelity to native Hardened JavaScript:
360
+ // We expect implicit assignment on globalThis to fail in strict mode but not
361
+ // in sloppy mode.
362
+ t . throws ( ( ) => evaluate ( 'eventuallyAssignedLocalProp = {}' ) , {
399
363
instanceOf : ReferenceError ,
400
364
} ) ;
401
- // Known compromise in fidelity of the emulated script environment:
402
- t . is ( evaluate ( 'eventuallyAssignedRealmGlobalProp' ) , undefined ) ;
365
+
366
+ unvaryingAssertions ( ) ;
403
367
404
368
// move "Symbol.unscopables" to prototype
405
369
delete globalObject [ Symbol . unscopables ] ;
@@ -410,24 +374,5 @@ test('scope behavior - Symbol.unscopables fidelity test', t => {
410
374
eventuallyAssignedLocalProp : true ,
411
375
} ;
412
376
413
- // Known compromise in fidelity of the emulated script environment:
414
- t . is ( evaluate ( 'typeof localProp' ) , 'undefined' ) ;
415
- // Known compromise in fidelity of the emulated script environment:
416
- t . is ( evaluate ( 'typeof eventuallyAssignedLocalProp' ) , 'undefined' ) ;
417
- t . is ( evaluate ( 'typeof missingRealmGlobalProp' ) , 'undefined' ) ;
418
- t . is ( evaluate ( 'typeof eventuallyAssignedRealmGlobalProp' ) , 'undefined' ) ;
419
-
420
- // Known compromise in fidelity of the emulated script environment:
421
- t . throws ( ( ) => evaluate ( 'localProp' ) , {
422
- instanceOf : ReferenceError ,
423
- } ) ;
424
- // Known compromise in fidelity of the emulated script environment:
425
- t . throws ( ( ) => evaluate ( 'eventuallyAssignedLocalProp' ) , {
426
- instanceOf : ReferenceError ,
427
- } ) ;
428
- t . throws ( ( ) => evaluate ( 'missingRealmGlobalProp' ) , {
429
- instanceOf : ReferenceError ,
430
- } ) ;
431
- // Known compromise in fidelity of the emulated script environment:
432
- t . is ( evaluate ( 'eventuallyAssignedRealmGlobalProp' ) , undefined ) ;
377
+ unvaryingAssertions ( ) ;
433
378
} ) ;
0 commit comments