Bug 1036507 - Introduce and use StandardProtoKeyOrNull. r=luke
authorBobby Holley <bobbyholley@gmail.com>
Fri, 11 Jul 2014 09:09:21 -0700
changeset 193609 885474ab4f1a44590e45b00ad0fecf6499528150
parent 193608 e4bb9cd85bef147e018ef6f3616a8b36c5263726
child 193610 2f058f0f4c1cc062ac9981c1988defe1677bece9
push id27123
push userryanvm@gmail.com
push dateFri, 11 Jul 2014 20:35:05 +0000
treeherdermozilla-central@84bd8d9f4256 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1036507
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1036507 - Introduce and use StandardProtoKeyOrNull. r=luke
js/src/jsobj.cpp
js/src/vm/GlobalObject.h
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -3419,37 +3419,37 @@ IsStandardPrototype(JSObject *obj, JSPro
     return v.isObject() && obj == &v.toObject();
 }
 
 JSProtoKey
 JS::IdentifyStandardInstance(JSObject *obj)
 {
     // Note: The prototype shares its JSClass with instances.
     JS_ASSERT(!obj->is<CrossCompartmentWrapperObject>());
-    JSProtoKey key = JSCLASS_CACHED_PROTO_KEY(obj->getClass());
+    JSProtoKey key = StandardProtoKeyOrNull(obj);
     if (key != JSProto_Null && !IsStandardPrototype(obj, key))
         return key;
     return JSProto_Null;
 }
 
 JSProtoKey
 JS::IdentifyStandardPrototype(JSObject *obj)
 {
     // Note: The prototype shares its JSClass with instances.
     JS_ASSERT(!obj->is<CrossCompartmentWrapperObject>());
-    JSProtoKey key = JSCLASS_CACHED_PROTO_KEY(obj->getClass());
+    JSProtoKey key = StandardProtoKeyOrNull(obj);
     if (key != JSProto_Null && IsStandardPrototype(obj, key))
         return key;
     return JSProto_Null;
 }
 
 JSProtoKey
 JS::IdentifyStandardInstanceOrPrototype(JSObject *obj)
 {
-    return JSCLASS_CACHED_PROTO_KEY(obj->getClass());
+    return StandardProtoKeyOrNull(obj);
 }
 
 JSProtoKey
 JS::IdentifyStandardConstructor(JSObject *obj)
 {
     // Note that NATIVE_CTOR does not imply that we are a standard constructor,
     // but the converse is true (at least until we start having self-hosted
     // constructors for standard classes). This lets us avoid a costly loop for
--- a/js/src/vm/GlobalObject.h
+++ b/js/src/vm/GlobalObject.h
@@ -802,16 +802,25 @@ GenericCreatePrototype(JSContext *cx, JS
     MOZ_ASSERT(key != JSProto_Object);
     JSProtoKey parentKey = ParentKeyForStandardClass(key);
     if (!GlobalObject::ensureConstructor(cx, cx->global(), parentKey))
         return nullptr;
     JSObject *parentProto = &cx->global()->getPrototype(parentKey).toObject();
     return cx->global()->createBlankPrototypeInheriting(cx, clasp, *parentProto);
 }
 
+inline JSProtoKey
+StandardProtoKeyOrNull(const JSObject *obj)
+{
+    JSProtoKey key = JSCLASS_CACHED_PROTO_KEY(obj->getClass());
+    if (key == JSProto_Error)
+        return GetExceptionProtoKey(obj->as<ErrorObject>().type());
+    return key;
+}
+
 } // namespace js
 
 template<>
 inline bool
 JSObject::is<js::GlobalObject>() const
 {
     return !!(getClass()->flags & JSCLASS_IS_GLOBAL);
 }