Skip to content

Commit 0a58d5b

Browse files
committed
refactor(ios): look up capture-scoped refusals without a prototype chain
The guest failure code is an open string. An object-literal table would answer a code that names an inherited property, so the lookup uses a map and every unknown code keeps the conservative generation default.
1 parent 147400d commit 0a58d5b

2 files changed

Lines changed: 20 additions & 15 deletions

File tree

‎packages/platform-apple/src/snapshot-route-failure-policy.test.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ describe('generation-wide failures', () => {
5555
).toEqual({ scope: 'generation', code: 'presentation-invariant' });
5656
});
5757

58-
test('a code this policy does not know keeps the conservative generation default', () => {
59-
// The guest's `code` is an open string. A refusal unknown here must not quietly keep a
60-
// generation on a path that just refused it; a new capture-scoped refusal is classified
61-
// explicitly, never by widening this default.
62-
expect(
63-
bridgeFailureDisposition({ kind: 'unsupported', code: 'future-runtime-refusal' }),
64-
).toEqual({ scope: 'generation', code: 'future-runtime-refusal' });
65-
});
58+
test.for(['future-runtime-refusal', 'toString', 'constructor'] as const)(
59+
'a code this policy does not know (%s) keeps the conservative generation default',
60+
(code) => {
61+
// The guest's `code` is an open string. A refusal unknown here must not quietly keep a
62+
// generation on a path that just refused it; a new capture-scoped refusal is classified
63+
// explicitly, never by widening this default. An inherited property name is an unknown code
64+
// too, so the table's lookup must not answer through a prototype chain.
65+
expect(bridgeFailureDisposition({ kind: 'unsupported', code })).toEqual({
66+
scope: 'generation',
67+
code,
68+
});
69+
},
70+
);
6671
});

‎packages/platform-apple/src/snapshot-route-failure-policy.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ export type BridgeFailureDisposition =
2828
* A new capture-scoped refusal enters here, by an explicit decision; the route's warning switch is
2929
* exhaustive over the consequence, so a new one cannot reach the warning path undefined.
3030
*/
31-
const CAPTURE_SCOPED_REFUSALS = {
32-
'window-coordinate-space-unresolved': 'coordinate-space-unresolved',
33-
'app-window-not-full-screen': 'window-not-full-screen',
34-
'foreground-owner-unverified': 'foreground-ownership',
35-
'foreground-owner-changed': 'foreground-ownership',
36-
} as const satisfies Readonly<Record<string, CaptureScopedConsequence>>;
31+
const CAPTURE_SCOPED_REFUSALS: ReadonlyMap<string, CaptureScopedConsequence> = new Map([
32+
['window-coordinate-space-unresolved', 'coordinate-space-unresolved'],
33+
['app-window-not-full-screen', 'window-not-full-screen'],
34+
['foreground-owner-unverified', 'foreground-ownership'],
35+
['foreground-owner-changed', 'foreground-ownership'],
36+
]);
3737

3838
/**
3939
* Whether a bridge failure is evidence that this app generation cannot be served by the bridge.
@@ -46,7 +46,7 @@ export function bridgeFailureDisposition(failure: SnapshotSourceFailure): Bridge
4646
if (failure.kind === 'preparing') {
4747
return { scope: 'capture', code: failure.code, consequence: 'bridge-preparation' };
4848
}
49-
const consequence = CAPTURE_SCOPED_REFUSALS[failure.code as keyof typeof CAPTURE_SCOPED_REFUSALS];
49+
const consequence = CAPTURE_SCOPED_REFUSALS.get(failure.code);
5050
if (consequence) {
5151
return { scope: 'capture', code: failure.code, consequence };
5252
}

0 commit comments

Comments
 (0)