From f6de2e4a9b3e3026ff05553f295d81e0d1b41a55 Mon Sep 17 00:00:00 2001 From: Marc Horowitz Date: Fri, 18 Aug 2017 14:43:28 -0700 Subject: [PATCH] Don't assume JS integers are dynamic Ints Reviewed By: kathryngray Differential Revision: D5643016 fbshipit-source-id: 2e4e1bce013e16c286745dc2a9aa5ff251f7afdd --- ReactCommon/cxxreact/CxxNativeModule.cpp | 4 ++-- ReactCommon/cxxreact/MethodCall.cpp | 9 ++++----- ReactCommon/cxxreact/tests/value.cpp | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ReactCommon/cxxreact/CxxNativeModule.cpp b/ReactCommon/cxxreact/CxxNativeModule.cpp index bd4fe385c..f050ae1d2 100644 --- a/ReactCommon/cxxreact/CxxNativeModule.cpp +++ b/ReactCommon/cxxreact/CxxNativeModule.cpp @@ -18,11 +18,11 @@ namespace react { std::function makeCallback( std::weak_ptr 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)); diff --git a/ReactCommon/cxxreact/MethodCall.cpp b/ReactCommon/cxxreact/MethodCall.cpp index 17d64c769..19ed01388 100644 --- a/ReactCommon/cxxreact/MethodCall.cpp +++ b/ReactCommon/cxxreact/MethodCall.cpp @@ -44,12 +44,11 @@ std::vector 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("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 methodCalls; @@ -60,8 +59,8 @@ std::vector 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); diff --git a/ReactCommon/cxxreact/tests/value.cpp b/ReactCommon/cxxreact/tests/value.cpp index 8f445b0e1..4ce30f94b 100644 --- a/ReactCommon/cxxreact/tests/value.cpp +++ b/ReactCommon/cxxreact/tests/value.cpp @@ -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);