Merge pull request #3269 from jianhan-he/master

[core] support sync call module on reactor
diff --git a/weex_core/Source/core/render/page/reactor_page.cpp b/weex_core/Source/core/render/page/reactor_page.cpp
index ff2116c..081e9b33 100644
--- a/weex_core/Source/core/render/page/reactor_page.cpp
+++ b/weex_core/Source/core/render/page/reactor_page.cpp
@@ -19,6 +19,8 @@
 
 #include "core/render/page/reactor_page.h"
 
+#include "third_party/json11/json11.hpp"
+#include "base/string_util.h"
 #include "core/render/manager/render_manager.h"
 #include "core/render/page/render_page.h"
 #include "core/render/node/factory/render_creator.h"
@@ -34,6 +36,87 @@
 #endif
 }
 
+static std::string ResultToString(const std::unique_ptr<ValueWithType>& result) {
+  switch (result->type) {
+    case ParamsType::DOUBLE:
+      return json11::Json(result->value.doubleValue).dump();
+    case ParamsType::STRING: {
+      if (!result->value.string) {
+        return "";
+      } else {
+        std::string ret;
+        if (result->value.string->length > 0) {
+          const auto& basic_string = weex::base::to_utf8(result->value.string->content,
+                                                         result->value.string->length);
+          ret = json11::Json(basic_string).dump();
+        } else {
+          ret = json11::Json("").dump();
+        }
+        free(result->value.string);
+        return ret;
+      }
+    }
+    case ParamsType::BYTEARRAYSTRING: {
+      if (!result->value.byteArray) {
+        return "";//null
+      } else {
+        std::string ret;
+        if (result->value.byteArray->length > 0) {
+          ret = json11::Json(result->value.byteArray->content).dump();
+        } else {
+          ret = json11::Json("").dump();
+        }
+        free(result->value.byteArray);
+        return ret;
+      }
+    }
+    case ParamsType::JSONSTRING: {
+      if (!result->value.string) {
+        return "";
+      } else {
+        std::string ret;
+        std::string err;
+        if (result->value.string->length > 0) {
+          const auto& raw_str = weex::base::to_utf8(result->value.string->content,
+                                                    result->value.string->length);
+
+          const json11::Json& json = json11::Json::parse(raw_str, err);
+          if (err.empty()) {
+            //succ
+            ret = json.dump();
+          } else {
+            LOGE("VnodeManager CallNative return value to object err, %s", err.c_str());
+          }
+        }
+        free(result->value.string);
+        return ret;
+      }
+    }
+    case ParamsType::BYTEARRAYJSONSTRING: {
+      if (!result->value.byteArray) {
+        return "";
+      } else {
+        std::string ret;
+        std::string err;
+        if (result->value.string->length > 0) {
+          const json11::Json& json = json11::Json::parse(result->value.byteArray->content, err);
+          if (err.empty()) {
+            //succ
+            ret = json.dump();
+          } else {
+            LOGE("VnodeManager CallNative return value to object err, %s", err.c_str());
+          }
+        }
+        free(result->value.byteArray);
+        return ret;
+      }
+    }
+    case ParamsType::BYTEARRAY:
+    default:
+      return "";
+  }
+}
+
 void ReactorPage::CreateBody(const std::string& ref,
                              const std::string& type,
                              const std::map<std::string, std::string>& styles,
@@ -77,7 +160,7 @@
     WeexCore::WeexCoreManager::Instance()->script_bridge()->core_side()->RemoveElement(page_id_.c_str(), ref.c_str());
 }
 
-void ReactorPage::CallNativeModule(const std::string& module,
+std::string ReactorPage::CallNativeModule(const std::string& module,
                                    const std::string& method,
                                    const std::string& arguments,
                                    size_t arguments_length,
@@ -87,6 +170,8 @@
       ->getPlatformBridge()
       ->platform_side()
       ->CallNativeModule(page_id_.c_str(), module.c_str(), method.c_str(), arguments.c_str(), static_cast<int>(arguments_length), options.c_str(), options_length);
+
+  return ResultToString(ptr);
 }
 
 void ReactorPage::CallNativeComponent(const std::string& ref,
diff --git a/weex_core/Source/core/render/page/reactor_page.h b/weex_core/Source/core/render/page/reactor_page.h
index 3386238..dd32e8a 100644
--- a/weex_core/Source/core/render/page/reactor_page.h
+++ b/weex_core/Source/core/render/page/reactor_page.h
@@ -59,7 +59,7 @@
 
     const std::string& page_id() const {return page_id_;}
 
-    void CallNativeModule(const std::string& module,
+    std::string CallNativeModule(const std::string& module,
                           const std::string& method,
                           const std::string& arguments,
                           size_t arguments_length,