@@ -31,7 +31,13 @@ import { assertPassableString } from './string.js';
31
31
/** @typedef {Exclude<PassStyle, PrimitiveStyle | "promise"> } HelperPassStyle */
32
32
33
33
const { ownKeys } = Reflect ;
34
- const { isFrozen, getOwnPropertyDescriptors, values } = Object ;
34
+ const {
35
+ getOwnPropertyDescriptors,
36
+ values,
37
+ isFrozen,
38
+ // @ts -expect-error TS does not yet have `isNonTrapping` on ObjectConstructor
39
+ isNonTrapping = isFrozen ,
40
+ } = Object ;
35
41
36
42
/**
37
43
* @param {PassStyleHelper[] } passStyleHelpers
@@ -143,14 +149,17 @@ const makePassStyleOf = passStyleHelpers => {
143
149
if ( inner === null ) {
144
150
return 'null' ;
145
151
}
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
- ) ;
152
+ if ( ! isNonTrapping ( inner ) ) {
153
+ if ( ! isFrozen ( inner ) ) {
154
+ throw assert . fail (
155
+ // TypedArrays get special treatment in harden()
156
+ // and a corresponding special error message here.
157
+ isTypedArray ( inner )
158
+ ? X `Cannot pass mutable typed arrays like ${ inner } .`
159
+ : X `Cannot pass non-frozen objects like ${ inner } . Use harden()` ,
160
+ ) ;
161
+ }
162
+ throw Fail `Cannot pass trapping objects like ${ inner } ` ;
154
163
}
155
164
if ( isPromise ( inner ) ) {
156
165
assertSafePromise ( inner ) ;
@@ -177,8 +186,12 @@ const makePassStyleOf = passStyleHelpers => {
177
186
return 'remotable' ;
178
187
}
179
188
case 'function' : {
180
- isFrozen ( inner ) ||
181
- Fail `Cannot pass non-frozen objects like ${ inner } . Use harden()` ;
189
+ if ( ! isNonTrapping ( inner ) ) {
190
+ if ( ! isFrozen ( inner ) ) {
191
+ throw Fail `Cannot pass non-frozen objects like ${ inner } . Use harden()` ;
192
+ }
193
+ throw Fail `Cannot pass trapping objects like ${ inner } . Use harden()` ;
194
+ }
182
195
typeof inner . then !== 'function' ||
183
196
Fail `Cannot pass non-promise thenables` ;
184
197
remotableHelper . assertValid ( inner , passStyleOfRecur ) ;
0 commit comments