From 35cbe9d14078a0a6676fd66d5099606bb7e6112a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 27 Feb 2018 15:15:06 +0900 Subject: [PATCH] Fix dockMenu not being referenced in JavaScript (#12062) * Fix dockMenu not being referenced in JavaScript * spec: Test garbage collecting dock menu --- lib/browser/api/app.js | 10 +++++++++- spec/api-app-spec.js | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/browser/api/app.js b/lib/browser/api/app.js index 381a2a866372..1ea1daddca84 100644 --- a/lib/browser/api/app.js +++ b/lib/browser/api/app.js @@ -10,6 +10,8 @@ const electron = require('electron') const {deprecate, Menu} = electron const {EventEmitter} = require('events') +let dockMenu = null + // App is an EventEmitter. Object.setPrototypeOf(App.prototype, EventEmitter.prototype) EventEmitter.call(app) @@ -49,7 +51,13 @@ if (process.platform === 'darwin') { hide: bindings.dockHide, show: bindings.dockShow, isVisible: bindings.dockIsVisible, - setMenu: bindings.dockSetMenu, + setMenu (menu) { + dockMenu = menu + bindings.dockSetMenu(menu) + }, + getMenu () { + return dockMenu + }, setIcon: bindings.dockSetIcon } } diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 0eda951b15d6..9fb28e3eb4c5 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -7,7 +7,7 @@ const path = require('path') const {ipcRenderer, remote} = require('electron') const {closeWindow} = require('./window-helpers') -const {app, BrowserWindow, ipcMain} = remote +const {app, BrowserWindow, Menu, ipcMain} = remote const isCI = remote.getGlobal('isCi') @@ -881,4 +881,18 @@ describe('app module', () => { }, /before app is ready/) }) }) + + describe('dock.setMenu', () => { + before(function () { + if (process.platform !== 'darwin') { + this.skip() + } + }) + + it('keeps references to the menu', () => { + app.dock.setMenu(new Menu()) + const v8Util = process.atomBinding('v8_util') + v8Util.requestGarbageCollectionForTesting() + }) + }) })