Commit 2f22cd60 authored by Jan de Mooij's avatar Jan de Mooij
Browse files

Bug 1827258 part 2 - Optimize IsConcatSpreadable. r=jonco

Use the interesting-symbol mechanism for `@@isConcatSpreadable` so that we can
add a fast path for the common case where the symbol isn't defined.

Differential Revision: https://phabricator.services.mozilla.com/D175776
parent 9845cb1d
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -4550,21 +4550,29 @@ static bool IsConcatSpreadable(JSContext* cx, HandleValue v, bool* spreadable) {
  }

  // Step 2.
  JS::Symbol* sym = cx->wellKnownSymbols().isConcatSpreadable;
  JSObject* holder;
  if (MOZ_UNLIKELY(
          MaybeHasInterestingSymbolProperty(cx, &v.toObject(), sym, &holder))) {
    RootedValue res(cx);
  RootedObject obj(cx, &v.toObject());
  RootedId id(cx,
              PropertyKey::Symbol(cx->wellKnownSymbols().isConcatSpreadable));
  if (!GetProperty(cx, obj, v, id, &res)) {
    RootedObject obj(cx, holder);
    Rooted<PropertyKey> key(cx, PropertyKey::Symbol(sym));
    if (!GetProperty(cx, obj, v, key, &res)) {
      return false;
    }

    // Step 3.
    if (!res.isUndefined()) {
      *spreadable = ToBoolean(res);
      return true;
    }
  }

  // Step 4.
  if (MOZ_LIKELY(v.toObject().is<ArrayObject>())) {
    *spreadable = true;
    return true;
  }
  RootedObject obj(cx, &v.toObject());
  bool isArray;
  if (!JS::IsArray(cx, obj, &isArray)) {
    return false;
+3 −1
Original line number Diff line number Diff line
@@ -79,7 +79,9 @@ class Symbol
  // symbol properties are added, so we can optimize lookups on objects that
  // don't have the BaseShape flag.
  bool isInterestingSymbol() const {
    return code_ == SymbolCode::toStringTag || code_ == SymbolCode::toPrimitive;
    return code_ == SymbolCode::toStringTag ||
           code_ == SymbolCode::toPrimitive ||
           code_ == SymbolCode::isConcatSpreadable;
  }

  // Symbol created for the #PrivateName syntax.