Bug 1394831 part 7 - Remove flags and allowDictionary arguments from addDataProperty. r=bhackett
authorJan de Mooij <jdemooij@mozilla.com>
Wed, 01 Nov 2017 11:39:22 +0100
changeset 440380 706c6d3891116441afca9d9a762a1dea20424883
parent 440379 88bfd12dc09931dcda7d143e06a7314fe3480176
child 440381 444453765199fc52a86a1d44832f893a02e7ff80
push id8114
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 16:33:21 +0000
treeherdermozilla-beta@73e0d89a540f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett
bugs1394831
milestone58.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 1394831 part 7 - Remove flags and allowDictionary arguments from addDataProperty. r=bhackett
js/src/vm/NativeObject.cpp
js/src/vm/NativeObject.h
js/src/vm/Shape-inl.h
js/src/vm/Shape.cpp
js/src/vm/UnboxedObject.cpp
--- a/js/src/vm/NativeObject.cpp
+++ b/js/src/vm/NativeObject.cpp
@@ -493,17 +493,17 @@ NativeObject::sparsifyDenseElement(JSCon
             return false;
         entry = &table->search<MaybeAdding::Adding>(id, keep);
     }
 
     // NOTE: We don't use addDataProperty because we don't want the
     // extensibility check if we're, for example, sparsifying frozen objects..
     if (!addDataPropertyInternal(cx, obj, id, slot,
                                  obj->getElementsHeader()->elementAttributes(),
-                                 0, entry, true, keep)) {
+                                 entry, keep)) {
         obj->setDenseElementUnchecked(index, value);
         return false;
     }
 
     MOZ_ASSERT(slot == obj->slotSpan() - 1);
     obj->initSlot(slot, value);
 
     return true;
@@ -1148,30 +1148,21 @@ NativeObject::freeSlot(JSContext* cx, ui
             cx->recoverFromOutOfMemory();
         }
     }
     setSlot(slot, UndefinedValue());
 }
 
 /* static */ Shape*
 NativeObject::addDataProperty(JSContext* cx, HandleNativeObject obj,
-                              jsid idArg, uint32_t slot, unsigned attrs)
-{
-    MOZ_ASSERT(!(attrs & (JSPROP_GETTER | JSPROP_SETTER)));
-    RootedId id(cx, idArg);
-    return addDataProperty(cx, obj, id, slot, attrs, 0);
-}
-
-/* static */ Shape*
-NativeObject::addDataProperty(JSContext* cx, HandleNativeObject obj,
                               HandlePropertyName name, uint32_t slot, unsigned attrs)
 {
     MOZ_ASSERT(!(attrs & (JSPROP_GETTER | JSPROP_SETTER)));
     RootedId id(cx, NameToId(name));
-    return addDataProperty(cx, obj, id, slot, attrs, 0);
+    return addDataProperty(cx, obj, id, slot, attrs);
 }
 
 template <AllowGC allowGC>
 bool
 js::NativeLookupOwnProperty(JSContext* cx,
                             typename MaybeRooted<NativeObject*, allowGC>::HandleType obj,
                             typename MaybeRooted<jsid, allowGC>::HandleType id,
                             typename MaybeRooted<PropertyResult, allowGC>::MutableHandleType propp)
