diff --git a/lib/browser/rpc-server.js b/lib/browser/rpc-server.js index 8fb78b3b2c24..3bff8e471e4c 100644 --- a/lib/browser/rpc-server.js +++ b/lib/browser/rpc-server.js @@ -12,6 +12,7 @@ const { ipcMain, isPromise } = electron const objectsRegistry = require('@electron/internal/browser/objects-registry') const bufferUtils = require('@electron/internal/common/buffer-utils') +const errorUtils = require('@electron/internal/common/error-utils') const hasProp = {}.hasOwnProperty @@ -138,9 +139,7 @@ const plainObjectToMeta = function (obj) { const exceptionToMeta = function (sender, contextId, error) { return { type: 'exception', - message: error.message, - stack: error.stack || error, - cause: valueToMeta(sender, contextId, error.cause) + value: errorUtils.serialize(error) } } diff --git a/lib/common/error-utils.js b/lib/common/error-utils.js index e6aac41ee697..26dd0185d3f4 100644 --- a/lib/common/error-utils.js +++ b/lib/common/error-utils.js @@ -11,10 +11,12 @@ const constructors = new Map([ ]) exports.deserialize = function (error) { - if (error.__ELECTRON_SERIALIZED_ERROR__ && constructors.has(error.name)) { + if (error && error.__ELECTRON_SERIALIZED_ERROR__ && constructors.has(error.name)) { const constructor = constructors.get(error.name) const deserializedError = new constructor(error.message) deserializedError.stack = error.stack + deserializedError.from = error.from + deserializedError.cause = exports.deserialize(error.cause) return deserializedError } return error @@ -28,6 +30,8 @@ exports.serialize = function (error) { message: error.message, stack: error.stack, name: error.name, + from: process.type, + cause: exports.serialize(error.cause), __ELECTRON_SERIALIZED_ERROR__: true } } diff --git a/lib/renderer/api/remote.js b/lib/renderer/api/remote.js index e1a6af8d7811..6ad9aed146ac 100644 --- a/lib/renderer/api/remote.js +++ b/lib/renderer/api/remote.js @@ -6,6 +6,7 @@ const resolvePromise = Promise.resolve.bind(Promise) const CallbacksRegistry = require('@electron/internal/renderer/callbacks-registry') const bufferUtils = require('@electron/internal/common/buffer-utils') +const errorUtils = require('@electron/internal/common/error-utils') const callbacksRegistry = new CallbacksRegistry() const remoteObjectCache = v8Util.createIDWeakMap() @@ -217,7 +218,7 @@ function metaToValue (meta) { promise: () => resolvePromise({ then: metaToValue(meta.then) }), error: () => metaToPlainObject(meta), date: () => new Date(meta.value), - exception: () => { throw metaToException(meta) } + exception: () => { throw errorUtils.deserialize(meta.value) } } if (meta.type in types) { @@ -267,15 +268,6 @@ function metaToPlainObject (meta) { return obj } -// Construct an exception error from the meta. -function metaToException (meta) { - const error = new Error(`${meta.message}\n${meta.stack}`) - const remoteProcess = exports.process - error.from = remoteProcess ? remoteProcess.type : null - error.cause = metaToValue(meta.cause) - return error -} - function handleMessage (channel, handler) { ipcRenderer.on(channel, (event, passedContextId, ...args) => { if (passedContextId === contextId) { diff --git a/lib/sandboxed_renderer/init.js b/lib/sandboxed_renderer/init.js index 914562250ce4..33284381d1a1 100644 --- a/lib/sandboxed_renderer/init.js +++ b/lib/sandboxed_renderer/init.js @@ -54,12 +54,16 @@ preloadProcess.getHeapStatistics = () => binding.getHeapStatistics() preloadProcess.getSystemMemoryInfo = () => binding.getSystemMemoryInfo() preloadProcess.getCPUUsage = () => binding.getCPUUsage() preloadProcess.getIOCounters = () => binding.getIOCounters() -preloadProcess.argv = process.argv = binding.getArgv() -preloadProcess.execPath = process.execPath = binding.getExecPath() -preloadProcess.pid = process.pid = binding.getPid() -preloadProcess.resourcesPath = binding.getResourcesPath() -preloadProcess.sandboxed = true -preloadProcess.type = 'renderer' + +Object.assign(processProps, { + argv: binding.getArgv(), + execPath: binding.getExecPath(), + pid: binding.getPid(), + resourcesPath: binding.getResourcesPath(), + sandboxed: true, + type: 'renderer' +}) + Object.assign(preloadProcess, processProps) Object.assign(process, processProps)