4
4
5
5
import { isPromise } from '@endo/promise-kit' ;
6
6
import { X , Fail , q , annotateError , makeError } from '@endo/errors' ;
7
- import { isObject , isTypedArray , PASS_STYLE } from './passStyle-helpers.js ' ;
7
+ import { extraObjectMethods } from '@endo/non-trapping-shim ' ;
8
8
9
+ import { isObject , isTypedArray , PASS_STYLE } from './passStyle-helpers.js' ;
9
10
import { CopyArrayHelper } from './copyArray.js' ;
10
11
import { CopyRecordHelper } from './copyRecord.js' ;
11
12
import { TaggedHelper } from './tagged.js' ;
@@ -31,7 +32,8 @@ import { assertPassableString } from './string.js';
31
32
/** @typedef {Exclude<PassStyle, PrimitiveStyle | "promise"> } HelperPassStyle */
32
33
33
34
const { ownKeys } = Reflect ;
34
- const { isFrozen, getOwnPropertyDescriptors, values } = Object ;
35
+ const { getOwnPropertyDescriptors, values, isFrozen } = Object ;
36
+ const { isNonTrapping } = extraObjectMethods ;
35
37
36
38
/**
37
39
* @param {PassStyleHelper[] } passStyleHelpers
@@ -143,14 +145,17 @@ const makePassStyleOf = passStyleHelpers => {
143
145
if ( inner === null ) {
144
146
return 'null' ;
145
147
}
146
- if ( ! isFrozen ( inner ) ) {
147
- assert . fail (
148
- // TypedArrays get special treatment in harden()
149
- // and a corresponding special error message here.
150
- isTypedArray ( inner )
151
- ? X `Cannot pass mutable typed arrays like ${ inner } .`
152
- : X `Cannot pass non-frozen objects like ${ inner } . Use harden()` ,
153
- ) ;
148
+ if ( ! isNonTrapping ( inner ) ) {
149
+ if ( ! isFrozen ( inner ) ) {
150
+ throw assert . fail (
151
+ // TypedArrays get special treatment in harden()
152
+ // and a corresponding special error message here.
153
+ isTypedArray ( inner )
154
+ ? X `Cannot pass mutable typed arrays like ${ inner } .`
155
+ : X `Cannot pass non-frozen objects like ${ inner } . Use harden()` ,
156
+ ) ;
157
+ }
158
+ throw Fail `Cannot pass non-trapping objects like ${ inner } ` ;
154
159
}
155
160
if ( isPromise ( inner ) ) {
156
161
assertSafePromise ( inner ) ;
@@ -177,8 +182,12 @@ const makePassStyleOf = passStyleHelpers => {
177
182
return 'remotable' ;
178
183
}
179
184
case 'function' : {
180
- isFrozen ( inner ) ||
181
- Fail `Cannot pass non-frozen objects like ${ inner } . Use harden()` ;
185
+ if ( ! isNonTrapping ( inner ) ) {
186
+ if ( ! isFrozen ( inner ) ) {
187
+ throw Fail `Cannot pass non-frozen objects like ${ inner } . Use harden()` ;
188
+ }
189
+ throw Fail `Cannot pass trapping objects like ${ inner } . Use harden()` ;
190
+ }
182
191
typeof inner . then !== 'function' ||
183
192
Fail `Cannot pass non-promise thenables` ;
184
193
remotableHelper . assertValid ( inner , passStyleOfRecur ) ;
0 commit comments