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
pull/10274/head
Simon H 10 months ago committed by GitHub
parent 40c2956381
commit 03c067f598
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: try-catch deep read during `$inspect`

@ -1965,7 +1965,11 @@ function deep_read(value, visited = new Set()) {
if (typeof value === 'object' && value !== null && !visited.has(value)) { if (typeof value === 'object' && value !== null && !visited.has(value)) {
visited.add(value); visited.add(value);
for (let key in value) { for (let key in value) {
try {
deep_read(value[key], visited); deep_read(value[key], visited);
} catch (e) {
// continue
}
} }
const proto = Object.getPrototypeOf(value); const proto = Object.getPrototypeOf(value);
if ( if (
@ -1979,7 +1983,11 @@ function deep_read(value, visited = new Set()) {
for (let key in descriptors) { for (let key in descriptors) {
const get = descriptors[key].get; const get = descriptors[key].get;
if (get) { if (get) {
try {
get.call(value); get.call(value);
} catch (e) {
// continue
}
} }
} }
} }

Loading…
Cancel
Save