From 25d19e38305157a5ed6f5a60b7d6ef4b93c0ae84 Mon Sep 17 00:00:00 2001 From: Joana Lopes Date: Thu, 29 Jun 2017 04:15:02 -0700 Subject: [PATCH] Translating NativeArray into NativeMap on getConstants Reviewed By: javache Differential Revision: D5321741 fbshipit-source-id: 2465c69a5bd1d4f3cf20ba73e163372b12616312 --- .../facebook/react/bridge/JSCJavaScriptExecutor.java | 11 ++++------- .../com/facebook/react/bridge/JavaModuleWrapper.java | 8 ++------ .../src/main/jni/react/jni/JavaModuleWrapper.cpp | 10 ++++------ ReactAndroid/src/main/jni/react/jni/OnLoad.cpp | 4 ++-- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/JSCJavaScriptExecutor.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/JSCJavaScriptExecutor.java index 31b2f3548..6864c78c7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/JSCJavaScriptExecutor.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/JSCJavaScriptExecutor.java @@ -15,13 +15,10 @@ import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip public class JSCJavaScriptExecutor extends JavaScriptExecutor { public static class Factory implements JavaScriptExecutor.Factory { - private ReadableNativeArray mJSCConfig; + private ReadableNativeMap mJSCConfig; public Factory(WritableNativeMap jscConfig) { - // TODO (t10707444): use NativeMap, which requires moving NativeMap out of OnLoad. - WritableNativeArray array = new WritableNativeArray(); - array.pushMap(jscConfig); - mJSCConfig = array; + mJSCConfig = jscConfig; } @Override @@ -34,9 +31,9 @@ public class JSCJavaScriptExecutor extends JavaScriptExecutor { ReactBridge.staticInit(); } - public JSCJavaScriptExecutor(ReadableNativeArray jscConfig) { + public JSCJavaScriptExecutor(ReadableNativeMap jscConfig) { super(initHybrid(jscConfig)); } - private native static HybridData initHybrid(ReadableNativeArray jscConfig); + private native static HybridData initHybrid(ReadableNativeMap jscConfig); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/JavaModuleWrapper.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/JavaModuleWrapper.java index 33c97719b..4e46ca487 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/JavaModuleWrapper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/JavaModuleWrapper.java @@ -122,10 +122,8 @@ public class JavaModuleWrapper { return mDescs; } - // TODO mhorowitz: make this return NativeMap, which requires moving - // NativeMap out of OnLoad. @DoNotStrip - public @Nullable NativeArray getConstants() { + public @Nullable NativeMap getConstants() { if (!mModuleHolder.getHasConstants()) { return null; } @@ -145,9 +143,7 @@ public class JavaModuleWrapper { Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "create WritableNativeMap"); ReactMarker.logMarker(CONVERT_CONSTANTS_START, moduleName); try { - WritableNativeArray array = new WritableNativeArray(); - array.pushMap(Arguments.makeNativeMap(map)); - return array; + return Arguments.makeNativeMap(map); } finally { ReactMarker.logMarker(CONVERT_CONSTANTS_END); Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); diff --git a/ReactAndroid/src/main/jni/react/jni/JavaModuleWrapper.cpp b/ReactAndroid/src/main/jni/react/jni/JavaModuleWrapper.cpp index ba3030061..9f667f23a 100644 --- a/ReactAndroid/src/main/jni/react/jni/JavaModuleWrapper.cpp +++ b/ReactAndroid/src/main/jni/react/jni/JavaModuleWrapper.cpp @@ -74,13 +74,12 @@ std::vector JavaNativeModule::getMethods() { folly::dynamic JavaNativeModule::getConstants() { static auto constantsMethod = - wrapper_->getClass()->getMethod("getConstants"); + wrapper_->getClass()->getMethod("getConstants"); auto constants = constantsMethod(wrapper_); if (!constants) { return nullptr; } else { - // See JavaModuleWrapper#getConstants for the other side of this hack. - return cthis(constants)->consume()[0]; + return cthis(constants)->consume(); } } @@ -147,13 +146,12 @@ std::vector NewJavaNativeModule::getMethods() { folly::dynamic NewJavaNativeModule::getConstants() { static auto constantsMethod = - wrapper_->getClass()->getMethod("getConstants"); + wrapper_->getClass()->getMethod("getConstants"); auto constants = constantsMethod(wrapper_); if (!constants) { return nullptr; } else { - // See JavaModuleWrapper#getConstants for the other side of this hack. - return cthis(constants)->consume()[0]; + return cthis(constants)->consume(); } } diff --git a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp index 81bc89883..703aa0e2a 100644 --- a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp @@ -39,9 +39,9 @@ class JSCJavaScriptExecutorHolder : public HybridClass initHybrid(alias_ref, ReadableNativeArray* jscConfigArray) { + static local_ref initHybrid(alias_ref, ReadableNativeMap* jscConfig) { // See JSCJavaScriptExecutor.Factory() for the other side of this hack. - folly::dynamic jscConfigMap = jscConfigArray->consume()[0]; + folly::dynamic jscConfigMap = jscConfig->consume(); return makeCxxInstance(std::make_shared(std::move(jscConfigMap))); }