mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-02 07:05:24 +00:00
Bug 1211366 - parentId validation in contextMenus. r=kmaglione
This commit is contained in:
parent
c3b77c61e9
commit
99d250bd13
@ -240,20 +240,33 @@ MenuItem.prototype = {
|
|||||||
return this._id;
|
return this._id;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
ensureValidParentId(parentId) {
|
||||||
|
if (parentId === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let menuMap = contextMenuMap.get(this.extension);
|
||||||
|
if (!menuMap.has(parentId)) {
|
||||||
|
throw new Error("Could not find any MenuItem with id: " + parentId);
|
||||||
|
}
|
||||||
|
for (let item = menuMap.get(parentId); item; item = item.parent) {
|
||||||
|
if (item === this) {
|
||||||
|
throw new Error("MenuItem cannot be an ancestor (or self) of its new parent.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
set parentId(parentId) {
|
set parentId(parentId) {
|
||||||
// TODO: cycle check here
|
this.ensureValidParentId(parentId);
|
||||||
|
|
||||||
if (this.parent) {
|
if (this.parent) {
|
||||||
this.parent.detachChild(this);
|
this.parent.detachChild(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
let menuMap = contextMenuMap.get(this.extension);
|
if (parentId === undefined) {
|
||||||
if (menuMap.has(parentId)) {
|
this.root.addChild(this);
|
||||||
|
} else {
|
||||||
|
let menuMap = contextMenuMap.get(this.extension);
|
||||||
menuMap.get(parentId).addChild(this);
|
menuMap.get(parentId).addChild(this);
|
||||||
} else if (parentId !== undefined) {
|
|
||||||
// Unless the intention was to null the parentId, if we cannot find
|
|
||||||
// any item with the given id, we should throw.
|
|
||||||
let e = new Error("Could not find any MenuItem with id: " + parentId);
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -54,7 +54,12 @@ add_task(function* () {
|
|||||||
{ title: "child2", parentId: parentToDel, onclick: genericOnClick });
|
{ title: "child2", parentId: parentToDel, onclick: genericOnClick });
|
||||||
browser.contextMenus.remove(parentToDel);
|
browser.contextMenus.remove(parentToDel);
|
||||||
|
|
||||||
browser.test.notifyPass();
|
try {
|
||||||
|
browser.contextMenus.update(parent, { parentId: child2 });
|
||||||
|
browser.test.notifyFail();
|
||||||
|
} catch(e) {
|
||||||
|
browser.test.notifyPass();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user