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 CallbacksRegistry = require('electron').CallbacksRegistry;
|
||||
const v8Util = process.atomBinding('v8_util');
|
||||
const IDWeakMap = process.atomBinding('id_weak_map').IDWeakMap;
|
||||
|
||||
const callbacksRegistry = new CallbacksRegistry;
|
||||
|
||||
var includes = [].includes;
|
||||
|
||||
var remoteObjectCache = new IDWeakMap;
|
||||
|
||||
// Check for circular reference.
|
||||
var isCircular = function(field, visited) {
|
||||
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
|
||||
// when the object is GCed.
|
||||
v8Util.setDestructor(ret, function() {
|
||||
|
@ -162,6 +168,7 @@ var metaToValue = function(meta) {
|
|||
|
||||
// Remember object's id.
|
||||
v8Util.setHiddenValue(ret, 'atomId', meta.id);
|
||||
remoteObjectCache.set(meta.id, 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() {
|
||||
it('should work when sending an object containing id property', function(done) {
|
||||
var obj = {
|
||||
|
|
Loading…
Reference in a new issue