Use DoubleIDWeakMap for |rendererFunctions|

This commit is contained in:
Cheng Zhao 2016-05-11 20:40:48 +09:00
parent 49ac160ff7
commit 759a46f3d6
3 changed files with 54 additions and 16 deletions

View file

@ -13,18 +13,7 @@ const FUNCTION_PROPERTIES = [
// The remote functions in renderer processes.
// id => Function
let rendererFunctions = v8Util.createIDWeakMap()
// Merge two IDs together.
let mergeIds = function (webContentsId, metaId) {
const PADDING_BITS = 20
if ((webContentsId << PADDING_BITS) < 0) {
throw new Error(`webContents ID is too large: ${webContentsId}`)
} else if (metaId > (1 << PADDING_BITS)) {
throw new Error(`Object ID is too large: ${metaId}`)
}
return (webContentsId << PADDING_BITS) + metaId
}
let rendererFunctions = v8Util.createDoubleIDWeakMap()
// Return the description of object's members:
let getObjectMembers = function (object) {
@ -179,7 +168,7 @@ var unwrapArgs = function (sender, args) {
// Merge webContentsId and meta.id, since meta.id can be the same in
// different webContents.
const webContentsId = sender.getId()
const objectId = mergeIds(webContentsId, meta.id)
const objectId = [webContentsId, meta.id]
// Cache the callbacks in renderer.
if (rendererFunctions.has(objectId)) {