Bug 1066652 - Clean up APIs for adding property types, r=jandem.
authorBrian Hackett <bhackett1024@gmail.com>
Mon, 22 Sep 2014 17:29:15 -0700
changeset 206609 245c55cc9ccfd8a4749ade4308a73cd6309f7a6c
parent 206608 5d90266605a1bc4842e79d662f1a592bfb0b9a08
child 206610 160e9c8a1fd74859e8db654c94bef009afca3565
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjandem
bugs1066652
milestone35.0a1
Bug 1066652 - Clean up APIs for adding property types, r=jandem.
js/src/jsinfer.cpp
js/src/jsinfer.h
js/src/jsinferinlines.h
--- a/js/src/jsinfer.cpp
+++ b/js/src/jsinfer.cpp
@@ -2594,18 +2594,17 @@ TypeCompartment::setTypeToHomogenousArra
         /* Make a new type to use for future arrays with the same elements. */
         RootedObject objProto(cx, obj->getProto());
         Rooted<TaggedProto> taggedProto(cx, TaggedProto(objProto));
         TypeObject *objType = newTypeObject(cx, &ArrayObject::class_, taggedProto);
         if (!objType)
             return;
         obj->setType(objType);
 
-        if (!objType->unknownProperties())
-            objType->addPropertyType(cx, JSID_VOID, elementType);
+        AddTypePropertyId(cx, objType, JSID_VOID, elementType);
 
         key.proto = objProto;
         (void) p.add(cx, *arrayTypeTable, key, objType);
     }
 }
 
 void
 TypeCompartment::fixArrayType(ExclusiveContext *cx, JSObject *obj)
@@ -2722,17 +2721,17 @@ UpdateObjectTableEntryTypes(ExclusiveCon
             /* The property types already reflect 'int32'. */
         } else {
             if (ntype.isPrimitive(JSVAL_TYPE_DOUBLE) &&
                 type.isPrimitive(JSVAL_TYPE_INT32))
             {
                 /* Include 'double' in the property types to avoid the update below later. */
                 entry.types[i] = Type::DoubleType();
             }
-            entry.object->addPropertyType(cx, IdToTypeId(properties[i].id), ntype);
+            AddTypePropertyId(cx, entry.object, IdToTypeId(properties[i].id), ntype);
         }
     }
 }
 
 void
 TypeCompartment::fixObjectType(ExclusiveContext *cx, JSObject *obj)
 {
     AutoEnterAnalysis enter(cx);
@@ -2799,18 +2798,17 @@ TypeCompartment::fixObjectType(Exclusive
 
     ScopedJSFreePtr<Type> types(objType->zone()->pod_calloc<Type>(properties.length()));
     if (!types)
         return;
 
     for (size_t i = 0; i < properties.length(); i++) {
         ids[i] = properties[i].id;
         types[i] = GetValueTypeForTable(obj->getSlot(i));
-        if (!objType->unknownProperties())
-            objType->addPropertyType(cx, IdToTypeId(ids[i]), types[i]);
+        AddTypePropertyId(cx, objType, IdToTypeId(ids[i]), types[i]);
     }
 
     ObjectTableKey key;
     key.properties = ids;
     key.nproperties = properties.length();
     key.nfixed = obj->numFixedSlots();
     JS_ASSERT(ObjectTableKey::match(key, lookup));
 
@@ -3045,21 +3043,24 @@ TypeObject::matchDefiniteProperties(Hand
             if (!found)
                 return false;
         }
     }
 
     return true;
 }
 
