2
2
import test from '@endo/ses-ava/prepare-endo.js' ;
3
3
4
4
import { q } from '@endo/errors' ;
5
+ import {
6
+ hardenOrSuppressTrapping ,
7
+ freezeOrSuppressTrapping ,
8
+ } from 'ses/nonTrappingShimAdapter.js' ;
5
9
6
10
import { passStyleOf } from '../src/passStyleOf.js' ;
7
11
import { Far , ToFarFunction } from '../src/make-far.js' ;
@@ -13,7 +17,7 @@ const harden = /** @type {import('ses').Harden & { isFake?: boolean }} */ (
13
17
global . harden
14
18
) ;
15
19
16
- const { getPrototypeOf, defineProperty, suppressTrapping } = Object ;
20
+ const { getPrototypeOf, defineProperty } = Object ;
17
21
const { ownKeys } = Reflect ;
18
22
19
23
test ( 'passStyleOf basic success cases' , t => {
@@ -113,8 +117,8 @@ test('some passStyleOf rejections', t => {
113
117
* For testing purposes, makes a *non-frozen* TagRecord-like object with
114
118
* non-enumerable PASS_STYLE and Symbol.toStringTag properties.
115
119
* 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
120
+ * - Before stabilize/hardenOrSuppressTrapping , a valid TagRecord must be frozen.
121
+ * - After stabilize/hardenOrSuppressTrapping , a valid TagRecord must also be
118
122
* stable/non-trapping, for example, because it was hardened.
119
123
*
120
124
* @param {string } [tag]
@@ -196,15 +200,15 @@ test('passStyleOf testing remotables', t => {
196
200
t . is ( passStyleOf ( Far ( 'foo' , ( ) => 'far function' ) ) , 'remotable' ) ;
197
201
198
202
const tagRecord1 = harden ( makeTagishRecord ( 'Alleged: manually constructed' ) ) ;
199
- const farObj1 = suppressTrapping ( { __proto__ : tagRecord1 } ) ;
203
+ const farObj1 = hardenOrSuppressTrapping ( { __proto__ : tagRecord1 } ) ;
200
204
t . is ( passStyleOf ( farObj1 ) , 'remotable' ) ;
201
205
202
206
const tagRecord2 = makeTagishRecord ( 'Alleged: tagRecord not hardened' ) ;
203
207
/**
204
208
* Do not freeze `tagRecord2` in order to test that an object with
205
209
* a non-frozen __proto__ is not passable.
206
210
*/
207
- const farObj2 = suppressTrapping ( { __proto__ : tagRecord2 } ) ;
211
+ const farObj2 = freezeOrSuppressTrapping ( { __proto__ : tagRecord2 } ) ;
208
212
if ( harden . isFake ) {
209
213
t . is ( passStyleOf ( farObj2 ) , 'remotable' ) ;
210
214
} else {
@@ -215,23 +219,23 @@ test('passStyleOf testing remotables', t => {
215
219
}
216
220
217
221
const tagRecord3 = harden ( makeTagishRecord ( 'Alleged: both manually frozen' ) ) ;
218
- const farObj3 = suppressTrapping ( { __proto__ : tagRecord3 } ) ;
222
+ const farObj3 = hardenOrSuppressTrapping ( { __proto__ : tagRecord3 } ) ;
219
223
t . is ( passStyleOf ( farObj3 ) , 'remotable' ) ;
220
224
221
225
const tagRecord4 = harden ( makeTagishRecord ( 'Remotable' ) ) ;
222
- const farObj4 = suppressTrapping ( { __proto__ : tagRecord4 } ) ;
226
+ const farObj4 = hardenOrSuppressTrapping ( { __proto__ : tagRecord4 } ) ;
223
227
t . is ( passStyleOf ( farObj4 ) , 'remotable' ) ;
224
228
225
229
const tagRecord5 = harden ( makeTagishRecord ( 'Not alleging' ) ) ;
226
- const farObj5 = suppressTrapping ( { __proto__ : tagRecord5 } ) ;
230
+ const farObj5 = hardenOrSuppressTrapping ( { __proto__ : tagRecord5 } ) ;
227
231
t . throws ( ( ) => passStyleOf ( farObj5 ) , {
228
232
message :
229
233
/ 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 / ,
230
234
} ) ;
231
235
232
236
const tagRecord6 = harden ( makeTagishRecord ( 'Alleged: manually constructed' ) ) ;
233
- const farObjProto6 = suppressTrapping ( { __proto__ : tagRecord6 } ) ;
234
- const farObj6 = suppressTrapping ( { __proto__ : farObjProto6 } ) ;
237
+ const farObjProto6 = hardenOrSuppressTrapping ( { __proto__ : tagRecord6 } ) ;
238
+ const farObj6 = hardenOrSuppressTrapping ( { __proto__ : farObjProto6 } ) ;
235
239
t . is ( passStyleOf ( farObj6 ) , 'remotable' , 'tagRecord grandproto is accepted' ) ;
236
240
237
241
// Our current agoric-sdk plans for far classes are to create a class-like
@@ -285,7 +289,7 @@ test('passStyleOf testing remotables', t => {
285
289
const tagRecordA1 = harden (
286
290
makeTagishRecord ( 'Alleged: null-proto tagRecord proto' , null ) ,
287
291
) ;
288
- const farObjA1 = suppressTrapping ( { __proto__ : tagRecordA1 } ) ;
292
+ const farObjA1 = hardenOrSuppressTrapping ( { __proto__ : tagRecordA1 } ) ;
289
293
t . throws (
290
294
( ) => passStyleOf ( farObjA1 ) ,
291
295
{ message : unusualTagRecordProtoMessage } ,
@@ -295,8 +299,8 @@ test('passStyleOf testing remotables', t => {
295
299
const tagRecordA2 = harden (
296
300
makeTagishRecord ( 'Alleged: null-proto tagRecord grandproto' , null ) ,
297
301
) ;
298
- const farObjProtoA2 = suppressTrapping ( { __proto__ : tagRecordA2 } ) ;
299
- const farObjA2 = suppressTrapping ( { __proto__ : farObjProtoA2 } ) ;
302
+ const farObjProtoA2 = hardenOrSuppressTrapping ( { __proto__ : tagRecordA2 } ) ;
303
+ const farObjA2 = hardenOrSuppressTrapping ( { __proto__ : farObjProtoA2 } ) ;
300
304
t . throws (
301
305
( ) => passStyleOf ( farObjA2 ) ,
302
306
{ message : unusualTagRecordProtoMessage } ,
@@ -310,10 +314,10 @@ test('passStyleOf testing remotables', t => {
310
314
const fauxTagRecordB = harden (
311
315
makeTagishRecord ( 'Alleged: manually constructed' , harden ( { } ) ) ,
312
316
) ;
313
- const farObjProtoB = suppressTrapping ( {
317
+ const farObjProtoB = hardenOrSuppressTrapping ( {
314
318
__proto__ : fauxTagRecordB ,
315
319
} ) ;
316
- const farObjB = suppressTrapping ( { __proto__ : farObjProtoB } ) ;
320
+ const farObjB = hardenOrSuppressTrapping ( { __proto__ : farObjProtoB } ) ;
317
321
t . throws ( ( ) => passStyleOf ( farObjB ) , {
318
322
message :
319
323
'cannot serialize Remotables with non-methods like "Symbol(passStyle)" in "[Alleged: manually constructed]"' ,
@@ -324,7 +328,7 @@ test('passStyleOf testing remotables', t => {
324
328
) ;
325
329
Object . defineProperty ( farObjProtoWithExtra , 'extra' , { value : ( ) => { } } ) ;
326
330
harden ( farObjProtoWithExtra ) ;
327
- const badFarObjExtraProtoProp = suppressTrapping ( {
331
+ const badFarObjExtraProtoProp = hardenOrSuppressTrapping ( {
328
332
__proto__ : farObjProtoWithExtra ,
329
333
} ) ;
330
334
t . throws ( ( ) => passStyleOf ( badFarObjExtraProtoProp ) , {
@@ -389,7 +393,8 @@ test('remotables - safety from the gibson042 attack', t => {
389
393
* explicitly make this non-trapping, which we cannot yet express.
390
394
* @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
391
395
*/
392
- const makeInput = ( ) => suppressTrapping ( { __proto__ : mercurialProto } ) ;
396
+ const makeInput = ( ) =>
397
+ freezeOrSuppressTrapping ( { __proto__ : mercurialProto } ) ;
393
398
const input1 = makeInput ( ) ;
394
399
const input2 = makeInput ( ) ;
395
400
@@ -450,12 +455,12 @@ test('Allow toStringTag overrides', t => {
450
455
t . is ( `${ alice } ` , '[object DebugName: Allison]' ) ;
451
456
t . is ( `${ q ( alice ) } ` , '"[DebugName: Allison]"' ) ;
452
457
453
- const carol = suppressTrapping ( { __proto__ : alice } ) ;
458
+ const carol = hardenOrSuppressTrapping ( { __proto__ : alice } ) ;
454
459
t . is ( passStyleOf ( carol ) , 'remotable' ) ;
455
460
t . is ( `${ carol } ` , '[object DebugName: Allison]' ) ;
456
461
t . is ( `${ q ( carol ) } ` , '"[DebugName: Allison]"' ) ;
457
462
458
- const bob = suppressTrapping ( {
463
+ const bob = hardenOrSuppressTrapping ( {
459
464
__proto__ : carol ,
460
465
[ Symbol . toStringTag ] : 'DebugName: Robert' ,
461
466
} ) ;
0 commit comments