Bug 1166351 - Add an assertion to make sure that we use the correct cached XBL binding prototypes. r?bholley
MozReview-Commit-ID: 7MfslXmortQ
--- a/dom/xbl/nsXBLBinding.cpp
+++ b/dom/xbl/nsXBLBinding.cpp
@@ -952,16 +952,25 @@ GetOrCreateMapEntryForPrototype(JSContex
if (!JS::SetWeakMapEntry(cx, map, wrappedProto, entryVal)) {
NS_WARNING("SetWeakMapEntry failed, probably due to non-preservable WeakMap "
"key. XBL binding will fail for this element.");
return nullptr;
}
return entry;
}
+static
+nsXBLPrototypeBinding*
+GetProtoBindingFromClassObject(JSObject* obj)
+{
+ MOZ_ASSERT(JS_GetClass(obj) == &gPrototypeJSClass);
+ return static_cast<nsXBLPrototypeBinding*>(::JS_GetReservedSlot(obj, 0).toPrivate());
+}
+
+
// static
nsresult
nsXBLBinding::DoInitJSClass(JSContext *cx,
JS::Handle<JSObject*> obj,
const nsAFlatString& aClassName,
nsXBLPrototypeBinding* aProtoBinding,
JS::MutableHandle<JSObject*> aClassObject,
bool* aNew)
@@ -1007,17 +1016,19 @@ nsXBLBinding::DoInitJSClass(JSContext *c
JS::Rooted<JSObject*> proto(cx);
JS::Rooted<JS::PropertyDescriptor> desc(cx);
if (!JS_GetOwnUCPropertyDescriptor(cx, holder, aClassName.get(), &desc)) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aNew = !desc.object();
if (desc.object()) {
proto = &desc.value().toObject();
- MOZ_ASSERT(JS_GetClass(js::UncheckedUnwrap(proto)) == &gPrototypeJSClass);
+ DebugOnly<nsXBLPrototypeBinding*> cachedBinding =
+ GetProtoBindingFromClassObject(js::UncheckedUnwrap(proto));
+ MOZ_ASSERT(cachedBinding == aProtoBinding);
} else {
// We need to create the prototype. First, enter the compartment where it's
// going to live, and create it.
JSAutoCompartment ac2(cx, global);
proto = JS_NewObjectWithGivenProto(cx, &gPrototypeJSClass, parent_proto);
if (!proto) {
return NS_ERROR_OUT_OF_MEMORY;