Skip to content

Commit b1afe12

Browse files
fix: remove ability to override getPrototypeOf
See invariant here for explanation why: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/getPrototypeOf#invariants BREAKING CHANGE: remove any mocks overriding `ProxySymbol.GET_PROTOTYPE_OF`
1 parent c5251c5 commit b1afe12

File tree

4 files changed

+6
-46
lines changed

4 files changed

+6
-46
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ Whenever a method accepts a `path` it is an array of properties and symbols to d
250250

251251
### Caveats
252252

253-
- You cannot override `ProxySymbol.IS_EXTENSIBLE` or `ProxySymbol.PREVENT_EXTENSIONS`. Their values are fixed as they must always match the proxy target.
253+
- You cannot override `ProxySymbol.IS_EXTENSIBLE`, `ProxySymbol.PREVENT_EXTENSIONS`, or `ProxySymbol.GET_PROTOTYPE_OF`. Their values are fixed as they must always match the proxy target.
254254

255255
## More examples
256256

src/recursiveProxyMock/__snapshots__/recursiveProxyMock.test.ts.snap

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -342,18 +342,18 @@ Array [
342342
"name": "get",
343343
"parent": 0,
344344
"pathKey": Array [
345-
"a",
345+
"b",
346346
],
347-
"prop": "a",
347+
"prop": "b",
348348
"self": 1,
349349
},
350350
Object {
351351
"name": "get",
352352
"parent": 1,
353353
"pathKey": Array [
354-
"b",
354+
"c",
355355
],
356-
"prop": "b",
356+
"prop": "c",
357357
"self": 2,
358358
},
359359
Object {
@@ -364,32 +364,6 @@ Array [
364364
],
365365
"self": 3,
366366
},
367-
Object {
368-
"name": "get",
369-
"parent": 0,
370-
"pathKey": Array [
371-
"b",
372-
],
373-
"prop": "b",
374-
"self": 4,
375-
},
376-
Object {
377-
"name": "get",
378-
"parent": 4,
379-
"pathKey": Array [
380-
"c",
381-
],
382-
"prop": "c",
383-
"self": 5,
384-
},
385-
Object {
386-
"name": "getPrototypeOf",
387-
"parent": 5,
388-
"pathKey": Array [
389-
Symbol(getPrototypeOf),
390-
],
391-
"self": 6,
392-
},
393367
]
394368
`;
395369

src/recursiveProxyMock/recursiveProxyMock.test.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,7 @@ describe("recursiveProxyMock", () => {
202202
});
203203

204204
test("proxy trap: getPrototypeOf", () => {
205-
const mock = recursiveProxyMock([
206-
{
207-
path: ["a", "b", ProxySymbol.GET_PROTOTYPE_OF],
208-
value: {
209-
protoValue: 7,
210-
},
211-
},
212-
]);
213-
expect(Object.getPrototypeOf(mock.a.b)).toStrictEqual({
214-
protoValue: 7,
215-
});
205+
const mock = recursiveProxyMock();
216206
expect(Object.getPrototypeOf(mock.b.c)).toBeNull();
217207
expect(listAllProxyOperations(mock)).toMatchSnapshot();
218208
});

src/recursiveProxyMock/recursiveProxyMock.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ function recursiveProxyRecurse(overrides: ProxyOverrideConfig[], stack: ProxySta
137137
parent: parentId,
138138
self: next,
139139
});
140-
const override = findOverrideConfig(overrides, [...currentPath, ...pathKey]) as object | null | undefined;
141-
if (typeof override !== "undefined") {
142-
return override;
143-
}
144140
return null;
145141
},
146142
has: (target, prop): boolean => {

0 commit comments

Comments
 (0)