From 90600ba653d2d17bfd739cc49403a3e322caa61a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 22 Jun 2016 10:06:54 -0700 Subject: [PATCH 1/2] Add failing spec for writeable command id --- spec/api-menu-spec.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/api-menu-spec.js b/spec/api-menu-spec.js index 34ce250778..d6ac56475f 100644 --- a/spec/api-menu-spec.js +++ b/spec/api-menu-spec.js @@ -357,10 +357,23 @@ describe('menu module', function () { }) }) + describe('MenuItem command id', function () { + it('cannot be overwritten', function () { + var item = new MenuItem({ + label: 'item' + }) + + var commandId = item.commandId + assert(commandId != null) + item.commandId = '' + commandId + '-modified' + assert.equal(item.commandId, commandId) + }) + }) + describe('MenuItem with invalid type', function () { it('throws an exception', function () { assert.throws(function () { - var menu = Menu.buildFromTemplate([ + Menu.buildFromTemplate([ { label: 'text', type: 'not-a-type' @@ -373,7 +386,7 @@ describe('menu module', function () { describe('MenuItem with submenu type and missing submenu', function () { it('throws an exception', function () { assert.throws(function () { - var menu = Menu.buildFromTemplate([ + Menu.buildFromTemplate([ { label: 'text', type: 'submenu' From ad110fc806a94e16a5ead9288b5d041bc3e997b5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 22 Jun 2016 10:07:02 -0700 Subject: [PATCH 2/2] Make commandId a read only property --- lib/browser/api/menu-item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/browser/api/menu-item.js b/lib/browser/api/menu-item.js index e1ccda4886..264be81790 100644 --- a/lib/browser/api/menu-item.js +++ b/lib/browser/api/menu-item.js @@ -72,7 +72,7 @@ const MenuItem = function (options) { throw new Error(`Unknown menu item type: ${this.type}`) } - this.commandId = ++nextCommandId + this.overrideReadOnlyProperty('commandId', ++nextCommandId) const click = options.click this.click = (event, focusedWindow) => {