Commit 5c84d76a authored by Jan de Mooij's avatar Jan de Mooij
Browse files

Bug 1733075 part 1 - Add HasEnumerable ObjectFlag. r=iain

This gives us the ability to check whether an object has only non-enumerable
properties in constant time. Prototype objects typically don't have enumerable
properties.

Differential Revision: https://phabricator.services.mozilla.com/D127054
parent 7897dc69
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2947,6 +2947,9 @@ void JSObject::dump(js::GenericPrinter& out) const {
    if (nobj->isIndexed()) {
      out.put(" indexed");
    }
    if (nobj->hasEnumerableProperty()) {
      out.put(" has_enumerable");
    }
    if (nobj->is<PlainObject>() &&
        nobj->as<PlainObject>().hasNonWritableOrAccessorPropExclProto()) {
      out.put(" has_non_writable_or_accessor_prop_excl_proto");
+4 −0
Original line number Diff line number Diff line
@@ -823,6 +823,10 @@ class NativeObject : public JSObject {
    return hasFlag(ObjectFlag::HasInterestingSymbol);
  }

  bool hasEnumerableProperty() const {
    return hasFlag(ObjectFlag::HasEnumerable);
  }

  static bool setHadGetterSetterChange(JSContext* cx, HandleNativeObject obj) {
    return setFlag(cx, obj, ObjectFlag::HadGetterSetterChange);
  }
+4 −0
Original line number Diff line number Diff line
@@ -31,6 +31,10 @@ GetObjectFlagsForNewProperty(const JSClass* clasp, ObjectFlags flags, jsid id,
    flags.setFlag(ObjectFlag::HasNonWritableOrAccessorPropExclProto);
  }

  if (propFlags.enumerable()) {
    flags.setFlag(ObjectFlag::HasEnumerable);
  }

  return flags;
}

+7 −1
Original line number Diff line number Diff line
@@ -22,7 +22,13 @@ enum class ObjectFlag : uint16_t {
  NotExtensible = 1 << 1,
  Indexed = 1 << 2,
  HasInterestingSymbol = 1 << 3,
  // (1 << 4) is unused.

  // If set, the shape's property map may contain an enumerable property. This
  // only accounts for (own) shape properties: if the flag is not set, the
  // object may still have (enumerable) dense elements, typed array elements, or
  // a JSClass enumeration hook.
  HasEnumerable = 1 << 4,

  FrozenElements = 1 << 5,  // See ObjectElements::FROZEN comment.

  // If set, the shape teleporting optimization can no longer be used for