Skip to content

Commit 1944fdc

Browse files
committed
Track visited parents and null out cycles
1 parent 12382f0 commit 1944fdc

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

lib/browser/guest-window-manager.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@ const hasProp = {}.hasOwnProperty
77
const frameToGuest = {}
88

99
// Copy attribute of |parent| to |child| if it is not defined in |child|.
10-
const mergeOptions = function (child, parent) {
11-
let key, value
12-
for (key in parent) {
10+
const mergeOptions = function (child, parent, visited) {
11+
// Check for circular reference.
12+
if (visited == null) visited = new Set()
13+
if (visited.has(parent)) return
14+
15+
visited.add(parent)
16+
for (const key in parent) {
1317
if (!hasProp.call(parent, key)) continue
14-
value = parent[key]
15-
if (!(key in child)) {
16-
if (typeof value === 'object') {
17-
child[key] = mergeOptions({}, value)
18-
} else {
19-
child[key] = value
20-
}
18+
if (key in child) continue
19+
20+
const value = parent[key]
21+
if (typeof value === 'object') {
22+
child[key] = mergeOptions({}, value, visited)
23+
} else {
24+
child[key] = value
2125
}
2226
}
27+
visited.delete(parent)
28+
2329
return child
2430
}
2531

spec/chromium-spec.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,13 @@ describe('chromium feature', function () {
270270
w = BrowserWindow.fromId(ipcRenderer.sendSync('create-window-with-options-cycle'))
271271
w.loadURL('file://' + fixtures + '/pages/window-open.html')
272272
w.webContents.once('new-window', (event, url, frameName, disposition, options) => {
273-
assert.deepEqual(options, {
274-
show: false,
275-
foo: {
276-
bar: null
273+
assert.equal(options.show, false)
274+
assert.deepEqual(options.foo, {
275+
bar: null,
276+
baz: {
277+
hello: {
278+
world: true
279+
}
277280
}
278281
})
279282
done()

spec/static/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ ipcMain.on('create-window-with-options-cycle', (event) => {
237237
// nulled out at the IPC layer
238238
const foo = {}
239239
foo.bar = foo
240+
foo.baz = {
241+
hello: {
242+
world: true
243+
}
244+
}
240245
const window = new BrowserWindow({show: false, foo: foo})
241246
event.returnValue = window.id
242247
})

0 commit comments

Comments
 (0)