@@ -1427,17 +1418,17 @@ AddOrChangeProperty(JSContext* cx, Handl
     }
 
     // If we know this is a new property we can call addProperty instead of
     // the slower putProperty.
     Shape* shape;
     if (AddOrChange == IsAddOrChange::Add) {
         if (Shape::isDataProperty(desc.attributes(), desc.getter(), desc.setter())) {
             shape = NativeObject::addDataProperty(cx, obj, id, SHAPE_INVALID_SLOT,
-                                                  desc.attributes(), 0);
+                                                  desc.attributes());
         } else {
             shape = NativeObject::addAccessorProperty(cx, obj, id, desc.getter(), desc.setter(),
                                                       desc.attributes(), 0);
         }
     } else {
         if (Shape::isDataProperty(desc.attributes(), desc.getter(), desc.setter())) {
             shape = NativeObject::putDataProperty(cx, obj, id, desc.attributes());
         } else {
--- a/js/src/vm/NativeObject.h
+++ b/js/src/vm/NativeObject.h
@@ -849,28 +849,26 @@ class NativeObject : public ShapedObject
   private:
     static MOZ_ALWAYS_INLINE Shape* getChildProperty(JSContext* cx, HandleNativeObject obj,
                                                      HandleShape parent,
                                                      MutableHandle<StackShape> child);
 
   public:
     /* Add a property whose id is not yet in this scope. */
     static MOZ_ALWAYS_INLINE Shape* addDataProperty(JSContext* cx, HandleNativeObject obj, HandleId id,
-                                                    uint32_t slot, unsigned attrs, unsigned flags,
-                                                    bool allowDictionary = true);
+                                                    uint32_t slot, unsigned attrs);
+
     static MOZ_ALWAYS_INLINE Shape* addAccessorProperty(JSContext* cx, HandleNativeObject obj, HandleId id,
                                                         JSGetterOp getter, JSSetterOp setter,
                                                         unsigned attrs, unsigned flags,
                                                         bool allowDictionary = true);
     static Shape* addEnumerableDataProperty(JSContext* cx, HandleNativeObject obj, HandleId id);
 
     /* Add a data property whose id is not yet in this scope. */
     static Shape* addDataProperty(JSContext* cx, HandleNativeObject obj,
-                                  jsid id_, uint32_t slot, unsigned attrs);
-    static Shape* addDataProperty(JSContext* cx, HandleNativeObject obj,
                                   HandlePropertyName name, uint32_t slot, unsigned attrs);
 
     /* Add or overwrite a property for id in this scope. */
     static Shape*
     putDataProperty(JSContext* cx, HandleNativeObject obj, HandleId id, unsigned attrs);
 
     static Shape*
     putAccessorProperty(JSContext* cx, HandleNativeObject obj, HandleId id,
@@ -892,18 +890,17 @@ class NativeObject : public ShapedObject
      * Internal helper that adds a shape not yet mapped by this object.
      *
      * Notes:
      * 1. getter and setter must be normalized based on flags (see jsscope.cpp).
      * 2. Checks for non-extensibility must be done by callers.
      */
     static Shape*
     addDataPropertyInternal(JSContext* cx, HandleNativeObject obj, HandleId id,
-                            uint32_t slot, unsigned attrs, unsigned flags,
-                            ShapeTable::Entry* entry, bool allowDictionary,
+                            uint32_t slot, unsigned attrs, ShapeTable::Entry* entry,
                             const AutoKeepShapeTables& keep);
 
     static Shape*
     addAccessorPropertyInternal(JSContext* cx, HandleNativeObject obj, HandleId id,
                                 JSGetterOp getter, JSSetterOp setter, unsigned attrs,
                                 unsigned flags, ShapeTable::Entry* entry, bool allowDictionary,
                                 const AutoKeepShapeTables& keep);
 
--- a/js/src/vm/Shape-inl.h
+++ b/js/src/vm/Shape-inl.h
@@ -387,32 +387,32 @@ Shape::searchNoHashify(Shape* start, jsi
         return entry.shape();
     }
 
     return start->searchLinear(id);
 }
 
 /* static */ MOZ_ALWAYS_INLINE Shape*
 NativeObject::addDataProperty(JSContext* cx, HandleNativeObject obj, HandleId id,
-                              uint32_t slot, unsigned attrs, unsigned flags, bool allowDictionary)
+                              uint32_t slot, unsigned attrs)
 {
     MOZ_ASSERT(!JSID_IS_VOID(id));
     MOZ_ASSERT(obj->uninlinedNonProxyIsExtensible());
     MOZ_ASSERT(!obj->containsPure(id));
 
     AutoKeepShapeTables keep(cx);
     ShapeTable::Entry* entry = nullptr;
     if (obj->inDictionaryMode()) {
         ShapeTable* table = obj->lastProperty()->ensureTableForDictionary(cx, keep);
         if (!table)
             return nullptr;
         entry = &table->search<MaybeAdding::Adding>(id, keep);
     }
 
-    return addDataPropertyInternal(cx, obj, id, slot, attrs, flags, entry, allowDictionary, keep);
+    return addDataPropertyInternal(cx, obj, id, slot, attrs, entry, keep);
 }
 
 /* static */ MOZ_ALWAYS_INLINE Shape*
 NativeObject::addAccessorProperty(JSContext* cx, HandleNativeObject obj, HandleId id,
                                   GetterOp getter, SetterOp setter, unsigned attrs,
                                   unsigned flags, bool allowDictionary)
 {
     MOZ_ASSERT(!JSID_IS_VOID(id));
--- a/js/src/vm/Shape.cpp
+++ b/js/src/vm/Shape.cpp
@@ -542,37 +542,31 @@ NativeObject::addAccessorPropertyInterna
 
     return shape;
 }
 
 /* static */ Shape*
 NativeObject::addDataPropertyInternal(JSContext* cx,
                                       HandleNativeObject obj, HandleId id,
                                       uint32_t slot, unsigned attrs,
-                                      unsigned flags, ShapeTable::Entry* entry,
-                                      bool allowDictionary, const AutoKeepShapeTables& keep)
+                                      ShapeTable::Entry* entry, const AutoKeepShapeTables& keep)
 {
-    MOZ_ASSERT_IF(!allowDictionary, !obj->inDictionaryMode());
-
     AutoCheckShapeConsistency check(obj);
 
     /*
      * The code below deals with either converting obj to dictionary mode or
      * growing an object that's already in dictionary mode.
      */
     ShapeTable* table = nullptr;
     if (!obj->inDictionaryMode()) {
         bool stableSlot =
             (slot == SHAPE_INVALID_SLOT) ||
             obj->lastProperty()->hasMissingSlot() ||
             (slot == obj->lastProperty()->maybeSlot() + 1);
-        MOZ_ASSERT_IF(!allowDictionary, stableSlot);
-        if (allowDictionary &&
-            (!stableSlot || ShouldConvertToDictionary(obj)))
-        {
+        if (!stableSlot || ShouldConvertToDictionary(obj)) {
             if (!toDictionaryMode(cx, obj))
                 return nullptr;
             table = obj->lastProperty()->maybeTable(keep);
             entry = &table->search<MaybeAdding::Adding>(id, keep);
         }
     } else {
         table = obj->lastProperty()->ensureTableForDictionary(cx, keep);
         if (!table)
@@ -590,17 +584,17 @@ NativeObject::addDataPropertyInternal(JS
     /* Find or create a property tree node labeled by our arguments. */
     RootedShape shape(cx);
     {
         RootedShape last(cx, obj->lastProperty());
         Rooted<UnownedBaseShape*> nbase(cx, GetBaseShapeForNewShape(cx, last, id));
         if (!nbase)
             return nullptr;
 
-        Rooted<StackShape> child(cx, StackShape(nbase, id, slot, attrs, flags));
+        Rooted<StackShape> child(cx, StackShape(nbase, id, slot, attrs, 0));
         shape = getChildProperty(cx, obj, last, &child);
         if (!shape)
             return nullptr;
     }
 
     MOZ_ASSERT(shape == obj->lastProperty());
 
     if (table) {
@@ -812,18 +806,17 @@ NativeObject::putDataProperty(JSContext*
 
     if (!shape) {
         /*
          * You can't add properties to a non-extensible object, but you can change
          * attributes of properties in such objects.
          */
         MOZ_ASSERT(obj->nonProxyIsExtensible());
 
-        return addDataPropertyInternal(cx, obj, id, SHAPE_INVALID_SLOT, attrs, 0, entry, true,
-                                       keep);
+        return addDataPropertyInternal(cx, obj, id, SHAPE_INVALID_SLOT, attrs, entry, keep);
     }
 
     /* Property exists: search must have returned a valid entry. */
     MOZ_ASSERT_IF(entry, !entry->isRemoved());
 
     AssertCanChangeAttrs(shape, attrs);
 
     /*
--- a/js/src/vm/UnboxedObject.cpp
+++ b/js/src/vm/UnboxedObject.cpp
@@ -389,19 +389,21 @@ PropagatePropertyTypes(JSContext* cx, js
 static PlainObject*
 MakeReplacementTemplateObject(JSContext* cx, HandleObjectGroup group, const UnboxedLayout &layout)
 {
     Rooted<PlainObject*> obj(cx, NewObjectWithGroup<PlainObject>(cx, group, layout.getAllocKind(),
                                                                  TenuredObject));
     if (!obj)
         return nullptr;
 
+    RootedId id(cx);
     for (size_t i = 0; i < layout.properties().length(); i++) {
         const UnboxedLayout::Property& property = layout.properties()[i];
-        if (!NativeObject::addDataProperty(cx, obj, NameToId(property.name), i, JSPROP_ENUMERATE))
+        id = NameToId(property.name);
+        if (!NativeObject::addDataProperty(cx, obj, id, i, JSPROP_ENUMERATE))
             return nullptr;
         MOZ_ASSERT(obj->slotSpan() == i + 1);
         MOZ_ASSERT(!obj->inDictionaryMode());
     }
 
     return obj;
 }