Bug 1493849 part 2. Add instrumentation to nsIDocument::WrapObject to figure out why it fails sometimes. r=mccr8

This commit is contained in:
Boris Zbarsky 2018-09-25 13:35:07 -04:00
parent f1812532b6
commit a6e3c61c96
6 changed files with 88 additions and 14 deletions

View File

@ -2899,6 +2899,9 @@ nsINode::WrapObject(JSContext *aCx, JS::Handle<JSObject*> 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<JSObject*> 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;
}

View File

@ -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<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
if (!canonicalProto) {
$*{noProto}
return false;
}
JS::Rooted<JSObject*> 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<NonRefcountedDOMObject, ${nativeType}>::value,
@ -3762,6 +3809,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
JS::Rooted<JSObject*> 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,

View File

@ -200,7 +200,11 @@ ImageDocument::Init()
JSObject*
ImageDocument::WrapNode(JSContext* aCx, JS::Handle<JSObject*> 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

View File

@ -202,7 +202,11 @@ NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(nsHTMLDocument,
JSObject*
nsHTMLDocument::WrapNode(JSContext* aCx, JS::Handle<JSObject*> 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

View File

@ -627,11 +627,16 @@ XMLDocument::Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const
JSObject*
XMLDocument::WrapNode(JSContext *aCx, JS::Handle<JSObject*> 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

View File

@ -2506,7 +2506,11 @@ XULDocument::DirectionChanged(const char* aPrefName, XULDocument* aDoc)
JSObject*
XULDocument::WrapNode(JSContext *aCx, JS::Handle<JSObject*> 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