fix crash when converting symbol or BigInt to dynamic

Summary:
Throws a JS error instead of crashing Hermes with an invariant when trying to convert a JS symbol or BigInt to a folly::dynamic value.

Changelog:
[General][Fixed] - Fixed crash when converting JS symbol to folly::dynamic

Reviewed By: javache

Differential Revision: D40444164

fbshipit-source-id: 37df8059b2eb425563f30cf1e9c0436e8d665b34
This commit is contained in:
Jan Kassens 2022-10-24 20:16:57 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 1bb5cca72d
Коммит 428feb2f76
1 изменённых файлов: 7 добавлений и 2 удалений

Просмотреть файл

@ -129,8 +129,7 @@ void dynamicFromValueShallow(
output = value.getNumber();
} else if (value.isString()) {
output = value.getString(runtime).utf8(runtime);
} else {
CHECK(value.isObject());
} else if (value.isObject()) {
Object obj = value.getObject(runtime);
if (obj.isArray(runtime)) {
output = folly::dynamic::array();
@ -140,6 +139,12 @@ void dynamicFromValueShallow(
output = folly::dynamic::object();
}
stack.emplace_back(&output, std::move(obj));
} else if (value.isBigInt()) {
throw JSError(runtime, "JS BigInts are not convertible to dynamic");
} else if (value.isSymbol()) {
throw JSError(runtime, "JS Symbols are not convertible to dynamic");
} else {
throw JSError(runtime, "Value is not convertible to dynamic");
}
}