diff --git a/browser/api/lib/dialog.coffee b/browser/api/lib/dialog.coffee index 7cf538b2f41..5b333f4a13b 100644 --- a/browser/api/lib/dialog.coffee +++ b/browser/api/lib/dialog.coffee @@ -1,4 +1,5 @@ binding = process.atomBinding 'dialog' +v8Util = process.atomBinding 'v8_util' BrowserWindow = require 'browser-window' fileDialogProperties = @@ -72,3 +73,6 @@ module.exports = String(options.detail), window, callback + +# Mark standard asynchronous functions. +v8Util.setHiddenValue f, 'asynchronous', true for k, f of module.exports diff --git a/browser/atom/rpc-server.coffee b/browser/atom/rpc-server.coffee index 0e5c707c403..04d5fe2c948 100644 --- a/browser/atom/rpc-server.coffee +++ b/browser/atom/rpc-server.coffee @@ -61,6 +61,17 @@ unwrapArgs = (processId, routingId, args) -> 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. +callFunction = (event, processId, routingId, func, caller, args) -> + if v8Util.getHiddenValue(func, 'asynchronous') and typeof args[args.length - 1] isnt 'function' + args.push (ret) -> + event.returnValue = valueToMeta processId, routingId, ret + func.apply caller, args + else + ret = func.apply caller, args + event.returnValue = valueToMeta processId, routingId, ret + ipc.on 'ATOM_BROWSER_REQUIRE', (event, processId, routingId, module) -> try event.returnValue = valueToMeta processId, routingId, require(module) @@ -100,8 +111,7 @@ ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, processId, routingId, id, args) -> try args = unwrapArgs processId, routingId, args func = objectsRegistry.get id - ret = func.apply global, args - event.returnValue = valueToMeta processId, routingId, ret + callFunction event, processId, routingId, func, global, args catch e event.returnValue = errorToMeta e @@ -119,8 +129,7 @@ ipc.on 'ATOM_BROWSER_MEMBER_CALL', (event, processId, routingId, id, method, arg try args = unwrapArgs processId, routingId, args obj = objectsRegistry.get id - ret = obj[method].apply(obj, args) - event.returnValue = valueToMeta processId, routingId, ret + callFunction event, processId, routingId, obj[method], obj, args catch e event.returnValue = errorToMeta e