Pass args array instead of arguments object

This commit is contained in:
Kevin Sawicki 2016-12-01 17:29:51 -08:00
parent c27633dff4
commit f894da13b0

View file

@ -88,7 +88,7 @@ const wrapArgs = function (args, visited) {
} }
} }
} }
return Array.prototype.slice.call(args).map(valueToMeta) return args.map(valueToMeta)
} }
// Populate object's members from descriptors. // Populate object's members from descriptors.
@ -102,14 +102,14 @@ const setObjectMembers = function (ref, object, metaId, members) {
let descriptor = { enumerable: member.enumerable } let descriptor = { enumerable: member.enumerable }
if (member.type === 'method') { if (member.type === 'method') {
const remoteMemberFunction = function () { const remoteMemberFunction = function (...args) {
if (this && this.constructor === remoteMemberFunction) { if (this && this.constructor === remoteMemberFunction) {
// Constructor call. // Constructor call.
let ret = ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_CONSTRUCTOR', metaId, member.name, wrapArgs(arguments)) let ret = ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_CONSTRUCTOR', metaId, member.name, wrapArgs(args))
return metaToValue(ret) return metaToValue(ret)
} else { } else {
// Call member function. // Call member function.
let ret = ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_CALL', metaId, member.name, wrapArgs(arguments)) let ret = ipcRenderer.sendSync('ELECTRON_BROWSER_MEMBER_CALL', metaId, member.name, wrapArgs(args))
return metaToValue(ret) return metaToValue(ret)
} }
} }
@ -220,17 +220,17 @@ const metaToValue = function (meta) {
if (meta.type === 'function') { if (meta.type === 'function') {
// A shadow class to represent the remote function object. // A shadow class to represent the remote function object.
let remoteFunction = function () { let remoteFunction = function (...args) {
if (this && this.constructor === remoteFunction) { if (this && this.constructor === remoteFunction) {
// Constructor call. // Constructor call.
let obj = ipcRenderer.sendSync('ELECTRON_BROWSER_CONSTRUCTOR', meta.id, wrapArgs(arguments)) let obj = ipcRenderer.sendSync('ELECTRON_BROWSER_CONSTRUCTOR', meta.id, wrapArgs(args))
// Returning object in constructor will replace constructed object // Returning object in constructor will replace constructed object
// with the returned object. // with the returned object.
// http://stackoverflow.com/questions/1978049/what-values-can-a-constructor-return-to-avoid-returning-this // http://stackoverflow.com/questions/1978049/what-values-can-a-constructor-return-to-avoid-returning-this
return metaToValue(obj) return metaToValue(obj)
} else { } else {
// Function call. // Function call.
let obj = ipcRenderer.sendSync('ELECTRON_BROWSER_FUNCTION_CALL', meta.id, wrapArgs(arguments)) let obj = ipcRenderer.sendSync('ELECTRON_BROWSER_FUNCTION_CALL', meta.id, wrapArgs(args))
return metaToValue(obj) return metaToValue(obj)
} }
} }