Bug 1280347 - Normalize local ExtensionErrors r=mixedpuppy

Normalize errors thrown by extension API implementations in content
processes to ensure that extension code can read the error message
if the error is an instance of ExtensionUtils.ExtensionError.

This code path is triggered in browser_ext_menus_replace.js and
browser_ext_menus_replace_menu_permissions.js.

Depends on D6625

Differential Revision: https://phabricator.services.mozilla.com/D6626

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Rob Wu 2018-09-27 08:21:06 +00:00
parent 444c304d8b
commit a69fd162a2
2 changed files with 15 additions and 2 deletions

View File

@ -939,11 +939,19 @@ class LocalAPIImplementation extends SchemaAPIInterface {
}
callFunction(args) {
return this.pathObj[this.name](...args);
try {
return this.pathObj[this.name](...args);
} catch (e) {
throw this.context.normalizeError(e);
}
}
callFunctionNoReturn(args) {
this.pathObj[this.name](...args);
try {
this.pathObj[this.name](...args);
} catch (e) {
throw this.context.normalizeError(e);
}
}
callAsyncFunction(args, callback, requireUserInput) {

View File

@ -19,6 +19,11 @@
* True if the error matches the expected error.
*/
const errorMatches = (error, expectedError, context) => {
if (typeof error === "object" && error !== null &&
!context.principal.subsumes(Cu.getObjectPrincipal(error))) {
Cu.reportError("Error object belongs to the wrong scope.");
return false;
}
if (expectedError === null) {
return true;
}