Skip to content

Commit

Permalink
fix crash when converting symbol or BigInt to dynamic
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kassens authored and facebook-github-bot committed Oct 25, 2022
1 parent 1bb5cca commit 428feb2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ReactCommon/jsi/jsi/JSIDynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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");
}
}

Expand Down

0 comments on commit 428feb2

Please sign in to comment.