From 31d688ad3dcf00852c45a00107e8ea95efee0f1e Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Sat, 17 Mar 2018 06:31:10 +0900 Subject: [PATCH] Check menu.popup options are an object (#12325) * check menu.popup options are an object * Add a spec for menu.popup options check * remove stray .only --- lib/browser/api/menu.js | 3 +++ spec/api-menu-spec.js | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index da5ff57a113f..e246a0894785 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -47,6 +47,9 @@ Menu.prototype._init = function () { } Menu.prototype.popup = function (options) { + if (options == null || typeof options !== 'object') { + throw new TypeError('Options must be an object') + } let {window, x, y, positioningItem, callback} = options // no callback passed diff --git a/spec/api-menu-spec.js b/spec/api-menu-spec.js index eb8fe3d63b2f..9aff30beeb6b 100644 --- a/spec/api-menu-spec.js +++ b/spec/api-menu-spec.js @@ -309,6 +309,12 @@ describe('Menu module', () => { return closeWindow(w).then(() => { w = null }) }) + it('throws an error if options is not an object', () => { + assert.throws(() => { + menu.popup() + }, /Options must be an object/) + }) + it('should emit menu-will-show event', (done) => { menu.on('menu-will-show', () => { done() }) menu.popup({window: w})