@@ -110,13 +110,17 @@ test('some passStyleOf rejections', t => {
110
110
} ) ;
111
111
112
112
/**
113
- * For testing purposes, makes a TagRecord-like object with
113
+ * For testing purposes, makes a *non-frozen* TagRecord-like object with
114
114
* non-enumerable PASS_STYLE and Symbol.toStringTag properties.
115
115
* A valid Remotable must inherit from a valid TagRecord.
116
+ * - Before stabilize/suppressTrapping, a valid TagRecord must be frozen.
117
+ * - After stabilize/suppressTrapping, a valid TagRecord must also be
118
+ * stable/non-trapping, for example, because it was hardened.
116
119
*
117
120
* @param {string } [tag]
118
121
* @param {object|null } [proto]
119
122
* @returns {{ [PASS_STYLE]: 'remotable', [Symbol.toStringTag]: string } }
123
+ * @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
120
124
*/
121
125
const makeTagishRecord = ( tag = 'Remotable' , proto = undefined ) => {
122
126
return Object . create ( proto === undefined ? Object . prototype : proto , {
@@ -193,16 +197,21 @@ test('passStyleOf testing remotables', t => {
193
197
194
198
const tagRecord1 = harden ( makeTagishRecord ( 'Alleged: manually constructed' ) ) ;
195
199
/** @type {any } UNTIL https://github.com/microsoft/TypeScript/issues/38385 */
200
+ // TODO Once we have support for explicit non-trapping, this should change
201
+ // from `harden` to `suppressTrapping` or `stabilize`.
196
202
const farObj1 = harden ( { __proto__ : tagRecord1 } ) ;
197
203
t . is ( passStyleOf ( farObj1 ) , 'remotable' ) ;
198
204
199
205
const tagRecord2 = makeTagishRecord ( 'Alleged: tagRecord not hardened' ) ;
200
206
/**
207
+ * Do not freeze `tagRecord2` in order to test that an object with
208
+ * a non-frozen __proto__ is not passable.
209
+ *
201
210
* TODO In order to run this test before we have explicit support for a
202
211
* non-trapping integrity trait, we have to `freeze` here but not `harden`.
203
212
* However, once we do have that support, and `passStyleOf` checks that
204
213
* its argument is also non-trapping, we still need to avoid `harden`
205
- * because that would also hardden `__proto__`. So we will need to
214
+ * because that would also harden `__proto__`. So we will need to
206
215
* explicitly make this non-trapping, which we cannot yet express.
207
216
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
208
217
*
@@ -220,24 +229,34 @@ test('passStyleOf testing remotables', t => {
220
229
221
230
const tagRecord3 = harden ( makeTagishRecord ( 'Alleged: both manually frozen' ) ) ;
222
231
/** @type {any } UNTIL https://github.com/microsoft/TypeScript/issues/38385 */
232
+ // TODO Once we have support for explicit non-trapping, this should change
233
+ // from `harden` to `suppressTrapping` or `stabilize`.
223
234
const farObj3 = harden ( { __proto__ : tagRecord3 } ) ;
224
235
t . is ( passStyleOf ( farObj3 ) , 'remotable' ) ;
225
236
226
237
const tagRecord4 = harden ( makeTagishRecord ( 'Remotable' ) ) ;
227
238
/** @type {any } UNTIL https://github.com/microsoft/TypeScript/issues/38385 */
239
+ // TODO Once we have support for explicit non-trapping, this should change
240
+ // from `harden` to `suppressTrapping` or `stabilize`.
228
241
const farObj4 = harden ( { __proto__ : tagRecord4 } ) ;
229
242
t . is ( passStyleOf ( farObj4 ) , 'remotable' ) ;
230
243
231
244
const tagRecord5 = harden ( makeTagishRecord ( 'Not alleging' ) ) ;
245
+ // TODO Once we have support for explicit non-trapping, this should change
246
+ // from `harden` to `suppressTrapping` or `stabilize`.
232
247
const farObj5 = harden ( { __proto__ : tagRecord5 } ) ;
233
248
t . throws ( ( ) => passStyleOf ( farObj5 ) , {
234
249
message :
235
250
/ F o r n o w , i f a c e " N o t a l l e g i n g " m u s t b e " R e m o t a b l e " o r b e g i n w i t h " A l l e g e d : " o r " D e b u g N a m e : " ; u n i m p l e m e n t e d / ,
236
251
} ) ;
237
252
238
253
const tagRecord6 = harden ( makeTagishRecord ( 'Alleged: manually constructed' ) ) ;
254
+ // TODO Once we have support for explicit non-trapping, this should change
255
+ // from `harden` to `suppressTrapping` or `stabilize`.
239
256
const farObjProto6 = harden ( { __proto__ : tagRecord6 } ) ;
240
257
/** @type {any } UNTIL https://github.com/microsoft/TypeScript/issues/38385 */
258
+ // TODO Once we have support for explicit non-trapping, this should change
259
+ // from `harden` to `suppressTrapping` or `stabilize`.
241
260
const farObj6 = harden ( { __proto__ : farObjProto6 } ) ;
242
261
t . is ( passStyleOf ( farObj6 ) , 'remotable' , 'tagRecord grandproto is accepted' ) ;
243
262
@@ -292,6 +311,8 @@ test('passStyleOf testing remotables', t => {
292
311
const tagRecordA1 = harden (
293
312
makeTagishRecord ( 'Alleged: null-proto tagRecord proto' , null ) ,
294
313
) ;
314
+ // TODO Once we have support for explicit non-trapping, this should change
315
+ // from `harden` to `suppressTrapping` or `stabilize`.
295
316
const farObjA1 = harden ( { __proto__ : tagRecordA1 } ) ;
296
317
t . throws (
297
318
( ) => passStyleOf ( farObjA1 ) ,
@@ -302,7 +323,11 @@ test('passStyleOf testing remotables', t => {
302
323
const tagRecordA2 = harden (
303
324
makeTagishRecord ( 'Alleged: null-proto tagRecord grandproto' , null ) ,
304
325
) ;
326
+ // TODO Once we have support for explicit non-trapping, this should change
327
+ // from `harden` to `suppressTrapping` or `stabilize`.
305
328
const farObjProtoA2 = harden ( { __proto__ : tagRecordA2 } ) ;
329
+ // TODO Once we have support for explicit non-trapping, this should change
330
+ // from `harden` to `suppressTrapping` or `stabilize`.
306
331
const farObjA2 = harden ( { __proto__ : farObjProtoA2 } ) ;
307
332
t . throws (
308
333
( ) => passStyleOf ( farObjA2 ) ,
@@ -317,7 +342,11 @@ test('passStyleOf testing remotables', t => {
317
342
const fauxTagRecordB = harden (
318
343
makeTagishRecord ( 'Alleged: manually constructed' , harden ( { } ) ) ,
319
344
) ;
345
+ // TODO Once we have support for explicit non-trapping, this should change
346
+ // from `harden` to `suppressTrapping` or `stabilize`.
320
347
const farObjProtoB = harden ( { __proto__ : fauxTagRecordB } ) ;
348
+ // TODO Once we have support for explicit non-trapping, this should change
349
+ // from `harden` to `suppressTrapping` or `stabilize`.
321
350
const farObjB = harden ( { __proto__ : farObjProtoB } ) ;
322
351
t . throws ( ( ) => passStyleOf ( farObjB ) , {
323
352
message :
@@ -329,6 +358,8 @@ test('passStyleOf testing remotables', t => {
329
358
) ;
330
359
Object . defineProperty ( farObjProtoWithExtra , 'extra' , { value : ( ) => { } } ) ;
331
360
harden ( farObjProtoWithExtra ) ;
361
+ // TODO Once we have support for explicit non-trapping, this should change
362
+ // from `harden` to `suppressTrapping` or `stabilize`.
332
363
const badFarObjExtraProtoProp = harden ( { __proto__ : farObjProtoWithExtra } ) ;
333
364
t . throws ( ( ) => passStyleOf ( badFarObjExtraProtoProp ) , {
334
365
message : 'Unexpected properties on Remotable Proto ["extra"]' ,
@@ -378,11 +409,17 @@ test('remotables - safety from the gibson042 attack', t => {
378
409
) ;
379
410
380
411
/**
412
+ * Do not freeze `mercurialProto` in order to test that an object with
413
+ * a non-frozen __proto__ is not passable. Once we have support for
414
+ * non-trapping, we should generalize this test (or add a new one) where
415
+ * `mercurialProto` is frozen but still trapping. This test would then
416
+ * test that a valid TagRecord must be non-trapping.
417
+ *
381
418
* TODO In order to run this test before we have explicit support for a
382
419
* non-trapping integrity trait, we have to `freeze` here but not `harden`.
383
420
* However, once we do have that support, and `passStyleOf` checks that
384
421
* its argument is also non-trapping, we still need to avoid `harden`
385
- * because that would also hardden `__proto__`. So we will need to
422
+ * because that would also harden `__proto__`. So we will need to
386
423
* explicitly make this non-trapping, which we cannot yet express.
387
424
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
388
425
*/
@@ -448,12 +485,16 @@ test('Allow toStringTag overrides', t => {
448
485
t . is ( `${ q ( alice ) } ` , '"[DebugName: Allison]"' ) ;
449
486
450
487
/** @type {any } UNTIL https://github.com/microsoft/TypeScript/issues/38385 */
488
+ // TODO Once we have support for explicit non-trapping, this should change
489
+ // from `harden` to `suppressTrapping` or `stabilize`.
451
490
const carol = harden ( { __proto__ : alice } ) ;
452
491
t . is ( passStyleOf ( carol ) , 'remotable' ) ;
453
492
t . is ( `${ carol } ` , '[object DebugName: Allison]' ) ;
454
493
t . is ( `${ q ( carol ) } ` , '"[DebugName: Allison]"' ) ;
455
494
456
495
/** @type {any } UNTIL https://github.com/microsoft/TypeScript/issues/38385 */
496
+ // TODO Once we have support for explicit non-trapping, this should change
497
+ // from `harden` to `suppressTrapping` or `stabilize`.
457
498
const bob = harden ( {
458
499
__proto__ : carol ,
459
500
[ Symbol . toStringTag ] : 'DebugName: Robert' ,
0 commit comments