diff --git a/Libraries/BatchedBridge/BatchedBridge.js b/Libraries/BatchedBridge/BatchedBridge.js index a75c59303..77dc9e6a5 100644 --- a/Libraries/BatchedBridge/BatchedBridge.js +++ b/Libraries/BatchedBridge/BatchedBridge.js @@ -12,8 +12,11 @@ const MessageQueue = require('MessageQueue'); +const serializeNativeParams = typeof global.__fbBatchedBridgeSerializeNativeParams !== 'undefined'; + const BatchedBridge = new MessageQueue( - () => global.__fbBatchedBridgeConfig + () => global.__fbBatchedBridgeConfig, + serializeNativeParams ); // TODO: Move these around to solve the cycle in a cleaner way. diff --git a/Libraries/Utilities/MessageQueue.js b/Libraries/Utilities/MessageQueue.js index cc24f5752..7f8c7067f 100644 --- a/Libraries/Utilities/MessageQueue.js +++ b/Libraries/Utilities/MessageQueue.js @@ -49,7 +49,7 @@ type Config = { }; class MessageQueue { - constructor(configProvider: () => Config) { + constructor(configProvider: () => Config, serializeNativeParams: boolean) { this._callableModules = {}; this._queue = [[], [], [], 0]; this._callbacks = []; @@ -57,6 +57,7 @@ class MessageQueue { this._callID = 0; this._lastFlush = 0; this._eventLoopStartTime = new Date().getTime(); + this._serializeNativeParams = serializeNativeParams; if (__DEV__) { this._debugInfo = {}; @@ -150,6 +151,7 @@ class MessageQueue { onSucc && params.push(this._callbackID); this._callbacks[this._callbackID++] = onSucc; } + var preparedParams = this._serializeNativeParams ? JSON.stringify(params) : params; if (__DEV__) { global.nativeTraceBeginAsyncFlow && @@ -159,7 +161,7 @@ class MessageQueue { this._queue[MODULE_IDS].push(module); this._queue[METHOD_IDS].push(method); - this._queue[PARAMS].push(params); + this._queue[PARAMS].push(preparedParams); const now = new Date().getTime(); if (global.nativeFlushQueueImmediate && diff --git a/ReactAndroid/src/main/jni/xreact/jni/ProxyExecutor.cpp b/ReactAndroid/src/main/jni/xreact/jni/ProxyExecutor.cpp index 784618726..011a12f56 100644 --- a/ReactAndroid/src/main/jni/xreact/jni/ProxyExecutor.cpp +++ b/ReactAndroid/src/main/jni/xreact/jni/ProxyExecutor.cpp @@ -58,6 +58,9 @@ ProxyExecutor::ProxyExecutor(jni::global_ref&& executorInstance, setGlobalVariable( "__fbBatchedBridgeConfig", folly::make_unique(detail::toStdString(folly::toJson(config)))); + setGlobalVariable( + "__fbBatchedBridgeSerializeNativeParams", + folly::make_unique("1")); } ProxyExecutor::~ProxyExecutor() { diff --git a/ReactCommon/cxxreact/JSCExecutor.cpp b/ReactCommon/cxxreact/JSCExecutor.cpp index b3a8a2db6..5bd5ba63e 100644 --- a/ReactCommon/cxxreact/JSCExecutor.cpp +++ b/ReactCommon/cxxreact/JSCExecutor.cpp @@ -119,12 +119,17 @@ JSCExecutor::JSCExecutor(std::shared_ptr delegate, } folly::dynamic config = - folly::dynamic::object("remoteModuleConfig", std::move(nativeModuleConfig)); + folly::dynamic::object + ("remoteModuleConfig", std::move(nativeModuleConfig)); + SystraceSection t("setGlobalVariable"); setGlobalVariable( "__fbBatchedBridgeConfig", folly::make_unique(detail::toStdString(folly::toJson(config)))); + setGlobalVariable( + "__fbBatchedBridgeSerializeNativeParams", + folly::make_unique("")); } JSCExecutor::JSCExecutor( diff --git a/ReactCommon/cxxreact/MethodCall.cpp b/ReactCommon/cxxreact/MethodCall.cpp index efb142c6c..d9c5e7543 100644 --- a/ReactCommon/cxxreact/MethodCall.cpp +++ b/ReactCommon/cxxreact/MethodCall.cpp @@ -51,16 +51,20 @@ std::vector parseMethodCalls(const std::string& json) throw(std::inv std::vector methodCalls; for (size_t i = 0; i < moduleIds.size(); i++) { - auto paramsValue = params[i]; + if (!params[i].isString()) { + throw std::invalid_argument( + folly::to("Call argument isn't a string")); + } + auto paramsValue = folly::parseJson(params[i].asString()); if (!paramsValue.isArray()) { throw std::invalid_argument( - folly::to("Call argument isn't an array")); + folly::to("Parsed params isn't an array")); } methodCalls.emplace_back( moduleIds[i].getInt(), methodIds[i].getInt(), - std::move(params[i]), + std::move(paramsValue), callId); // only incremement callid if contains valid callid as callid is optional