Skip to content

Commit

Permalink
fix: handle errors in encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Oct 18, 2022
1 parent 751edce commit b3a232e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/shared-utils/src/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@ function encode (data, replacer, list, seen) {
const keys = Object.keys(data)
for (i = 0, l = keys.length; i < l; i++) {
key = keys[i]
value = data[key]
if (replacer) value = replacer.call(data, key, value)
try {
value = data[key]
if (replacer) value = replacer.call(data, key, value)
} catch (e) {
value = e
}
stored[key] = encode(value, replacer, list, seen)
}
} else if (proto === '[object Array]') {
stored = []
seen.set(data, index)
list.push(stored)
for (i = 0, l = data.length; i < l; i++) {
value = data[i]
if (replacer) value = replacer.call(data, i, value)
try {
value = data[i]
if (replacer) value = replacer.call(data, i, value)
} catch (e) {
value = e
}
stored[i] = encode(value, replacer, list, seen)
}
} else {
Expand Down

0 comments on commit b3a232e

Please sign in to comment.