remote: return webcontents instance from cache
This commit is contained in:
parent
25156dbd53
commit
0d77fd4a2c
2 changed files with 15 additions and 0 deletions
|
@ -1,11 +1,14 @@
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const ipcRenderer = require('electron').ipcRenderer;
|
||||||
const CallbacksRegistry = require('electron').CallbacksRegistry;
|
const CallbacksRegistry = require('electron').CallbacksRegistry;
|
||||||
const v8Util = process.atomBinding('v8_util');
|
const v8Util = process.atomBinding('v8_util');
|
||||||
|
const IDWeakMap = process.atomBinding('id_weak_map').IDWeakMap;
|
||||||
|
|
||||||
const callbacksRegistry = new CallbacksRegistry;
|
const callbacksRegistry = new CallbacksRegistry;
|
||||||
|
|
||||||
var includes = [].includes;
|
var includes = [].includes;
|
||||||
|
|
||||||
|
var remoteObjectCache = new IDWeakMap;
|
||||||
|
|
||||||
// Check for circular reference.
|
// Check for circular reference.
|
||||||
var isCircular = function(field, visited) {
|
var isCircular = function(field, visited) {
|
||||||
if (typeof field === 'object') {
|
if (typeof field === 'object') {
|
||||||
|
@ -154,6 +157,9 @@ var metaToValue = function(meta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (remoteObjectCache.has(meta.id))
|
||||||
|
return remoteObjectCache.get(meta.id);
|
||||||
|
|
||||||
// Track delegate object's life time, and tell the browser to clean up
|
// Track delegate object's life time, and tell the browser to clean up
|
||||||
// when the object is GCed.
|
// when the object is GCed.
|
||||||
v8Util.setDestructor(ret, function() {
|
v8Util.setDestructor(ret, function() {
|
||||||
|
@ -162,6 +168,7 @@ var metaToValue = function(meta) {
|
||||||
|
|
||||||
// Remember object's id.
|
// Remember object's id.
|
||||||
v8Util.setHiddenValue(ret, 'atomId', meta.id);
|
v8Util.setHiddenValue(ret, 'atomId', meta.id);
|
||||||
|
remoteObjectCache.set(meta.id, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -90,6 +90,14 @@ describe('ipc module', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('remote webContents', function() {
|
||||||
|
it('can return same object with different getters', function() {
|
||||||
|
var contents1 = remote.getCurrentWindow().webContents;
|
||||||
|
var contents2 = remote.getCurrentWebContents();
|
||||||
|
assert(contents1 == contents2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('ipc.sender.send', function() {
|
describe('ipc.sender.send', function() {
|
||||||
it('should work when sending an object containing id property', function(done) {
|
it('should work when sending an object containing id property', function(done) {
|
||||||
var obj = {
|
var obj = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue