Bug 1269400. Provide better error messages for the cases when a CallSetup fails and we hence fail to execute a Web IDL callback. r=bholley

This commit is contained in:
Boris Zbarsky 2016-05-04 13:59:42 -04:00
Родитель 666508a960
Коммит 049c40b0ef
2 изменённых файлов: 14 добавлений и 2 удалений

Просмотреть файл

@ -90,6 +90,9 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
// We don't want to run script in windows that have been navigated away
// from.
if (!win->AsInner()->HasActiveDocument()) {
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
NS_LITERAL_CSTRING("Refusing to execute function from window "
"whose document is no longer active."));
return;
}
globalObject = win;
@ -109,6 +112,9 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
// on gaia-ui tests, probably because nsInProcessTabChildGlobal is returning
// null in some kind of teardown state.
if (!globalObject->GetGlobalJSObject()) {
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
NS_LITERAL_CSTRING("Refusing to execute function from global which is "
"being torn down."));
return;
}
@ -125,6 +131,9 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
// nsIGlobalObject has severed its reference to the JS global. Let's just
// be safe here, so that nobody has to waste a day debugging gaia-ui tests.
if (!incumbent->GetGlobalJSObject()) {
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
NS_LITERAL_CSTRING("Refusing to execute function because our "
"incumbent global is being torn down."));
return;
}
mAutoIncumbentScript.emplace(incumbent);
@ -151,6 +160,9 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
ScriptAllowed(js::GetGlobalForObjectCrossCompartment(realCallback));
if (!allowed) {
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
NS_LITERAL_CSTRING("Refusing to execute function from global in which "
"script is disabled."));
return;
}
}

Просмотреть файл

@ -14879,7 +14879,7 @@ class CGCallback(CGClass):
}
CallSetup s(this, aRv, aExecutionReason, aExceptionHandling, aCompartment);
if (!s.GetContext()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
MOZ_ASSERT(aRv.Failed());
return${errorReturn};
}
""",
@ -15244,7 +15244,7 @@ class CallbackMember(CGNativeMember):
$*{callSetup}
JSContext* cx = s.GetContext();
if (!cx) {
aRv.Throw(NS_ERROR_UNEXPECTED);
MOZ_ASSERT(aRv.Failed());
return${errorReturn};
}
""",