Skip to content

Commit 03c067f

Browse files
authored
fix: try-catch deep read (#10270)
Accessing values might throw errors if they're not just values but getters. Guard against that by try-catching every access so that `$inspect` doesn't fail fixes the iframe error in the playground reported in #10174
1 parent 40c2956 commit 03c067f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

.changeset/rich-waves-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: try-catch deep read during `$inspect`

packages/svelte/src/internal/client/runtime.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,11 @@ function deep_read(value, visited = new Set()) {
19651965
if (typeof value === 'object' && value !== null && !visited.has(value)) {
19661966
visited.add(value);
19671967
for (let key in value) {
1968-
deep_read(value[key], visited);
1968+
try {
1969+
deep_read(value[key], visited);
1970+
} catch (e) {
1971+
// continue
1972+
}
19691973
}
19701974
const proto = Object.getPrototypeOf(value);
19711975
if (
@@ -1979,7 +1983,11 @@ function deep_read(value, visited = new Set()) {
19791983
for (let key in descriptors) {
19801984
const get = descriptors[key].get;
19811985
if (get) {
1982-
get.call(value);
1986+
try {
1987+
get.call(value);
1988+
} catch (e) {
1989+
// continue
1990+
}
19831991
}
19841992
}
19851993
}

0 commit comments

Comments
 (0)