@@ -22,7 +22,7 @@ test('scope behavior - lookup behavior', t => {
2222 t . is ( evaluate ( 'globalThis' ) , undefined ) ;
2323 t . is ( evaluate ( 'eval' ) , undefined ) ;
2424 t . is ( evaluate ( 'realmGlobalProp' ) , undefined ) ;
25- t . throws ( ( ) => evaluate ( 'missingProp' ) , { instanceOf : ReferenceError } ) ;
25+ t . is ( evaluate ( 'missingProp' ) , undefined ) ;
2626
2727 t . is ( evaluate ( 'globalProp' ) , globalObject . globalProp ) ;
2828 t . is ( evaluate ( 'lexicalProp' ) , moduleLexicals . lexicalProp ) ;
@@ -279,39 +279,35 @@ test('scope behavior - strict vs sloppy locally non-existing global set', t => {
279279 t . notThrows ( ( ) => evaluateSloppy ( 'missingRealmGlobalProp = 456' ) ) ;
280280} ) ;
281281
282- test ( 'scope behavior - realm globalThis property info leak' , t => {
282+ test ( 'scope behavior - no realm globalThis property info leak' , t => {
283283 t . plan ( 8 ) ;
284284
285285 const globalObject = { } ;
286286 const { safeEvaluate : evaluate } = makeSafeEvaluator ( {
287287 globalObject,
288288 } ) ;
289289
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 ( ) ;
298300
299301 globalThis . eventuallyAssignedRealmGlobalProp = { } ;
300302 t . teardown ( ( ) => {
301303 delete globalThis . eventuallyAssignedRealmGlobalProp ;
302304 } ) ;
303305
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 ( ) ;
311307} ) ;
312308
313309test ( 'scope behavior - Symbol.unscopables fidelity test' , t => {
314- t . plan ( 33 ) ;
310+ t . plan ( 41 ) ;
315311
316312 const globalObject = {
317313 Symbol,
@@ -325,81 +321,49 @@ test('scope behavior - Symbol.unscopables fidelity test', t => {
325321 globalObject,
326322 } ) ;
327323
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' ) ;
333329
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+ } ;
347338
339+ unvaryingAssertions ( ) ;
340+
341+ // Compartment should not be sensitive to existence of a host globalThis
342+ // property.
348343 globalThis . eventuallyAssignedRealmGlobalProp = { } ;
349344 t . teardown ( ( ) => {
350345 delete globalThis . eventuallyAssignedRealmGlobalProp ;
351346 } ) ;
352347
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 ( ) ;
371349
372350 evaluate (
373351 'this[Symbol.unscopables] = { eventuallyAssignedRealmGlobalProp: true, localProp: true, eventuallyAssignedLocalProp: true }' ,
374352 ) ;
375353 // after property is created on globalObject, assignment is evaluated to
376354 // test if it is affected by the Symbol.unscopables configuration
377355 globalObject . eventuallyAssignedLocalProp = null ;
378- // Known compromise in fidelity of the emulated script environment:
379- t . throws ( ( ) => evaluate ( 'eventuallyAssignedLocalProp = {}' ) , {
380- instanceOf : ReferenceError ,
381- } ) ;
382356
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 ( ) ;
389358
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 = {}' ) , {
399363 instanceOf : ReferenceError ,
400364 } ) ;
401- // Known compromise in fidelity of the emulated script environment:
402- t . is ( evaluate ( 'eventuallyAssignedRealmGlobalProp' ) , undefined ) ;
365+
366+ unvaryingAssertions ( ) ;
403367
404368 // move "Symbol.unscopables" to prototype
405369 delete globalObject [ Symbol . unscopables ] ;
@@ -410,24 +374,5 @@ test('scope behavior - Symbol.unscopables fidelity test', t => {
410374 eventuallyAssignedLocalProp : true ,
411375 } ;
412376
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 ( ) ;
433378} ) ;
0 commit comments