Skip to content

Commit 1bd19ba

Browse files
committed
fix: guard ownMethodDep toString against throwing callables
Wrap Function.prototype.toString.call(method) and the subsequent regex test in a try/catch inside ownMethodDep, returning the receiver on failure. This matches the documented fail-closed contract: unrecognized functions track the receiver (worst case is a spurious recompute). The guarded path already caught reflection errors via its outer try/catch, but the unguarded own-property path at line 77 called ownMethodDep without protection. A callable whose toString throws (revoked function proxy, SES/lockdown, some host/CSP wrappers) would abort dependency evaluation during render instead of falling back.
1 parent 527c9a4 commit 1bd19ba

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎packages/octane/src/method-dep.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ const ARROW_HEAD = /^(?:async\s*)?(?:\(|[\w$]+\s*=>)/;
9090

9191
function ownMethodDep(receiver: object, method: unknown): unknown {
9292
if (typeof method !== 'function') return method;
93-
const source = Function.prototype.toString.call(method);
94-
return ARROW_HEAD.test(source) && (source[0] === '(' || method.name !== 'async')
95-
? method
96-
: receiver;
93+
try {
94+
const source = Function.prototype.toString.call(method);
95+
return ARROW_HEAD.test(source) && (source[0] === '(' || method.name !== 'async')
96+
? method
97+
: receiver;
98+
} catch {
99+
return receiver;
100+
}
97101
}

0 commit comments

Comments
 (0)