From c68c47d2bafa8e8e25b534d6cdd1a63bc77a1cf4 Mon Sep 17 00:00:00 2001 From: Krzysztof Piaskowy Date: Sun, 2 Jan 2022 16:11:38 -0800 Subject: [PATCH] Added missing constructor to WritableNativeArray (#32796) Summary: `WritableNativeMap` has two constructors: ```c++ WritableNativeMap(); WritableNativeMap(folly::dynamic &&val); ``` but `WritableNativeMap` has only one constructor: ```c++ WritableNativeMap(); ``` Without a second constructor, I am not able to create `WritableNativeMap` from the existing array. I added this second constructor because I need it for `react-native-reanimated`. ## Changelog [Android] [Added] - Added missing constructor to WritableNativeArray Pull Request resolved: https://github.com/facebook/react-native/pull/32796 Test Plan: ```c++ std::shared_ptr rt = facebook::hermes::makeHermesRuntime(); jsi::Value value; WritableNativeMap::newObjectCxxArgs(jsi::dynamicFromValue(*rt.get(), value)); ``` Reviewed By: cortinico Differential Revision: D33285316 Pulled By: lunaleaps fbshipit-source-id: 1bbd816892f34ae6fef747066893fe3b803c088d --- .../src/main/jni/react/jni/WritableNativeArray.cpp | 7 +++++++ ReactAndroid/src/main/jni/react/jni/WritableNativeArray.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/ReactAndroid/src/main/jni/react/jni/WritableNativeArray.cpp b/ReactAndroid/src/main/jni/react/jni/WritableNativeArray.cpp index 21626aeba31a07..227994274955e9 100644 --- a/ReactAndroid/src/main/jni/react/jni/WritableNativeArray.cpp +++ b/ReactAndroid/src/main/jni/react/jni/WritableNativeArray.cpp @@ -17,6 +17,13 @@ namespace react { WritableNativeArray::WritableNativeArray() : HybridBase(folly::dynamic::array()) {} +WritableNativeArray::WritableNativeArray(folly::dynamic &&val) + : HybridBase(std::move(val)) { + if (!array_.isArray()) { + throw std::runtime_error("WritableNativeArray value must be an array."); + } +} + local_ref WritableNativeArray::initHybrid( alias_ref) { return makeCxxInstance(); diff --git a/ReactAndroid/src/main/jni/react/jni/WritableNativeArray.h b/ReactAndroid/src/main/jni/react/jni/WritableNativeArray.h index b4b3e0c660b88d..40a813d21af99c 100644 --- a/ReactAndroid/src/main/jni/react/jni/WritableNativeArray.h +++ b/ReactAndroid/src/main/jni/react/jni/WritableNativeArray.h @@ -29,6 +29,8 @@ struct WritableNativeArray "Lcom/facebook/react/bridge/WritableNativeArray;"; WritableNativeArray(); + WritableNativeArray(folly::dynamic &&val); + static jni::local_ref initHybrid(jni::alias_ref); void pushNull();