Skip to content

Commit

Permalink
Translating NativeArray into NativeMap on getConstants
Browse files Browse the repository at this point in the history
Reviewed By: javache

Differential Revision: D5321741

fbshipit-source-id: 2465c69a5bd1d4f3cf20ba73e163372b12616312
  • Loading branch information
Joana Lopes authored and facebook-github-bot committed Jun 29, 2017
1 parent 33057aa commit 25d19e3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
@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
Expand All @@ -34,9 +31,9 @@ public JavaScriptExecutor create() throws Exception {
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,8 @@ public List<MethodDescriptor> getMethodDescriptors() {
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;
}
Expand All @@ -145,9 +143,7 @@ public List<MethodDescriptor> getMethodDescriptors() {
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);
Expand Down
10 changes: 4 additions & 6 deletions ReactAndroid/src/main/jni/react/jni/JavaModuleWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,12 @@ std::vector<MethodDescriptor> JavaNativeModule::getMethods() {

folly::dynamic JavaNativeModule::getConstants() {
static auto constantsMethod =
wrapper_->getClass()->getMethod<NativeArray::javaobject()>("getConstants");
wrapper_->getClass()->getMethod<NativeMap::javaobject()>("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();
}
}

Expand Down Expand Up @@ -147,13 +146,12 @@ std::vector<MethodDescriptor> NewJavaNativeModule::getMethods() {

folly::dynamic NewJavaNativeModule::getConstants() {
static auto constantsMethod =
wrapper_->getClass()->getMethod<NativeArray::javaobject()>("getConstants");
wrapper_->getClass()->getMethod<NativeMap::javaobject()>("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();
}
}

Expand Down
4 changes: 2 additions & 2 deletions ReactAndroid/src/main/jni/react/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class JSCJavaScriptExecutorHolder : public HybridClass<JSCJavaScriptExecutorHold
public:
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/bridge/JSCJavaScriptExecutor;";

static local_ref<jhybriddata> initHybrid(alias_ref<jclass>, ReadableNativeArray* jscConfigArray) {
static local_ref<jhybriddata> initHybrid(alias_ref<jclass>, 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<JSCExecutorFactory>(std::move(jscConfigMap)));
}

Expand Down

0 comments on commit 25d19e3

Please sign in to comment.