@@ -20,18 +20,17 @@ const isPrimitive = specimen => OriginalObject(specimen) !== specimen;
20
20
* `Reflect.isNonTrapping`.
21
21
*
22
22
* @param {any } specimen
23
- * @param {boolean } shouldThrow
24
23
* @returns {boolean }
25
24
*/
26
- const isNonTrappingInternal = ( specimen , shouldThrow ) => {
25
+ const isNonTrappingInternal = specimen => {
27
26
if ( nonTrappingSet . has ( specimen ) ) {
28
27
return true ;
29
28
}
30
29
if ( ! proxyHandlerMap . has ( specimen ) ) {
31
30
return false ;
32
31
}
33
32
const [ target , handler ] = proxyHandlerMap . get ( specimen ) ;
34
- if ( isNonTrappingInternal ( target , shouldThrow ) ) {
33
+ if ( isNonTrappingInternal ( target ) ) {
35
34
nonTrappingSet . add ( specimen ) ;
36
35
return true ;
37
36
}
@@ -40,14 +39,11 @@ const isNonTrappingInternal = (specimen, shouldThrow) => {
40
39
return false ;
41
40
}
42
41
const result = apply ( trap , handler , [ target ] ) ;
43
- const ofTarget = isNonTrappingInternal ( target , shouldThrow ) ;
42
+ const ofTarget = isNonTrappingInternal ( target ) ;
44
43
if ( result !== ofTarget ) {
45
- if ( shouldThrow ) {
46
- throw TypeError (
47
- `'isNonTrapping' proxy trap does not reflect 'isNonTrapping' of proxy target (which is '${ ofTarget } ')` ,
48
- ) ;
49
- }
50
- return false ;
44
+ throw TypeError (
45
+ `'isNonTrapping' proxy trap does not reflect 'isNonTrapping' of proxy target (which is '${ ofTarget } ')` ,
46
+ ) ;
51
47
}
52
48
if ( result ) {
53
49
nonTrappingSet . add ( specimen ) ;
@@ -60,10 +56,9 @@ const isNonTrappingInternal = (specimen, shouldThrow) => {
60
56
* `Reflect.suppressTrapping`.
61
57
*
62
58
* @param {any } specimen
63
- * @param {boolean } shouldThrow
64
59
* @returns {boolean }
65
60
*/
66
- const suppressTrappingInternal = ( specimen , shouldThrow ) => {
61
+ const suppressTrappingInternal = specimen => {
67
62
if ( nonTrappingSet . has ( specimen ) ) {
68
63
return true ;
69
64
}
@@ -73,27 +68,24 @@ const suppressTrappingInternal = (specimen, shouldThrow) => {
73
68
return true ;
74
69
}
75
70
const [ target , handler ] = proxyHandlerMap . get ( specimen ) ;
76
- if ( isNonTrappingInternal ( target , shouldThrow ) ) {
71
+ if ( isNonTrappingInternal ( target ) ) {
77
72
nonTrappingSet . add ( specimen ) ;
78
73
return true ;
79
74
}
80
75
const trap = handler . suppressTrapping ;
81
76
if ( trap === undefined ) {
82
- const result = suppressTrappingInternal ( target , shouldThrow ) ;
77
+ const result = suppressTrappingInternal ( target ) ;
83
78
if ( result ) {
84
79
nonTrappingSet . add ( specimen ) ;
85
80
}
86
81
return result ;
87
82
}
88
83
const result = apply ( trap , handler , [ target ] ) ;
89
- const ofTarget = isNonTrappingInternal ( target , shouldThrow ) ;
84
+ const ofTarget = isNonTrappingInternal ( target ) ;
90
85
if ( result !== ofTarget ) {
91
- if ( shouldThrow ) {
92
- throw TypeError (
93
- `'suppressTrapping' proxy trap does not reflect 'isNonTrapping' of proxy target (which is '${ ofTarget } ')` ,
94
- ) ;
95
- }
96
- return false ;
86
+ throw TypeError (
87
+ `'suppressTrapping' proxy trap does not reflect 'isNonTrapping' of proxy target (which is '${ ofTarget } ')` ,
88
+ ) ;
97
89
}
98
90
if ( result ) {
99
91
nonTrappingSet . add ( specimen ) ;
@@ -106,13 +98,13 @@ export const extraReflectMethods = freeze({
106
98
if ( isPrimitive ( target ) ) {
107
99
throw TypeError ( 'Reflect.isNonTrapping called on non-object' ) ;
108
100
}
109
- return isNonTrappingInternal ( target , false ) ;
101
+ return isNonTrappingInternal ( target ) ;
110
102
} ,
111
103
suppressTrapping ( target ) {
112
104
if ( isPrimitive ( target ) ) {
113
105
throw TypeError ( 'Reflect.suppressTrapping called on non-object' ) ;
114
106
}
115
- return suppressTrappingInternal ( target , false ) ;
107
+ return suppressTrappingInternal ( target ) ;
116
108
} ,
117
109
} ) ;
118
110
@@ -121,13 +113,13 @@ export const extraObjectMethods = freeze({
121
113
if ( isPrimitive ( target ) ) {
122
114
return true ;
123
115
}
124
- return isNonTrappingInternal ( target , true ) ;
116
+ return isNonTrappingInternal ( target ) ;
125
117
} ,
126
118
suppressTrapping ( target ) {
127
119
if ( isPrimitive ( target ) ) {
128
120
return target ;
129
121
}
130
- if ( suppressTrappingInternal ( target , true ) ) {
122
+ if ( suppressTrappingInternal ( target ) ) {
131
123
return target ;
132
124
}
133
125
throw TypeError ( 'suppressTrapping trap returned falsy' ) ;
@@ -198,7 +190,7 @@ const metaHandler = freeze({
198
190
* @param {any[] } rest
199
191
*/
200
192
const trapPlus = freeze ( ( target , ...rest ) => {
201
- if ( isNonTrappingInternal ( target , true ) ) {
193
+ if ( isNonTrappingInternal ( target ) ) {
202
194
defineProperty ( handlerPlus , trapName , {
203
195
value : undefined ,
204
196
writable : false ,
@@ -284,7 +276,7 @@ ProxyPlus.revocable = (target, handler) => {
284
276
return {
285
277
proxy,
286
278
revoke ( ) {
287
- if ( isNonTrappingInternal ( target , true ) ) {
279
+ if ( isNonTrappingInternal ( target ) ) {
288
280
throw TypeError ( 'Cannot revoke non-trapping proxy' ) ;
289
281
}
290
282
revoke ( ) ;
0 commit comments