Bug 1651732 - Part 8: Split ValueToId callers in js::Stringify. r=jandem

Only call `ValueToId` for primitive values in preparation for the next patch
and instead call `ToAtom` for objects.

Differential Revision: https://phabricator.services.mozilla.com/D83059
This commit is contained in:
André Bargull 2020-07-11 12:43:03 +00:00
parent 60f966c979
commit 616df230cc

View File

@ -770,7 +770,12 @@ bool js::Stringify(JSContext* cx, MutableHandleValue vp, JSObject* replacer_,
}
/* Step 4b(iii)(5)(c-g). */
if (!item.isNumber() && !item.isString()) {
RootedId id(cx);
if (item.isNumber() || item.isString()) {
if (!ValueToId<CanGC>(cx, item, &id)) {
return false;
}
} else {
ESClass cls;
if (!GetClassOfValue(cx, item, &cls)) {
return false;
@ -779,11 +784,13 @@ bool js::Stringify(JSContext* cx, MutableHandleValue vp, JSObject* replacer_,
if (cls != ESClass::String && cls != ESClass::Number) {
continue;
}
JSAtom* atom = ToAtom<CanGC>(cx, item);
if (!atom) {
return false;
}
RootedId id(cx);
if (!ValueToId<CanGC>(cx, item, &id)) {
return false;
id.set(AtomToId(atom));
}
/* Step 4b(iii)(5)(g). */