Skip to content

Commit bcc292a

Browse files
committed
fixup! review suggestion
1 parent 2b82131 commit bcc292a

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

packages/non-trapping-shim/src/non-trapping-pony.js

+19-27
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@ const isPrimitive = specimen => OriginalObject(specimen) !== specimen;
2020
* `Reflect.isNonTrapping`.
2121
*
2222
* @param {any} specimen
23-
* @param {boolean} shouldThrow
2423
* @returns {boolean}
2524
*/
26-
const isNonTrappingInternal = (specimen, shouldThrow) => {
25+
const isNonTrappingInternal = specimen => {
2726
if (nonTrappingSet.has(specimen)) {
2827
return true;
2928
}
3029
if (!proxyHandlerMap.has(specimen)) {
3130
return false;
3231
}
3332
const [target, handler] = proxyHandlerMap.get(specimen);
34-
if (isNonTrappingInternal(target, shouldThrow)) {
33+
if (isNonTrappingInternal(target)) {
3534
nonTrappingSet.add(specimen);
3635
return true;
3736
}
@@ -40,14 +39,11 @@ const isNonTrappingInternal = (specimen, shouldThrow) => {
4039
return false;
4140
}
4241
const result = apply(trap, handler, [target]);
43-
const ofTarget = isNonTrappingInternal(target, shouldThrow);
42+
const ofTarget = isNonTrappingInternal(target);
4443
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+
);
5147
}
5248
if (result) {
5349
nonTrappingSet.add(specimen);
@@ -60,10 +56,9 @@ const isNonTrappingInternal = (specimen, shouldThrow) => {
6056
* `Reflect.suppressTrapping`.
6157
*
6258
* @param {any} specimen
63-
* @param {boolean} shouldThrow
6459
* @returns {boolean}
6560
*/
66-
const suppressTrappingInternal = (specimen, shouldThrow) => {
61+
const suppressTrappingInternal = specimen => {
6762
if (nonTrappingSet.has(specimen)) {
6863
return true;
6964
}
@@ -73,27 +68,24 @@ const suppressTrappingInternal = (specimen, shouldThrow) => {
7368
return true;
7469
}
7570
const [target, handler] = proxyHandlerMap.get(specimen);
76-
if (isNonTrappingInternal(target, shouldThrow)) {
71+
if (isNonTrappingInternal(target)) {
7772
nonTrappingSet.add(specimen);
7873
return true;
7974
}
8075
const trap = handler.suppressTrapping;
8176
if (trap === undefined) {
82-
const result = suppressTrappingInternal(target, shouldThrow);
77+
const result = suppressTrappingInternal(target);
8378
if (result) {
8479
nonTrappingSet.add(specimen);
8580
}
8681
return result;
8782
}
8883
const result = apply(trap, handler, [target]);
89-
const ofTarget = isNonTrappingInternal(target, shouldThrow);
84+
const ofTarget = isNonTrappingInternal(target);
9085
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+
);
9789
}
9890
if (result) {
9991
nonTrappingSet.add(specimen);
@@ -106,13 +98,13 @@ export const extraReflectMethods = freeze({
10698
if (isPrimitive(target)) {
10799
throw TypeError('Reflect.isNonTrapping called on non-object');
108100
}
109-
return isNonTrappingInternal(target, false);
101+
return isNonTrappingInternal(target);
110102
},
111103
suppressTrapping(target) {
112104
if (isPrimitive(target)) {
113105
throw TypeError('Reflect.suppressTrapping called on non-object');
114106
}
115-
return suppressTrappingInternal(target, false);
107+
return suppressTrappingInternal(target);
116108
},
117109
});
118110

@@ -121,13 +113,13 @@ export const extraObjectMethods = freeze({
121113
if (isPrimitive(target)) {
122114
return true;
123115
}
124-
return isNonTrappingInternal(target, true);
116+
return isNonTrappingInternal(target);
125117
},
126118
suppressTrapping(target) {
127119
if (isPrimitive(target)) {
128120
return target;
129121
}
130-
if (suppressTrappingInternal(target, true)) {
122+
if (suppressTrappingInternal(target)) {
131123
return target;
132124
}
133125
throw TypeError('suppressTrapping trap returned falsy');
@@ -198,7 +190,7 @@ const metaHandler = freeze({
198190
* @param {any[]} rest
199191
*/
200192
const trapPlus = freeze((target, ...rest) => {
201-
if (isNonTrappingInternal(target, true)) {
193+
if (isNonTrappingInternal(target)) {
202194
defineProperty(handlerPlus, trapName, {
203195
value: undefined,
204196
writable: false,
@@ -284,7 +276,7 @@ ProxyPlus.revocable = (target, handler) => {
284276
return {
285277
proxy,
286278
revoke() {
287-
if (isNonTrappingInternal(target, true)) {
279+
if (isNonTrappingInternal(target)) {
288280
throw TypeError('Cannot revoke non-trapping proxy');
289281
}
290282
revoke();

0 commit comments

Comments
 (0)