Merge pull request #9287 from electron/store-frames-to-guest-as-map

Store frames to guest as Map
This commit is contained in:
Kevin Sawicki 2017-04-26 10:47:21 -07:00 committed by GitHub
commit 0aa53f4af7
2 changed files with 24 additions and 4 deletions

View file

@ -5,7 +5,7 @@ const {isSameOrigin} = process.atomBinding('v8_util')
const parseFeaturesString = require('../common/parse-features-string') const parseFeaturesString = require('../common/parse-features-string')
const hasProp = {}.hasOwnProperty const hasProp = {}.hasOwnProperty
const frameToGuest = {} const frameToGuest = new Map()
// Copy attribute of |parent| to |child| if it is not defined in |child|. // Copy attribute of |parent| to |child| if it is not defined in |child|.
const mergeOptions = function (child, parent, visited) { const mergeOptions = function (child, parent, visited) {
@ -92,10 +92,10 @@ const setupGuest = function (embedder, frameName, guest, options) {
guest.once('closed', closedByUser) guest.once('closed', closedByUser)
} }
if (frameName) { if (frameName) {
frameToGuest[frameName] = guest frameToGuest.set(frameName, guest)
guest.frameName = frameName guest.frameName = frameName
guest.once('closed', function () { guest.once('closed', function () {
delete frameToGuest[frameName] frameToGuest.delete(frameName)
}) })
} }
return guestId return guestId
@ -103,7 +103,7 @@ const setupGuest = function (embedder, frameName, guest, options) {
// Create a new guest created by |embedder| with |options|. // Create a new guest created by |embedder| with |options|.
const createGuest = function (embedder, url, frameName, options, postData) { const createGuest = function (embedder, url, frameName, options, postData) {
let guest = frameToGuest[frameName] let guest = frameToGuest.get(frameName)
if (frameName && (guest != null)) { if (frameName && (guest != null)) {
guest.loadURL(url) guest.loadURL(url)
return guest.webContents.id return guest.webContents.id

View file

@ -371,6 +371,26 @@ describe('chromium feature', function () {
window.open('', '', {toString: 3}) window.open('', '', {toString: 3})
}, /Cannot convert object to primitive value/) }, /Cannot convert object to primitive value/)
}) })
it('sets the window title to the specified frameName', function (done) {
let b
app.once('browser-window-created', (event, createdWindow) => {
assert.equal(createdWindow.getTitle(), 'hello')
b.close()
done()
})
b = window.open('', 'hello')
})
it('does not throw an exception when the frameName is a built-in object property', function (done) {
let b
app.once('browser-window-created', (event, createdWindow) => {
assert.equal(createdWindow.getTitle(), '__proto__')
b.close()
done()
})
b = window.open('', '__proto__')
})
}) })
describe('window.opener', function () { describe('window.opener', function () {