diff --git a/dom/base/nsINode.cpp b/dom/base/nsINode.cpp index 0d29bce254c5..3e939bce5384 100644 --- a/dom/base/nsINode.cpp +++ b/dom/base/nsINode.cpp @@ -2899,6 +2899,9 @@ nsINode::WrapObject(JSContext *aCx, JS::Handle aGivenProto) if (!OwnerDoc()->GetScriptHandlingObject(hasHadScriptHandlingObject) && !hasHadScriptHandlingObject && !nsContentUtils::IsSystemCaller(aCx)) { + if (IsDocument()) { + MOZ_CRASH("Looks like bug 1488480/1405521, with a document that lost its script handling object"); + } Throw(aCx, NS_ERROR_UNEXPECTED); return nullptr; } @@ -2907,6 +2910,9 @@ nsINode::WrapObject(JSContext *aCx, JS::Handle aGivenProto) MOZ_ASSERT_IF(obj && ChromeOnlyAccess(), xpc::IsInContentXBLScope(obj) || !xpc::UseContentXBLScope(JS::GetObjectRealmOrNull(obj))); + if (!obj && IsDocument()) { + MOZ_CRASH("Looks like bug 1488480/1405521, with WrapNode on a document returning null"); + } return obj; } diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 2e4fc7d56bf6..8ec2de667f93 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -3496,7 +3496,7 @@ class CGConstructorEnabled(CGAbstractMethod): return body.define() -def CreateBindingJSObject(descriptor, properties): +def CreateBindingJSObject(descriptor, properties, failureCode = ""): objDecl = "BindingJSObjectCreator<%s> creator(aCx);\n" % descriptor.nativeType # We don't always need to root obj, but there are a variety @@ -3521,12 +3521,14 @@ def CreateBindingJSObject(descriptor, properties): """ creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); """) - return objDecl + create + dedent( + return objDecl + create + fill( """ if (!aReflector) { + $*{failureCode} return false; } - """) + """, + failureCode=failureCode) def InitUnforgeablePropertiesOnHolder(descriptor, properties, failureCode, @@ -3696,14 +3698,15 @@ def SetImmutablePrototype(descriptor, failureCode): failureCode=failureCode) -def DeclareProto(): +def DeclareProto(noProto = "", wrapFail = ""): """ Declare the canonicalProto and proto we have for our wrapping operation. """ - return dedent( + return fill( """ JS::Handle canonicalProto = GetProtoObjectHandle(aCx); if (!canonicalProto) { + $*{noProto} return false; } JS::Rooted proto(aCx); @@ -3714,13 +3717,16 @@ def DeclareProto(): // to wrap the proto here. if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { if (!JS_WrapObject(aCx, &proto)) { + $*{wrapFail} return false; } } } else { proto = canonicalProto; } - """) + """, + noProto=noProto, + wrapFail=wrapFail) class CGWrapWithCacheMethod(CGAbstractMethod): @@ -3747,6 +3753,47 @@ class CGWrapWithCacheMethod(CGAbstractMethod): return false; """) + isDocument = False + iface = self.descriptor.interface + while iface: + if iface.identifier.name == "Document": + isDocument = True + break + iface = iface.parent + + if isDocument: + noGlobal = fill( + """ + MOZ_CRASH("Looks like bug 1488480/1405521, with ${name} not having a global"); + """, + name = self.descriptor.name) + noProto = fill( + """ + MOZ_CRASH("Looks like bug 1488480/1405521, with ${name} not having a proto"); + """, + name = self.descriptor.name) + protoWrapFail = fill( + """ + MOZ_CRASH("Looks like bug 1488480/1405521, with ${name} failing to wrap a custom proto"); + """, + name = self.descriptor.name) + createObjectFailed = fill( + """ + MOZ_CRASH("Looks like bug 1488480/1405521, with ${name} failing to CreateObject/CreateProxyObject"); + """, + name = self.descriptor.name) + expandoAllocFail = fill( + """ + MOZ_CRASH("Looks like bug 1488480/1405521, with ${name} failing to EnsureExpandoObject or JS_InitializePropertiesFromCompatibleNativeObject"); + """, + name = self.descriptor.name) + else: + noGlobal = "" + noProto = "" + protoWrapFail = "" + createObjectFailed = "" + expandoAllocFail = "" + return fill( """ static_assert(!IsBaseOf::value, @@ -3762,6 +3809,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod): JS::Rooted global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); if (!global) { + $*{noGlobal} return false; } MOZ_ASSERT(JS_IsGlobalObject(global)); @@ -3802,11 +3850,14 @@ class CGWrapWithCacheMethod(CGAbstractMethod): return true; """, + noGlobal=noGlobal, nativeType=self.descriptor.nativeType, assertInheritance=AssertInheritanceChain(self.descriptor), - declareProto=DeclareProto(), - createObject=CreateBindingJSObject(self.descriptor, self.properties), + declareProto=DeclareProto(noProto, protoWrapFail), + createObject=CreateBindingJSObject(self.descriptor, self.properties, + createObjectFailed), unforgeable=CopyUnforgeablePropertiesToInstance(self.descriptor, + expandoAllocFail + failureCode), slots=InitMemberSlots(self.descriptor, failureCode), setImmutablePrototype=SetImmutablePrototype(self.descriptor, diff --git a/dom/html/ImageDocument.cpp b/dom/html/ImageDocument.cpp index 834b75479310..446d61b77cb6 100644 --- a/dom/html/ImageDocument.cpp +++ b/dom/html/ImageDocument.cpp @@ -200,7 +200,11 @@ ImageDocument::Init() JSObject* ImageDocument::WrapNode(JSContext* aCx, JS::Handle aGivenProto) { - return ImageDocument_Binding::Wrap(aCx, this, aGivenProto); + JSObject* obj = ImageDocument_Binding::Wrap(aCx, this, aGivenProto); + if (!obj) { + MOZ_CRASH("Looks like bug 1488480/1405521, with ImageDocument::WrapNode failing"); + } + return obj; } nsresult diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index 6184b5204da3..b681482dfce9 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -202,7 +202,11 @@ NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(nsHTMLDocument, JSObject* nsHTMLDocument::WrapNode(JSContext* aCx, JS::Handle aGivenProto) { - return HTMLDocument_Binding::Wrap(aCx, this, aGivenProto); + JSObject* obj = HTMLDocument_Binding::Wrap(aCx, this, aGivenProto); + if (!obj) { + MOZ_CRASH("Looks like bug 1488480/1405521, with nsHTMLDocument::WrapNode failing"); + } + return obj; } nsresult diff --git a/dom/xml/XMLDocument.cpp b/dom/xml/XMLDocument.cpp index 81647f28be44..84c6d706b3a1 100644 --- a/dom/xml/XMLDocument.cpp +++ b/dom/xml/XMLDocument.cpp @@ -627,11 +627,16 @@ XMLDocument::Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const JSObject* XMLDocument::WrapNode(JSContext *aCx, JS::Handle aGivenProto) { + JSObject* obj; if (mIsPlainDocument) { - return Document_Binding::Wrap(aCx, this, aGivenProto); + obj = Document_Binding::Wrap(aCx, this, aGivenProto); + } else { + obj = XMLDocument_Binding::Wrap(aCx, this, aGivenProto); } - - return XMLDocument_Binding::Wrap(aCx, this, aGivenProto); + if (!obj) { + MOZ_CRASH("Looks like bug 1488480/1405521, with XMLDocument::WrapNode failing"); + } + return obj; } } // namespace dom diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp index d222cff16798..9a1bced2ba86 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -2506,7 +2506,11 @@ XULDocument::DirectionChanged(const char* aPrefName, XULDocument* aDoc) JSObject* XULDocument::WrapNode(JSContext *aCx, JS::Handle aGivenProto) { - return XULDocument_Binding::Wrap(aCx, this, aGivenProto); + JSObject* obj = XULDocument_Binding::Wrap(aCx, this, aGivenProto); + if (!obj) { + MOZ_CRASH("Looks like bug 1488480/1405521, with XULDocument_Binding::Wrap failing"); + } + return obj; } } // namespace dom