Bug 867863. Be a little more careful in GlobalObject initialization. r=peterv

This commit is contained in:
Boris Zbarsky 2013-05-08 15:50:58 -04:00
parent 5a20ce811f
commit 797571f64b
3 changed files with 15 additions and 5 deletions

View File

@ -1631,6 +1631,7 @@ GlobalObject::GlobalObject(JSContext* aCx, JSObject* aObject)
Maybe<JSAutoCompartment> ac;
mGlobalJSObject = GetGlobalObject<true>(aCx, aObject, ac);
if (!mGlobalJSObject) {
mGlobalObject = nullptr;
return;
}
@ -1717,14 +1718,18 @@ InterfaceHasInstance(JSContext* cx, JSHandleObject obj, JSMutableHandleValue vp,
return InterfaceHasInstance(cx, obj, instanceObject, bp);
}
void
bool
ReportLenientThisUnwrappingFailure(JSContext* cx, JS::Handle<JSObject*> obj)
{
GlobalObject global(cx, obj);
if (global.Failed()) {
return false;
}
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global.Get());
if (window && window->GetDoc()) {
window->GetDoc()->WarnOnceAbout(nsIDocument::eLenientThis);
}
return true;
}
// Date implementation methods

View File

@ -1768,8 +1768,9 @@ JSBool
InterfaceHasInstance(JSContext* cx, JSHandleObject obj, JSMutableHandleValue vp,
JSBool* bp);
// Helper for lenient getters/setters to report to console
void
// Helper for lenient getters/setters to report to console. If this
// returns false, we couldn't even get a global.
bool
ReportLenientThisUnwrappingFailure(JSContext* cx, JS::Handle<JSObject*> obj);
inline JSObject*

View File

@ -5010,7 +5010,9 @@ class CGGenericGetter(CGAbstractBindingMethod):
name = "genericLenientGetter"
unwrapFailureCode = (
"MOZ_ASSERT(!JS_IsExceptionPending(cx));\n"
"ReportLenientThisUnwrappingFailure(cx, obj);\n"
"if (!ReportLenientThisUnwrappingFailure(cx, obj)) {\n"
" return false;\n"
"}\n"
"JS_SET_RVAL(cx, vp, JS::UndefinedValue());\n"
"return true;")
else:
@ -5087,7 +5089,9 @@ class CGGenericSetter(CGAbstractBindingMethod):
name = "genericLenientSetter"
unwrapFailureCode = (
"MOZ_ASSERT(!JS_IsExceptionPending(cx));\n"
"ReportLenientThisUnwrappingFailure(cx, obj);\n"
"if (!ReportLenientThisUnwrappingFailure(cx, obj)) {\n"
" return false;\n"
"}\n"
"JS_SET_RVAL(cx, vp, JS::UndefinedValue());\n"
"return true;")
else: