chore: remove special handling for dialog methods in remote module (#17412)
* chore: remove special handling for dialog methods in remote module * refactor: remove callFunction helper
This commit is contained in:
parent
f4c3151815
commit
06a4594435
3 changed files with 18 additions and 37 deletions
|
@ -242,32 +242,6 @@ const unwrapArgs = function (sender, frameId, contextId, args) {
|
|||
return args.map(metaToValue)
|
||||
}
|
||||
|
||||
// Call a function and send reply asynchronously if it's a an asynchronous
|
||||
// style function and the caller didn't pass a callback.
|
||||
const callFunction = function (event, contextId, func, caller, args) {
|
||||
const funcMarkedAsync = v8Util.getHiddenValue(func, 'asynchronous')
|
||||
const funcPassedCallback = typeof args[args.length - 1] === 'function'
|
||||
try {
|
||||
if (funcMarkedAsync && !funcPassedCallback) {
|
||||
args.push(function (ret) {
|
||||
event.returnValue = valueToMeta(event.sender, contextId, ret, true)
|
||||
})
|
||||
func.apply(caller, args)
|
||||
} else {
|
||||
const ret = func.apply(caller, args)
|
||||
return valueToMeta(event.sender, contextId, ret, true)
|
||||
}
|
||||
} catch (error) {
|
||||
// Catch functions thrown further down in function invocation and wrap
|
||||
// them with the function name so it's easier to trace things like
|
||||
// `Error processing argument -1.`
|
||||
const funcName = func.name || 'anonymous'
|
||||
const err = new Error(`Could not call remote function '${funcName}'. Check that the function signature is correct. Underlying error: ${error.message}`)
|
||||
err.cause = error
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
const isRemoteModuleEnabledCache = new WeakMap()
|
||||
|
||||
const isRemoteModuleEnabled = function (contents) {
|
||||
|
@ -401,7 +375,13 @@ handleRemoteCommand('ELECTRON_BROWSER_FUNCTION_CALL', function (event, contextId
|
|||
throwRPCError(`Cannot call function on missing remote object ${id}`)
|
||||
}
|
||||
|
||||
return callFunction(event, contextId, func, global, args)
|
||||
try {
|
||||
return valueToMeta(event.sender, contextId, func(...args), true)
|
||||
} catch (error) {
|
||||
const err = new Error(`Could not call remote function '${func.name || 'anonymous'}'. Check that the function signature is correct. Underlying error: ${error.message}`)
|
||||
err.cause = error
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
handleRemoteCommand('ELECTRON_BROWSER_MEMBER_CONSTRUCTOR', function (event, contextId, id, method, args) {
|
||||
|
@ -417,13 +397,19 @@ handleRemoteCommand('ELECTRON_BROWSER_MEMBER_CONSTRUCTOR', function (event, cont
|
|||
|
||||
handleRemoteCommand('ELECTRON_BROWSER_MEMBER_CALL', function (event, contextId, id, method, args) {
|
||||
args = unwrapArgs(event.sender, event.frameId, contextId, args)
|
||||
const obj = objectsRegistry.get(id)
|
||||
const object = objectsRegistry.get(id)
|
||||
|
||||
if (obj == null) {
|
||||
throwRPCError(`Cannot call function '${method}' on missing remote object ${id}`)
|
||||
if (object == null) {
|
||||
throwRPCError(`Cannot call method '${method}' on missing remote object ${id}`)
|
||||
}
|
||||
|
||||
return callFunction(event, contextId, obj[method], obj, args)
|
||||
try {
|
||||
return valueToMeta(event.sender, contextId, object[method](...args), true)
|
||||
} catch (error) {
|
||||
const err = new Error(`Could not call remote method '${method}'. Check that the method signature is correct. Underlying error: ${error.message}`)
|
||||
err.cause = error
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
handleRemoteCommand('ELECTRON_BROWSER_MEMBER_SET', function (event, contextId, id, name, args) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue