Browse Source

Backport (2-0-x) - Check menu.popup options are an object (#12330)

* check menu.popup options are an object

* Add a spec for menu.popup options check

* remove stray .only
trop[bot] 7 years ago
parent
commit
0cc4584352
2 changed files with 9 additions and 0 deletions
  1. 3 0
      lib/browser/api/menu.js
  2. 6 0
      spec/api-menu-spec.js

+ 3 - 0
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

+ 6 - 0
spec/api-menu-spec.js

@@ -332,6 +332,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})