Skip to content

Commit

Permalink
fix ipc serialization for RegExp objects
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jan 13, 2025
1 parent 76dbb60 commit c26c972
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/try/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const serializeFunctions = (value: any): any => {
const text = value + ''
return new EvalError('function ' + value.name + text.slice(text.indexOf('(')))
}
if (typeof value === 'object' && value) {
if (typeof value === 'object' && value && !(value instanceof RegExp)) {
if (Array.isArray(value)) return value.map(serializeFunctions)
else return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, serializeFunctions(v)]))
}
Expand Down
2 changes: 1 addition & 1 deletion src/try/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const formatMessages = (api: API, messages: Message[], options: FormatMessagesOp

// Hack: Deserialize "EvalError" objects as "Function" objects instead
const deserializeFunctions = (value: any): any => {
if (typeof value === 'object' && value) {
if (typeof value === 'object' && value && !(value instanceof RegExp)) {
if (value instanceof EvalError) return new Function('return ' + value.message)()
else if (Array.isArray(value)) return value.map(deserializeFunctions)
else return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, deserializeFunctions(v)]))
Expand Down

0 comments on commit c26c972

Please sign in to comment.