From 5f6f117bad369c59e9109b58af25ad0a678d06a8 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 25 Oct 2017 23:41:11 -0400 Subject: [PATCH] changes from review --- lib/renderer/api/remote.js | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/lib/renderer/api/remote.js b/lib/renderer/api/remote.js index f115215f311b..e38c531c90a5 100644 --- a/lib/renderer/api/remote.js +++ b/lib/renderer/api/remote.js @@ -12,10 +12,8 @@ const callbacksRegistry = new CallbacksRegistry() const remoteObjectCache = v8Util.createIDWeakMap() // Convert the arguments object into an array of meta data. -function wrapArgs (args, visited) { - if (visited) visited = new Set() - - const valueToMeta = function (value) { +function wrapArgs (args, visited = new Set()) { + const valueToMeta = (value) => { // Check for circular reference. if (visited.has(value)) { return { @@ -59,7 +57,7 @@ function wrapArgs (args, visited) { let meta = { type: 'object', - name: (value.constructor) ? value.constructor.name : '', + name: value.constructor ? value.constructor.name : '', members: [] } visited.add(value) @@ -140,7 +138,7 @@ function setObjectMembers (ref, object, metaId, members) { const meta = ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_SET', metaId, member.name, args) // Meta will be non-null when a setter error occurred so parse it // to a value so it gets re-thrown. - if (meta) metaToValue(meta) + if (meta != null) metaToValue(meta) return value } } @@ -207,10 +205,7 @@ function proxyFunctionProperties (remoteMemberFunction, metaId, name) { function metaToValue (meta) { const types = { 'value': () => meta.value, - 'array': () => { - const members = meta.members - return members.map((member) => metaToValue(member)) - }, + 'array': () => meta.members.map((member) => metaToValue(member)), 'buffer': () => Buffer.from(meta.value), 'promise': () => resolvePromise({then: metaToValue(meta.then)}), 'error': () => metaToPlainObject(meta), @@ -219,7 +214,7 @@ function metaToValue (meta) { } if (meta.type in types) { - types[meta.type]() + return types[meta.type] } else { let ret if (remoteObjectCache.has(meta.id)) return remoteObjectCache.get(meta.id) @@ -278,44 +273,42 @@ process.on('exit', () => { }) // Get remote module. -exports.require = function (module) { +exports.require = (module) => { return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_REQUIRE', module)) } // Alias to remote.require('electron').xxx. -exports.getBuiltin = function (module) { +exports.getBuiltin = (module) => { return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_GET_BUILTIN', module)) } // Get current BrowserWindow. -exports.getCurrentWindow = function () { +exports.getCurrentWindow = () => { return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_CURRENT_WINDOW')) } // Get current WebContents object. -exports.getCurrentWebContents = function () { +exports.getCurrentWebContents = () => { return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_CURRENT_WEB_CONTENTS')) } // Get a global object in browser. -exports.getGlobal = function (name) { +exports.getGlobal = (name) => { return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_GLOBAL', name)) } // Get the process object in browser. -exports.__defineGetter__('process', function () { - return exports.getGlobal('process') -}) +exports.__defineGetter__('process', () => exports.getGlobal('process')) -// Create a funtion that will return the specifed value when called in browser. -exports.createFunctionWithReturnValue = function (returnValue) { +// Create a function that will return the specified value when called in browser. +exports.createFunctionWithReturnValue = (returnValue) => { const func = () => returnValue v8Util.setHiddenValue(func, 'returnValue', true) return func } // Get the guest WebContents from guestInstanceId. -exports.getGuestWebContents = function (guestInstanceId) { +exports.getGuestWebContents = (guestInstanceId) => { const meta = ipcRenderer.sendSync('ELECTRON_BROWSER_GUEST_WEB_CONTENTS', guestInstanceId) return metaToValue(meta) }