@webContents = @getWebContents()
@webContents.once 'destroyed', => @webContents = null
- # Remember the window.
- id = BrowserWindow.windows.add this
+ # Remember the window ID.
+ Object.defineProperty this, 'id',
+ value: BrowserWindow.windows.add(this)
+ enumerable: true
# Remove the window from weak map immediately when it's destroyed, since we
# could be iterating windows before GC happened.
- @once 'closed', ->
- BrowserWindow.windows.remove id if BrowserWindow.windows.has id
+ @once 'closed', =>
+ BrowserWindow.windows.remove @id if BrowserWindow.windows.has @id
BrowserWindow::openDevTools = ->
@_openDevTools()
windows = BrowserWindow.getAllWindows()
return window for window in windows when webContents.equal window.devToolsWebContents
+BrowserWindow.fromId = (id) ->
+ BrowserWindow.windows.get id
+
# Helpers.
BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
assert.equal after[0], size[0]
assert.equal after[1], size[1]
+ describe 'BrowserWindow.fromId(id)', ->
+ it 'returns the window with id', ->
+ assert.equal w.id, BrowserWindow.fromId(w.id).id
+
describe '"use-content-size" option', ->
it 'make window created with content size when used', ->
w.destroy()