Don't assume JS integers are dynamic Ints
Reviewed By: kathryngray Differential Revision: D5643016 fbshipit-source-id: 2e4e1bce013e16c286745dc2a9aa5ff251f7afdd
This commit is contained in:
parent
2292023a1b
commit
f6de2e4a9b
|
@ -18,11 +18,11 @@ namespace react {
|
|||
|
||||
std::function<void(folly::dynamic)> makeCallback(
|
||||
std::weak_ptr<Instance> instance, const folly::dynamic& callbackId) {
|
||||
if (!callbackId.isInt()) {
|
||||
if (!callbackId.isNumber()) {
|
||||
throw std::invalid_argument("Expected callback(s) as final argument");
|
||||
}
|
||||
|
||||
auto id = callbackId.getInt();
|
||||
auto id = callbackId.asInt();
|
||||
return [winstance = std::move(instance), id](folly::dynamic args) {
|
||||
if (auto instance = winstance.lock()) {
|
||||
instance->callJSCallback(id, std::move(args));
|
||||
|
|
|
@ -44,12 +44,11 @@ std::vector<MethodCall> parseMethodCalls(folly::dynamic&& jsonData) throw(std::i
|
|||
}
|
||||
|
||||
if (jsonData.size() > REQUEST_CALLID) {
|
||||
if (!jsonData[REQUEST_CALLID].isInt()) {
|
||||
if (!jsonData[REQUEST_CALLID].isNumber()) {
|
||||
throw std::invalid_argument(
|
||||
folly::to<std::string>("Did not get valid calls back from JS: %s", folly::toJson(jsonData)));
|
||||
} else {
|
||||
callId = jsonData[REQUEST_CALLID].getInt();
|
||||
}
|
||||
callId = jsonData[REQUEST_CALLID].asInt();
|
||||
}
|
||||
|
||||
std::vector<MethodCall> methodCalls;
|
||||
|
@ -60,8 +59,8 @@ std::vector<MethodCall> parseMethodCalls(folly::dynamic&& jsonData) throw(std::i
|
|||
}
|
||||
|
||||
methodCalls.emplace_back(
|
||||
moduleIds[i].getInt(),
|
||||
methodIds[i].getInt(),
|
||||
moduleIds[i].asInt(),
|
||||
methodIds[i].asInt(),
|
||||
std::move(params[i]),
|
||||
callId);
|
||||
|
||||
|
|
|
@ -51,8 +51,8 @@ TEST(Value, ToJSONString) {
|
|||
EXPECT_TRUE(dyn.isObject());
|
||||
auto val = dyn.at("a");
|
||||
ASSERT_NE(nullptr, val);
|
||||
ASSERT_TRUE(val.isInt());
|
||||
EXPECT_EQ(4, val.getInt());
|
||||
ASSERT_TRUE(val.isNumber());
|
||||
EXPECT_EQ(4, val.asInt());
|
||||
EXPECT_EQ(4.0f, val.asDouble());
|
||||
|
||||
JSC_JSGlobalContextRelease(ctx);
|
||||
|
|
Loading…
Reference in New Issue