Bug 1388354 - Optimize ToPropertyKey a bit. r=anba

This commit is contained in:
Jan de Mooij 2017-08-10 11:11:42 +02:00
parent 11d57944d7
commit 9f891645fa
2 changed files with 21 additions and 7 deletions

View File

@ -3176,6 +3176,20 @@ js::ToPrimitiveSlow(JSContext* cx, JSType preferredType, MutableHandleValue vp)
return OrdinaryToPrimitive(cx, obj, preferredType, vp);
}
/* ES6 draft rev 28 (2014 Oct 14) 7.1.14 */
bool
js::ToPropertyKeySlow(JSContext* cx, HandleValue argument, MutableHandleId result)
{
MOZ_ASSERT(argument.isObject());
// Steps 1-2.
RootedValue key(cx, argument);
if (!ToPrimitiveSlow(cx, JSTYPE_STRING, &key))
return false;
// Steps 3-4.
return ValueToId<CanGC>(cx, key, result);
}
/* * */

View File

@ -583,17 +583,17 @@ HasNoToPrimitiveMethodPure(JSObject* obj, JSContext* cx)
return !prop;
}
extern bool
ToPropertyKeySlow(JSContext* cx, HandleValue argument, MutableHandleId result);
/* ES6 draft rev 28 (2014 Oct 14) 7.1.14 */
inline bool
MOZ_ALWAYS_INLINE bool
ToPropertyKey(JSContext* cx, HandleValue argument, MutableHandleId result)
{
// Steps 1-2.
RootedValue key(cx, argument);
if (!ToPrimitive(cx, JSTYPE_STRING, &key))
return false;
if (MOZ_LIKELY(argument.isPrimitive()))
return ValueToId<CanGC>(cx, argument, result);
// Steps 3-4.
return ValueToId<CanGC>(cx, key, result);
return ToPropertyKeySlow(cx, argument, result);
}
/*