From 428feb2f76c55d6ae5914b019095cd835aa514b0 Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Mon, 24 Oct 2022 20:16:57 -0700 Subject: [PATCH] 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 --- ReactCommon/jsi/jsi/JSIDynamic.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ReactCommon/jsi/jsi/JSIDynamic.cpp b/ReactCommon/jsi/jsi/JSIDynamic.cpp index 4464cc3b62f..02f112c0e0c 100644 --- a/ReactCommon/jsi/jsi/JSIDynamic.cpp +++ b/ReactCommon/jsi/jsi/JSIDynamic.cpp @@ -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"); } }