-static inline void
-InlineAddTypeProperty(ExclusiveContext *cx, TypeObject *obj, jsid id, Type type)
+void
+types::AddTypePropertyId(ExclusiveContext *cx, TypeObject *obj, jsid id, Type type)
 {
     JS_ASSERT(id == IdToTypeId(id));
 
+    if (obj->unknownProperties())
+        return;
+
     AutoEnterAnalysis enter(cx);
 
     HeapTypeSet *types = obj->getProperty(cx, id);
     if (!types)
         return;
 
     // Clear any constant flag if it exists.
     if (!types->empty() && !types->nonConstantProperty()) {
@@ -3078,31 +3079,24 @@ InlineAddTypeProperty(ExclusiveContext *
     // Propagate new types from partially initialized types to fully
     // initialized types for the acquired properties analysis. Note that we
     // don't need to do this for other property changes, as these will also be
     // reflected via shape changes on the object that will prevent the object
     // from acquiring the fully initialized type.
     if (obj->newScript() && obj->newScript()->initializedType()) {
         if (type.isObjectUnchecked() && types->unknownObject())
             type = Type::AnyObjectType();
-        if (!obj->newScript()->initializedType()->unknownProperties())
-            obj->newScript()->initializedType()->addPropertyType(cx, id, type);
+        AddTypePropertyId(cx, obj->newScript()->initializedType(), id, type);
     }
 }
 
 void
-TypeObject::addPropertyType(ExclusiveContext *cx, jsid id, Type type)
+types::AddTypePropertyId(ExclusiveContext *cx, TypeObject *obj, jsid id, const Value &value)
 {
-    InlineAddTypeProperty(cx, this, id, type);
-}
-
-void
-TypeObject::addPropertyType(ExclusiveContext *cx, jsid id, const Value &value)
-{
-    InlineAddTypeProperty(cx, this, id, GetValueType(value));
+    AddTypePropertyId(cx, obj, id, GetValueType(value));
 }
 
 void
 TypeObject::markPropertyNonData(ExclusiveContext *cx, jsid id)
 {
     AutoEnterAnalysis enter(cx);
 
     id = IdToTypeId(id);
--- a/js/src/jsinfer.h
+++ b/js/src/jsinfer.h
@@ -1189,18 +1189,16 @@ struct TypeObject : public gc::TenuredCe
     inline Property *getProperty(unsigned i);
 
     /* Helpers */
 
     void updateNewPropertyTypes(ExclusiveContext *cx, jsid id, HeapTypeSet *types);
     bool addDefiniteProperties(ExclusiveContext *cx, Shape *shape);
     bool matchDefiniteProperties(HandleObject obj);
     void addPrototype(JSContext *cx, TypeObject *proto);
-    void addPropertyType(ExclusiveContext *cx, jsid id, Type type);
-    void addPropertyType(ExclusiveContext *cx, jsid id, const Value &value);
     void markPropertyNonData(ExclusiveContext *cx, jsid id);
     void markPropertyNonWritable(ExclusiveContext *cx, jsid id);
     void markStateChange(ExclusiveContext *cx);
     void setFlags(ExclusiveContext *cx, TypeObjectFlags flags);
     void markUnknown(ExclusiveContext *cx);
     void maybeClearNewScriptOnOOM();
     void clearNewScript(ExclusiveContext *cx);
     bool isPropertyNonData(jsid id);
--- a/js/src/jsinferinlines.h
+++ b/js/src/jsinferinlines.h
@@ -456,45 +456,34 @@ HasTypePropertyId(JSObject *obj, jsid id
 }
 
 inline bool
 HasTypePropertyId(JSObject *obj, jsid id, const Value &value)
 {
     return HasTypePropertyId(obj, id, GetValueType(value));
 }
 
+void AddTypePropertyId(ExclusiveContext *cx, TypeObject *obj, jsid id, Type type);
+void AddTypePropertyId(ExclusiveContext *cx, TypeObject *obj, jsid id, const Value &value);
+
 /* Add a possible type for a property of obj. */
 inline void
 AddTypePropertyId(ExclusiveContext *cx, JSObject *obj, jsid id, Type type)
 {
     id = IdToTypeId(id);
     if (TrackPropertyTypes(cx, obj, id))
-        obj->type()->addPropertyType(cx, id, type);
+        AddTypePropertyId(cx, obj->type(), id, type);
 }
 
 inline void
 AddTypePropertyId(ExclusiveContext *cx, JSObject *obj, jsid id, const Value &value)
 {
     id = IdToTypeId(id);
     if (TrackPropertyTypes(cx, obj, id))
-        obj->type()->addPropertyType(cx, id, value);
-}
-
-inline void
-AddTypePropertyId(ExclusiveContext *cx, TypeObject *obj, jsid id, Type type)
-{
-    if (!obj->unknownProperties())
-        obj->addPropertyType(cx, id, type);
-}
-
-inline void
-AddTypePropertyId(ExclusiveContext *cx, TypeObject *obj, jsid id, const Value &value)
-{
-    if (!obj->unknownProperties())
-        obj->addPropertyType(cx, id, value);
+        AddTypePropertyId(cx, obj->type(), id, value);
 }
 
 /* Set one or more dynamic flags on a type object. */
 inline void
 MarkTypeObjectFlags(ExclusiveContext *cx, JSObject *obj, TypeObjectFlags flags)
 {
     if (!obj->hasLazyType() && !obj->type()->hasAllFlags(flags))
         obj->type()->setFlags(cx, flags);