changes from review
This commit is contained in:
parent
d4880b135a
commit
5f6f117bad
1 changed files with 15 additions and 22 deletions
|
@ -12,10 +12,8 @@ const callbacksRegistry = new CallbacksRegistry()
|
||||||
const remoteObjectCache = v8Util.createIDWeakMap()
|
const remoteObjectCache = v8Util.createIDWeakMap()
|
||||||
|
|
||||||
// Convert the arguments object into an array of meta data.
|
// Convert the arguments object into an array of meta data.
|
||||||
function wrapArgs (args, visited) {
|
function wrapArgs (args, visited = new Set()) {
|
||||||
if (visited) visited = new Set()
|
const valueToMeta = (value) => {
|
||||||
|
|
||||||
const valueToMeta = function (value) {
|
|
||||||
// Check for circular reference.
|
// Check for circular reference.
|
||||||
if (visited.has(value)) {
|
if (visited.has(value)) {
|
||||||
return {
|
return {
|
||||||
|
@ -59,7 +57,7 @@ function wrapArgs (args, visited) {
|
||||||
|
|
||||||
let meta = {
|
let meta = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
name: (value.constructor) ? value.constructor.name : '',
|
name: value.constructor ? value.constructor.name : '',
|
||||||
members: []
|
members: []
|
||||||
}
|
}
|
||||||
visited.add(value)
|
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)
|
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
|
// Meta will be non-null when a setter error occurred so parse it
|
||||||
// to a value so it gets re-thrown.
|
// to a value so it gets re-thrown.
|
||||||
if (meta) metaToValue(meta)
|
if (meta != null) metaToValue(meta)
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,10 +205,7 @@ function proxyFunctionProperties (remoteMemberFunction, metaId, name) {
|
||||||
function metaToValue (meta) {
|
function metaToValue (meta) {
|
||||||
const types = {
|
const types = {
|
||||||
'value': () => meta.value,
|
'value': () => meta.value,
|
||||||
'array': () => {
|
'array': () => meta.members.map((member) => metaToValue(member)),
|
||||||
const members = meta.members
|
|
||||||
return members.map((member) => metaToValue(member))
|
|
||||||
},
|
|
||||||
'buffer': () => Buffer.from(meta.value),
|
'buffer': () => Buffer.from(meta.value),
|
||||||
'promise': () => resolvePromise({then: metaToValue(meta.then)}),
|
'promise': () => resolvePromise({then: metaToValue(meta.then)}),
|
||||||
'error': () => metaToPlainObject(meta),
|
'error': () => metaToPlainObject(meta),
|
||||||
|
@ -219,7 +214,7 @@ function metaToValue (meta) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta.type in types) {
|
if (meta.type in types) {
|
||||||
types[meta.type]()
|
return types[meta.type]
|
||||||
} else {
|
} else {
|
||||||
let ret
|
let ret
|
||||||
if (remoteObjectCache.has(meta.id)) return remoteObjectCache.get(meta.id)
|
if (remoteObjectCache.has(meta.id)) return remoteObjectCache.get(meta.id)
|
||||||
|
@ -278,44 +273,42 @@ process.on('exit', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Get remote module.
|
// Get remote module.
|
||||||
exports.require = function (module) {
|
exports.require = (module) => {
|
||||||
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_REQUIRE', module))
|
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_REQUIRE', module))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alias to remote.require('electron').xxx.
|
// Alias to remote.require('electron').xxx.
|
||||||
exports.getBuiltin = function (module) {
|
exports.getBuiltin = (module) => {
|
||||||
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_GET_BUILTIN', module))
|
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_GET_BUILTIN', module))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current BrowserWindow.
|
// Get current BrowserWindow.
|
||||||
exports.getCurrentWindow = function () {
|
exports.getCurrentWindow = () => {
|
||||||
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_CURRENT_WINDOW'))
|
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_CURRENT_WINDOW'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current WebContents object.
|
// Get current WebContents object.
|
||||||
exports.getCurrentWebContents = function () {
|
exports.getCurrentWebContents = () => {
|
||||||
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_CURRENT_WEB_CONTENTS'))
|
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_CURRENT_WEB_CONTENTS'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a global object in browser.
|
// Get a global object in browser.
|
||||||
exports.getGlobal = function (name) {
|
exports.getGlobal = (name) => {
|
||||||
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_GLOBAL', name))
|
return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_GLOBAL', name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the process object in browser.
|
// Get the process object in browser.
|
||||||
exports.__defineGetter__('process', function () {
|
exports.__defineGetter__('process', () => exports.getGlobal('process'))
|
||||||
return exports.getGlobal('process')
|
|
||||||
})
|
|
||||||
|
|
||||||
// Create a funtion that will return the specifed value when called in browser.
|
// Create a function that will return the specified value when called in browser.
|
||||||
exports.createFunctionWithReturnValue = function (returnValue) {
|
exports.createFunctionWithReturnValue = (returnValue) => {
|
||||||
const func = () => returnValue
|
const func = () => returnValue
|
||||||
v8Util.setHiddenValue(func, 'returnValue', true)
|
v8Util.setHiddenValue(func, 'returnValue', true)
|
||||||
return func
|
return func
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the guest WebContents from guestInstanceId.
|
// Get the guest WebContents from guestInstanceId.
|
||||||
exports.getGuestWebContents = function (guestInstanceId) {
|
exports.getGuestWebContents = (guestInstanceId) => {
|
||||||
const meta = ipcRenderer.sendSync('ELECTRON_BROWSER_GUEST_WEB_CONTENTS', guestInstanceId)
|
const meta = ipcRenderer.sendSync('ELECTRON_BROWSER_GUEST_WEB_CONTENTS', guestInstanceId)
|
||||||
return metaToValue(meta)
|
return metaToValue(meta)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue