[WEEX-378][android] wson support for weex-core new architecture and remove rapidjson
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/50ae70ce Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/50ae70ce Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/50ae70ce Branch: refs/heads/master Commit: 50ae70ce89da8746ade471c84996509a5f22e91f Parents: 162d705 Author: jianbai.gbj <[email protected]> Authored: Fri May 18 19:22:37 2018 +0800 Committer: jianbai.gbj <[email protected]> Committed: Thu May 24 14:52:26 2018 +0800 ---------------------------------------------------------------------- .../java/com/alibaba/weex/WXApplication.java | 4 +- .../weex/extend/module/WXWsonTestModule.java | 26 + android/sdk/libs/armeabi-v7a/libweexjsb.so | Bin 22620 -> 22620 bytes android/sdk/libs/armeabi-v7a/libweexjsc.so | Bin 0 -> 628596 bytes android/sdk/libs/armeabi-v7a/libweexjss.so | Bin 3758900 -> 3758908 bytes android/sdk/libs/armeabi/libweexjsb.so | Bin 22620 -> 22620 bytes android/sdk/libs/armeabi/libweexjsc.so | Bin 0 -> 640884 bytes android/sdk/libs/armeabi/libweexjss.so | Bin 3758900 -> 3758908 bytes android/sdk/libs/x86/libweexjsb.so | Bin 3212 -> 5548 bytes android/sdk/libs/x86/libweexjsc.so | Bin 0 -> 1185692 bytes android/sdk/libs/x86/libweexjss.so | Bin 10990992 -> 12220172 bytes .../java/com/taobao/weex/bridge/WXBridge.java | 49 +- .../com/taobao/weex/bridge/WXBridgeManager.java | 36 +- .../com/taobao/weex/bridge/WXJsFunctions.java | 42 +- .../java/com/taobao/weex/bridge/WXParams.java | 2 +- .../java/com/taobao/weex/common/IWXBridge.java | 1 + .../taobao/weex/ui/component/WXComponent.java | 3 + .../com/taobao/weex/utils/WXWsonJSONSwitch.java | 100 + .../main/java/com/taobao/weex/wson/Wson.java | 820 ++++++ .../java/com/taobao/weex/wson/WsonUtils.java | 54 + weex_core/Source/CMakeLists.txt | 10 +- .../android/base/string/scoped_jstring_utf8.h | 2 - .../Source/android/base/string/string_utils.h | 34 +- .../android/bridge/impl/bridge_impl_android.cpp | 18 +- .../android/bridge/impl/bridge_impl_android.h | 4 +- .../bridge/impl/jsfunction_impl_android.cpp | 49 +- .../native_render_object_utils_impl_android.cpp | 5 + weex_core/Source/android/jniprebuild/jni_files | 4 +- .../jniprebuild/jniheader/WXJsFunctions_jni.h | 24 +- .../jsengine/multiprocess/ExtendJSApi.cpp | 41 +- .../android/jsengine/multiprocess/WeexProxy.cpp | 209 +- weex_core/Source/core/api/WeexJSCoreApi.cpp | 29 +- weex_core/Source/core/api/WeexJSCoreApi.h | 6 +- weex_core/Source/core/bridge/bridge.h | 4 +- weex_core/Source/core/parser/dom_parser.cpp | 532 ---- weex_core/Source/core/parser/dom_parser.h | 151 - weex_core/Source/core/parser/dom_wson.cpp | 224 ++ weex_core/Source/core/parser/dom_wson.h | 42 + .../core/render/manager/render_manager.cpp | 34 +- .../Source/core/render/manager/render_manager.h | 10 +- .../Source/core/render/page/render_page.cpp | 1 - weex_core/Source/include/WeexApiHeader.h | 34 +- weex_core/Source/rapidjson/allocators.h | 271 -- weex_core/Source/rapidjson/document.h | 2618 ------------------ weex_core/Source/rapidjson/encodedstream.h | 299 -- weex_core/Source/rapidjson/encodings.h | 716 ----- weex_core/Source/rapidjson/error/en.h | 74 - weex_core/Source/rapidjson/error/error.h | 161 -- weex_core/Source/rapidjson/filereadstream.h | 99 - weex_core/Source/rapidjson/filewritestream.h | 104 - weex_core/Source/rapidjson/fwd.h | 151 - .../Source/rapidjson/internal/biginteger.h | 290 -- weex_core/Source/rapidjson/internal/diyfp.h | 258 -- weex_core/Source/rapidjson/internal/dtoa.h | 245 -- weex_core/Source/rapidjson/internal/ieee754.h | 78 - weex_core/Source/rapidjson/internal/itoa.h | 304 -- weex_core/Source/rapidjson/internal/meta.h | 181 -- weex_core/Source/rapidjson/internal/pow10.h | 55 - weex_core/Source/rapidjson/internal/regex.h | 734 ----- weex_core/Source/rapidjson/internal/stack.h | 231 -- weex_core/Source/rapidjson/internal/strfunc.h | 69 - weex_core/Source/rapidjson/internal/strtod.h | 269 -- weex_core/Source/rapidjson/internal/swap.h | 46 - weex_core/Source/rapidjson/istreamwrapper.h | 115 - weex_core/Source/rapidjson/memorybuffer.h | 70 - weex_core/Source/rapidjson/memorystream.h | 71 - .../Source/rapidjson/msinttypes/inttypes.h | 316 --- weex_core/Source/rapidjson/msinttypes/stdint.h | 300 -- weex_core/Source/rapidjson/ostreamwrapper.h | 81 - weex_core/Source/rapidjson/pointer.h | 1358 --------- weex_core/Source/rapidjson/prettywriter.h | 277 -- weex_core/Source/rapidjson/rapidjson.h | 628 ----- weex_core/Source/rapidjson/reader.h | 2221 --------------- weex_core/Source/rapidjson/schema.h | 2026 -------------- weex_core/Source/rapidjson/stream.h | 179 -- weex_core/Source/rapidjson/stringbuffer.h | 121 - weex_core/Source/rapidjson/writer.h | 711 ----- weex_core/Source/wson/wson.c | 345 +++ weex_core/Source/wson/wson.h | 127 + weex_core/Source/wson/wson_parser.cpp | 306 ++ weex_core/Source/wson/wson_parser.h | 194 ++ weex_core/Source/wson/wson_util.cpp | 270 ++ weex_core/Source/wson/wson_util.h | 58 + weex_core/debug.sh | 8 +- weex_core/release.sh | 6 + weex_core/trace.sh | 2 + 86 files changed, 2973 insertions(+), 16674 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/playground/app/src/main/java/com/alibaba/weex/WXApplication.java ---------------------------------------------------------------------- diff --git a/android/playground/app/src/main/java/com/alibaba/weex/WXApplication.java b/android/playground/app/src/main/java/com/alibaba/weex/WXApplication.java index 35fd36a..e7499f2 100644 --- a/android/playground/app/src/main/java/com/alibaba/weex/WXApplication.java +++ b/android/playground/app/src/main/java/com/alibaba/weex/WXApplication.java @@ -63,8 +63,8 @@ public class WXApplication extends Application { **/ // initDebugEnvironment(true, false, "DEBUG_SERVER_HOST"); WXBridgeManager.updateGlobalConfig("wson_on"); - WXEnvironment.setOpenDebugLog(true); - WXEnvironment.setApkDebugable(true); + WXEnvironment.setOpenDebugLog(false); + WXEnvironment.setApkDebugable(false); WXSDKEngine.addCustomOptions("appName", "WXSample"); WXSDKEngine.addCustomOptions("appGroup", "WXApp"); WXSDKEngine.initialize(this, http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/playground/app/src/main/java/com/alibaba/weex/extend/module/WXWsonTestModule.java ---------------------------------------------------------------------- diff --git a/android/playground/app/src/main/java/com/alibaba/weex/extend/module/WXWsonTestModule.java b/android/playground/app/src/main/java/com/alibaba/weex/extend/module/WXWsonTestModule.java index f3fb1ff..1982080 100644 --- a/android/playground/app/src/main/java/com/alibaba/weex/extend/module/WXWsonTestModule.java +++ b/android/playground/app/src/main/java/com/alibaba/weex/extend/module/WXWsonTestModule.java @@ -2,10 +2,15 @@ package com.alibaba.weex.extend.module; import android.util.Log; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.taobao.weex.WXEnvironment; import com.taobao.weex.annotation.JSMethod; import com.taobao.weex.bridge.JSCallback; +import com.taobao.weex.bridge.WXBridgeManager; import com.taobao.weex.common.WXModule; +import com.taobao.weex.utils.WXWsonJSONSwitch; +import com.taobao.weex.wson.Wson; /** * Created by furture on 2018/1/18. @@ -54,4 +59,25 @@ public class WXWsonTestModule extends WXModule { back.put("javaJSON", back.toJSONString()); callback.invoke(back); } + + @JSMethod(uiThread = false) + public Object benchmark(JSONObject params) { + if(params == null){ + throw new RuntimeException("params is null"); + }//do nothing + return params; + } + + @JSMethod(uiThread = false) + public void switchTrans(JSCallback callback) { + if(WXWsonJSONSwitch.USE_WSON){ + WXBridgeManager.updateGlobalConfig("wson_off"); + callback.invoke("wson off, use json"); + }else{ + WXBridgeManager.updateGlobalConfig("wson_on"); + callback.invoke("wson on, use wson"); + } + } + + } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/libs/armeabi-v7a/libweexjsb.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/armeabi-v7a/libweexjsb.so b/android/sdk/libs/armeabi-v7a/libweexjsb.so index f0287cf..8e3a855 100755 Binary files a/android/sdk/libs/armeabi-v7a/libweexjsb.so and b/android/sdk/libs/armeabi-v7a/libweexjsb.so differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/libs/armeabi-v7a/libweexjsc.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/armeabi-v7a/libweexjsc.so b/android/sdk/libs/armeabi-v7a/libweexjsc.so new file mode 100755 index 0000000..3e4ca8a Binary files /dev/null and b/android/sdk/libs/armeabi-v7a/libweexjsc.so differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/libs/armeabi-v7a/libweexjss.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/armeabi-v7a/libweexjss.so b/android/sdk/libs/armeabi-v7a/libweexjss.so index 2e4f52a..dee6022 100755 Binary files a/android/sdk/libs/armeabi-v7a/libweexjss.so and b/android/sdk/libs/armeabi-v7a/libweexjss.so differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/libs/armeabi/libweexjsb.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/armeabi/libweexjsb.so b/android/sdk/libs/armeabi/libweexjsb.so index f0287cf..8e3a855 100755 Binary files a/android/sdk/libs/armeabi/libweexjsb.so and b/android/sdk/libs/armeabi/libweexjsb.so differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/libs/armeabi/libweexjsc.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/armeabi/libweexjsc.so b/android/sdk/libs/armeabi/libweexjsc.so new file mode 100644 index 0000000..f6f75bc Binary files /dev/null and b/android/sdk/libs/armeabi/libweexjsc.so differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/libs/armeabi/libweexjss.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/armeabi/libweexjss.so b/android/sdk/libs/armeabi/libweexjss.so index 2e4f52a..dee6022 100755 Binary files a/android/sdk/libs/armeabi/libweexjss.so and b/android/sdk/libs/armeabi/libweexjss.so differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/libs/x86/libweexjsb.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/x86/libweexjsb.so b/android/sdk/libs/x86/libweexjsb.so index 89b54ae..165578b 100755 Binary files a/android/sdk/libs/x86/libweexjsb.so and b/android/sdk/libs/x86/libweexjsb.so differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/libs/x86/libweexjsc.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/x86/libweexjsc.so b/android/sdk/libs/x86/libweexjsc.so new file mode 100644 index 0000000..ac8b642 Binary files /dev/null and b/android/sdk/libs/x86/libweexjsc.so differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/libs/x86/libweexjss.so ---------------------------------------------------------------------- diff --git a/android/sdk/libs/x86/libweexjss.so b/android/sdk/libs/x86/libweexjss.so index d452b26..b5ad418 100755 Binary files a/android/sdk/libs/x86/libweexjss.so and b/android/sdk/libs/x86/libweexjss.so differ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java index c4b7aed..c674ed6 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java @@ -24,6 +24,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.taobao.weex.WXEnvironment; +import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.adapter.IWXUserTrackAdapter; import com.taobao.weex.common.IWXBridge; @@ -32,6 +33,7 @@ import com.taobao.weex.dom.CSSShorthand; import com.taobao.weex.layout.ContentBoxMeasurement; import com.taobao.weex.utils.WXExceptionUtils; import com.taobao.weex.utils.WXLogUtils; +import com.taobao.weex.utils.WXWsonJSONSwitch; import java.io.Serializable; import java.util.HashMap; @@ -165,11 +167,25 @@ public class WXBridge implements IWXBridge { * @param callback */ public int callNative(String instanceId, byte[] tasks, String callback) { - return callNative(instanceId, new String(tasks), callback); + return callNative(instanceId, (JSONArray) JSON.parseArray(new String(tasks)), callback); } @Override public int callNative(String instanceId, String tasks, String callback) { + try{ + return callNative(instanceId, JSONArray.parseArray(tasks), callback); + }catch (Exception e){ + WXLogUtils.e(TAG, "callNative throw exception: " + e.getMessage()); + return IWXBridge.INSTANCE_RENDERING; + } + } + + private int callNative(String instanceId, JSONArray tasks, String callback){ + long start = System.currentTimeMillis(); + WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId); + if (instance != null) { + instance.firstScreenCreateInstanceTime(start); + } int errorCode = IWXBridge.INSTANCE_RENDERING; try { errorCode = WXBridgeManager.getInstance().callNative(instanceId, tasks, callback); @@ -203,16 +219,18 @@ public class WXBridge implements IWXBridge { */ @Override public Object callNativeModule(String instanceId, String module, String method, byte[] arguments, byte[] options) { - JSONArray argArray = null; - if (arguments != null) { - argArray = JSON.parseArray(new String(arguments)); - } - JSONObject optionsObj = null; - if (options != null) { - optionsObj = JSON.parseObject(new String(options)); + try{ + JSONArray argArray = (JSONArray) WXWsonJSONSwitch.parseWsonOrJSON(arguments); + JSONObject optionsObj = null; + if (options != null) { + optionsObj = (JSONObject) WXWsonJSONSwitch.parseWsonOrJSON(options); + } + Object object = WXBridgeManager.getInstance().callNativeModule(instanceId, module, method, argArray, optionsObj); + return WXWsonJSONSwitch.toWsonOrJsonWXJSObject(object); + }catch (Exception e){ + WXLogUtils.e(TAG, e); + return new WXJSObject(null); } - Object object = WXBridgeManager.getInstance().callNativeModule(instanceId, module, method, argArray, optionsObj); - return new WXJSObject(object); } /** @@ -225,9 +243,14 @@ public class WXBridge implements IWXBridge { * @param options option arguments for extending */ @Override - public void callNativeComponent(String instanceId, String ref, String method, byte[] arguments, byte[] options) { - JSONArray argArray = JSON.parseArray(new String(arguments)); - WXBridgeManager.getInstance().callNativeComponent(instanceId, ref, method, argArray, options); + public void callNativeComponent(String instanceId, String ref, String method, byte[] arguments, byte[] optionsData) { + try{ + JSONArray argArray = (JSONArray) WXWsonJSONSwitch.parseWsonOrJSON(arguments); + Object options = WXWsonJSONSwitch.parseWsonOrJSON(optionsData); + WXBridgeManager.getInstance().callNativeComponent(instanceId, ref, method, argArray, options); + }catch (Exception e){ + WXLogUtils.e(TAG, e); + } } public void setTimeoutNative(String callbackId, String time) { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java index f8cc404..1e4fa90 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java @@ -38,7 +38,6 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.taobao.weex.WXEnvironment; -import com.taobao.weex.WXSDKEngine; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.adapter.IWXJSExceptionAdapter; @@ -73,12 +72,12 @@ import com.taobao.weex.ui.action.GraphicActionUpdateAttr; import com.taobao.weex.ui.action.GraphicActionUpdateStyle; import com.taobao.weex.ui.action.GraphicPosition; import com.taobao.weex.ui.action.GraphicSize; -import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.module.WXDomModule; import com.taobao.weex.utils.WXExceptionUtils; import com.taobao.weex.utils.WXFileUtils; import com.taobao.weex.utils.WXJsonUtils; import com.taobao.weex.utils.WXLogUtils; +import com.taobao.weex.utils.WXWsonJSONSwitch; import com.taobao.weex.utils.WXUtils; import com.taobao.weex.utils.WXViewUtils; import com.taobao.weex.utils.batch.BactchExecutor; @@ -554,8 +553,8 @@ public class WXBridgeManager implements Callback, BactchExecutor { * @param tasks tasks to be executed * @param callback next tick id */ - public int callNative(String instanceId, String tasks, String callback) { - if (TextUtils.isEmpty(tasks)) { + public int callNative(String instanceId, JSONArray tasks, String callback) { + if (tasks == null) { String err = "[WXBridgeManager] callNative: call Native tasks is null"; WXLogUtils.e(err); WXExceptionUtils.commitCriticalExceptionRT(instanceId, @@ -578,7 +577,7 @@ public class WXBridgeManager implements Callback, BactchExecutor { long parseNanos = System.nanoTime(); - JSONArray array = JSON.parseArray(tasks); + JSONArray array = tasks; parseNanos = System.nanoTime() - parseNanos; if (null != array && array.size() > 0) { @@ -880,7 +879,7 @@ public class WXBridgeManager implements Callback, BactchExecutor { Object[] tasks = {task}; WXJSObject[] jsArgs = { new WXJSObject(WXJSObject.String, instanceId), - new WXJSObject(WXJSObject.JSON, WXJsonUtils.fromObjectToJSONString(tasks))}; + WXWsonJSONSwitch.toWsonOrJsonWXJSObject(tasks)}; invokeExecJS(String.valueOf(instanceId), null, METHOD_CALL_JS, jsArgs, true); jsArgs[0] = null; jsArgs = null; @@ -920,13 +919,13 @@ public class WXBridgeManager implements Callback, BactchExecutor { Object[] tasks = {task}; WXJSObject[] jsArgs = { new WXJSObject(WXJSObject.String, instanceId), - new WXJSObject(WXJSObject.JSON, WXJsonUtils.fromObjectToJSONString(tasks))}; + WXWsonJSONSwitch.toWsonOrJsonWXJSObject(tasks)}; byte[] taskResult = invokeExecJSWithResult(String.valueOf(instanceId), null, METHOD_CALL_JS, jsArgs, true); if(eventCallback == null){ return; } if(taskResult != null){ - JSONArray arrayResult = (JSONArray) JSON.parse(new String(taskResult, "UTF-8")); + JSONArray arrayResult = (JSONArray) WXWsonJSONSwitch.parseWsonOrJSON(taskResult); if(arrayResult != null && arrayResult.size() > 0){ result = arrayResult.get(0); } @@ -1602,7 +1601,7 @@ public class WXBridgeManager implements Callback, BactchExecutor { private byte[] invokeExecJSWithResult(String instanceId, String namespace, String function, WXJSObject[] args,boolean logTaskDetail){ - if (WXEnvironment.isOpenDebugLog()) { + if (WXEnvironment.isOpenDebugLog() && BRIDGE_LOG_SWITCH) { mLodBuilder.append("callJS >>>> instanceId:").append(instanceId) .append("function:").append(function); if(logTaskDetail) { @@ -1767,8 +1766,7 @@ public class WXBridgeManager implements Callback, BactchExecutor { WXJSObject[] args = { new WXJSObject(WXJSObject.String, instanceId), - new WXJSObject(WXJSObject.JSON, - WXJsonUtils.fromObjectToJSONString(task))}; + WXWsonJSONSwitch.toWsonOrJsonWXJSObject(task)}; invokeExecJS(String.valueOf(instanceId), null, METHOD_CALL_JS, args); @@ -1937,8 +1935,7 @@ public class WXBridgeManager implements Callback, BactchExecutor { return; } - WXJSObject[] args = {new WXJSObject(WXJSObject.JSON, - WXJsonUtils.fromObjectToJSONString(modules))}; + WXJSObject[] args = {WXWsonJSONSwitch.toWsonOrJsonWXJSObject(modules)}; try { mWXBridge.execJS("", null, METHOD_REGISTER_MODULES, args); try { @@ -1980,8 +1977,7 @@ public class WXBridgeManager implements Callback, BactchExecutor { return; } - WXJSObject[] args = {new WXJSObject(WXJSObject.JSON, - WXJsonUtils.fromObjectToJSONString(components))}; + WXJSObject[] args = {WXWsonJSONSwitch.toWsonOrJsonWXJSObject(components)}; try { mWXBridge.execJS("", null, METHOD_REGISTER_COMPONENTS, args); } catch (Throwable e) { @@ -2167,6 +2163,11 @@ public class WXBridgeManager implements Callback, BactchExecutor { } } } + if(globalConfig.contains(WXWsonJSONSwitch.WSON_OFF)){ + WXWsonJSONSwitch.USE_WSON = false; + }else{ + WXWsonJSONSwitch.USE_WSON = true; + } } }; if(mBridgeManager != null && mBridgeManager.isJSFrameworkInit()){ @@ -2530,7 +2531,10 @@ public class WXBridgeManager implements Callback, BactchExecutor { addAction.setIndex(index); } WXSDKManager.getInstance().getWXRenderManager().postGraphicAction(pageId, addAction); - WXSDKManager.getInstance().getSDKInstance(pageId).removeInActiveAddElmentAction(ref); + WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(pageId); + if(instance != null){ + instance.removeInActiveAddElmentAction(ref); + } } else { final BasicGraphicAction action = new GraphicActionLayout(pageId, ref, position, size); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/src/main/java/com/taobao/weex/bridge/WXJsFunctions.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/WXJsFunctions.java b/android/sdk/src/main/java/com/taobao/weex/bridge/WXJsFunctions.java index 53108ef..3624f23 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/WXJsFunctions.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/WXJsFunctions.java @@ -18,7 +18,10 @@ */ package com.taobao.weex.bridge; +import com.alibaba.fastjson.JSON; import com.taobao.weex.common.IWXJsFunctions; +import com.taobao.weex.utils.WXWsonJSONSwitch; +import com.taobao.weex.wson.WsonUtils; /** * Created by darin on 27/03/2018. @@ -37,16 +40,31 @@ public class WXJsFunctions implements IWXJsFunctions { @Override public native void jsHandleCallNative(String instanceId, byte[] tasks, String callback); + @Override - public native void jsHandleCallNativeModule(String instanceId, String module, String method, byte[] arguments, byte[] options); + public void jsHandleCallNativeModule(String instanceId, String module, String method, byte[] arguments, byte[] options){ + jsHandleCallNativeModule(instanceId, module, method, + WXWsonJSONSwitch.convertJSONToWsonIfUseWson(arguments), WXWsonJSONSwitch.convertJSONToWsonIfUseWson(options), true); + } + + public native void jsHandleCallNativeModule(String instanceId, String module, String method, byte[] arguments, byte[] options, boolean h5); @Override - public native void jsHandleCallNativeComponent(String instanceId, String componentRef, String method, byte[] arguments, byte[] options); + public void jsHandleCallNativeComponent(String instanceId, String componentRef, String method, byte[] arguments, byte[] options){ + jsHandleCallNativeComponent(instanceId, componentRef, method, arguments, options, true); + } + + + public native void jsHandleCallNativeComponent(String instanceId, String componentRef, String method, byte[] arguments, byte[] options, boolean from); @Override - public native void jsHandleCallAddElement(String instanceId, String ref, String dom, String index); + public void jsHandleCallAddElement(String instanceId, String ref, String dom, String index){ + jsHandleCallAddElement(instanceId, ref, WsonUtils.toWson(JSON.parse(dom)), index, true); + } + + public native void jsHandleCallAddElement(String instanceId, String ref, byte[] dom, String index, boolean h5); @Override @@ -58,7 +76,11 @@ public class WXJsFunctions implements IWXJsFunctions { @Override - public native void jsFunctionCallCreateBody(String pageId, String domStr); + public void jsFunctionCallCreateBody(String pageId, String domStr){ + jsFunctionCallCreateBody(pageId, WsonUtils.toWson(JSON.parse(domStr)), true); + } + + public native void jsFunctionCallCreateBody(String pageId, byte[] domStr, boolean h5); @Override @@ -74,11 +96,19 @@ public class WXJsFunctions implements IWXJsFunctions { @Override - public native void jsFunctionCallUpdateAttrs(String pageId, String ref, String data); + public void jsFunctionCallUpdateAttrs(String pageId, String ref, String data){ + jsFunctionCallUpdateAttrs(pageId, ref, WsonUtils.toWson(JSON.parseObject(data)), true); + } + + public native void jsFunctionCallUpdateAttrs(String pageId, String ref, byte[] data, boolean h5); @Override - public native void jsFunctionCallUpdateStyle(String pageId, String ref, String data); + public void jsFunctionCallUpdateStyle(String pageId, String ref, String data){ + jsFunctionCallUpdateStyle(pageId, ref, WsonUtils.toWson(JSON.parseObject(data)), true); + } + + public native void jsFunctionCallUpdateStyle(String pageId, String ref, byte[] data, boolean h5); @Override http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/src/main/java/com/taobao/weex/bridge/WXParams.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/WXParams.java b/android/sdk/src/main/java/com/taobao/weex/bridge/WXParams.java index 495cdab..5a7081d 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/WXParams.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/WXParams.java @@ -145,7 +145,7 @@ public class WXParams { } public String getUseSingleProcess() { - WXLogUtils.e("getUseSingleProcess is running"); + WXLogUtils.e("getUseSingleProcess is running " + useSingleProcess); return useSingleProcess; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/src/main/java/com/taobao/weex/common/IWXBridge.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/common/IWXBridge.java b/android/sdk/src/main/java/com/taobao/weex/common/IWXBridge.java index 092a5f3..ee9100b 100644 --- a/android/sdk/src/main/java/com/taobao/weex/common/IWXBridge.java +++ b/android/sdk/src/main/java/com/taobao/weex/common/IWXBridge.java @@ -105,6 +105,7 @@ public interface IWXBridge extends IWXObject { */ int callNative(String instanceId, byte[] tasks, String callback); + int callNative(String instanceId, String tasks, String callback); void reportJSException(String instanceId, String func, String exception); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java index 94f4848..1463452 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java @@ -715,6 +715,9 @@ public abstract class WXComponent<T extends View> extends WXBasicComponent imple * @return true means that the property is consumed */ protected boolean setProperty(String key, Object param) { + if(key == null){ + return true; + } switch (key) { case Constants.Name.PREVENT_MOVE_EVENT: if (mGesture != null) { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/src/main/java/com/taobao/weex/utils/WXWsonJSONSwitch.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/utils/WXWsonJSONSwitch.java b/android/sdk/src/main/java/com/taobao/weex/utils/WXWsonJSONSwitch.java new file mode 100644 index 0000000..1904d3c --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/utils/WXWsonJSONSwitch.java @@ -0,0 +1,100 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.utils; + +import com.alibaba.fastjson.JSON; +import com.taobao.weex.bridge.WXJSObject; +import com.taobao.weex.wson.Wson; +import com.taobao.weex.wson.WsonUtils; + +/** + * Created by furture on 2018/5/17. + */ + +public class WXWsonJSONSwitch { + + private static final String TAG = "WXSwitch"; + + /** + * switch input data to target according to config, if not use wson return normal data + * */ + public static final byte[] convertJSONToWsonIfUseWson(byte[] json){ + if(!USE_WSON){ + return json; + } + if(json == null){ + return null; + } + return WsonUtils.toWson(JSON.parse(json)); + } + + /** + * parse json or wson data by config switch + * */ + public static final Object parseWsonOrJSON(byte[] data){ + if(data == null){ + return null; + } + try{ + if(USE_WSON){ + return Wson.parse(data); + }else{ + return JSON.parse(new String(data, "UTF-8")); + } + }catch (Exception e){ + WXLogUtils.e(TAG, e); + if(USE_WSON){ //fallback + return JSON.parse(new String(data)); + }else{ + return Wson.parse(data); + } + } + } + + /** + * to wson or wson WXJSObject + * */ + public static final WXJSObject toWsonOrJsonWXJSObject(Object tasks){ + if(tasks == null){ + return new WXJSObject(null); + } + if(tasks.getClass() == WXJSObject.class){ + return (WXJSObject) tasks; + } + if(USE_WSON) { + return new WXJSObject(WXJSObject.WSON, Wson.toWson(tasks)); + }else{ + return new WXJSObject(WXJSObject.JSON, WXJsonUtils.fromObjectToJSONString(tasks)); + } + } + + + + /** + * config whether use json or wson, you should update this value by updateGlobalConfig(String config) + * in WXBridgeManager class method + * */ + public static boolean USE_WSON = true; + + + /**wson off */ + public static final String WSON_OFF = "wson_off"; + + +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/src/main/java/com/taobao/weex/wson/Wson.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/wson/Wson.java b/android/sdk/src/main/java/com/taobao/weex/wson/Wson.java new file mode 100644 index 0000000..b8b8992 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/wson/Wson.java @@ -0,0 +1,820 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.wson; + + +import android.support.v4.util.LruCache; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.annotation.JSONField; +import com.taobao.weex.utils.WXLogUtils; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * fast binary json format for parse map and serialize map + * Created by efurture on 2017/8/16. + */ +public class Wson { + + /** + * skip map null values + * */ + public static final boolean WriteMapNullValue = false; + /** + * wson data type + * */ + private static final byte NULL_TYPE = '0'; + + private static final byte STRING_TYPE = 's'; + + private static final byte BOOLEAN_TYPE_TRUE = 't'; + + private static final byte BOOLEAN_TYPE_FALSE = 'f'; + + private static final byte NUMBER_INT_TYPE = 'i'; + + private static final byte NUMBER_LONG_TYPE = 'l'; + + private static final byte NUMBER_BIG_INTEGER_TYPE = 'g'; + + private static final byte NUMBER_BIG_DECIMAL_TYPE = 'e'; + + private static final byte NUMBER_DOUBLE_TYPE = 'd'; + + private static final byte NUMBER_FLOAT_TYPE = 'F'; + + private static final byte ARRAY_TYPE = '['; + + private static final byte MAP_TYPE = '{'; + + /** + * StringUTF-16, byte order with native byte order + * */ + private static final boolean IS_NATIVE_LITTLE_ENDIAN = (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN); + + + /** + * parse wson data to object, please use WXJsonUtils.parseWson + * @param data byte array + * */ + public static final Object parse(byte[] data){ + if(data == null){ + return null; + } + try{ + Parser parser = new Parser(data); + Object object = parser.parse(); + parser.close(); + return object; + }catch (Exception e){ + WXLogUtils.e("parseWson", e); + return null; + } + } + + + /** + * serialize object to wson data, please use WXJsonUtils.toWsonOrJsonWXJSObject + * */ + public static final byte[] toWson(Object object){ + if(object == null){ + return null; + } + Builder builder = new Builder(); + byte[] bts = builder.toWson(object); + builder.close(); + return bts; + } + + + /** + * wson data parser + * */ + private static final class Parser { + + private int position = 0; + private byte[] buffer; + private char[] charsBuffer; + + private Parser(byte[] buffer) { + this.buffer = buffer; + charsBuffer = localCharsBufferCache.get(); + if(charsBuffer != null){ + localCharsBufferCache.set(null); + }else{ + charsBuffer = new char[512]; + } + } + + + private final Object parse(){ + return readObject(); + } + + private final void close(){ + position = 0; + buffer = null; + if(charsBuffer != null){ + localCharsBufferCache.set(charsBuffer); + } + charsBuffer = null; + } + + private final Object readObject(){ + byte type = readType(); + switch (type){ + case STRING_TYPE: + return readUTF16String(); + case NUMBER_INT_TYPE : + return readVarInt(); + case NUMBER_FLOAT_TYPE : + return readFloat(); + case MAP_TYPE: + return readMap(); + case ARRAY_TYPE: + return readArray(); + case NUMBER_DOUBLE_TYPE : + return readDouble(); + case NUMBER_LONG_TYPE : + return readLong(); + case NUMBER_BIG_INTEGER_TYPE : + return new BigInteger(readUTF16String()); + case NUMBER_BIG_DECIMAL_TYPE : + return new BigDecimal(readUTF16String()); + case BOOLEAN_TYPE_FALSE: + return Boolean.FALSE; + case BOOLEAN_TYPE_TRUE: + return Boolean.TRUE; + case NULL_TYPE: + return null; + default: + throw new RuntimeException("wson unhandled type " + type + " " + + position + " length " + buffer.length); + } + } + + + + private final Object readMap(){ + int size = readUInt(); + Map<String, Object> object = new JSONObject();; + for(int i=0; i<size; i++){ + String key = readMapKeyUTF16(); + Object value = readObject(); + object.put(key, value); + } + return object; + } + + private final Object readArray(){ + int length = readUInt(); + List<Object> array = new JSONArray(length); + for(int i=0; i<length; i++){ + array.add(readObject()); + } + return array; + } + + private final byte readType(){ + byte type = buffer[position]; + position ++; + return type; + } + + + private final String readMapKeyUTF16() { + int length = readUInt(); + length = length/2; + if(charsBuffer.length < length){ + charsBuffer = new char[length]; + } + int hash = 5381; + if(IS_NATIVE_LITTLE_ENDIAN){ + for(int i=0; i<length; i++){ + char ch = (char) ((buffer[position] & 0xFF) + + (buffer[position + 1] << 8)); + charsBuffer[i] = (ch); + hash = ((hash << 5) + hash) + ch; + position+=2; + } + }else{ + for(int i=0; i<length; i++){ + char ch = (char) ((buffer[position + 1] & 0xFF) + + (buffer[position] << 8)); + charsBuffer[i] = (ch); + hash = ((hash << 5) + hash) + ch; + position+=2; + } + } + int globalIndex = (globalStringBytesCache.length - 1)&hash; + String cache = globalStringBytesCache[globalIndex]; + if(cache != null + && cache.length() == length){ + boolean isStringEqual = true; + for(int i=0; i<length; i++){ + if(charsBuffer[i] != cache.charAt(i)){ + isStringEqual = false; + break; + } + } + if(isStringEqual) { + return cache; + } + } + cache = new String(charsBuffer, 0, length); + if(length < 64) { + globalStringBytesCache[globalIndex] = cache; + } + return cache; + } + + private final String readUTF16String(){ + int length = readUInt()/2; + if(charsBuffer.length < length){ + charsBuffer = new char[length]; + } + if(IS_NATIVE_LITTLE_ENDIAN){ + for(int i=0; i<length; i++){ + char ch = (char) ((buffer[position] & 0xFF) + + (buffer[position + 1] << 8)); + charsBuffer[i] = (ch); + position+=2; + } + }else{ + for(int i=0; i<length; i++){ + char ch = (char) ((buffer[position + 1] & 0xFF) + + (buffer[position] << 8)); + charsBuffer[i] = (ch); + position+=2; + } + } + return new String(charsBuffer, 0, length); + } + + + + + + private final int readVarInt(){ + int raw = readUInt(); + // This undoes the trick in putVarInt() + int num = (((raw << 31) >> 31) ^ raw) >> 1; + // This extra step lets us deal with the largest signed values by treating + // negative results from read unsigned methods as like unsigned values. + // Must re-flip the top bit if the original read value had it set. + return num ^ (raw & (1 << 31)); + } + + private final int readUInt(){ + int value = 0; + int i = 0; + int b; + while (((b = buffer[position]) & 0x80) != 0) { + value |= (b & 0x7F) << i; + i += 7; + position+=1; + if (i > 35) { + throw new IllegalArgumentException("Variable length quantity is too long"); + } + } + position+=1; + return value | (b << i); + } + + private final long readLong(){ + long number = (((buffer[position + 7] & 0xFFL) ) + + ((buffer[position + 6] & 0xFFL) << 8) + + ((buffer[position + 5] & 0xFFL) << 16) + + ((buffer[position + 4] & 0xFFL) << 24) + + ((buffer[position + 3] & 0xFFL) << 32) + + ((buffer[position + 2] & 0xFFL) << 40) + + ((buffer[position + 1] & 0xFFL) << 48) + + (((long) buffer[position]) << 56)); + position += 8; + return number; + } + + private final Object readDouble(){ + double number = Double.longBitsToDouble(readLong()); + if(number > Integer.MAX_VALUE){ + long numberLong = (long) number; + double doubleLong = (numberLong); + if(number - doubleLong < Double.MIN_NORMAL){ + return numberLong; + } + } + return number; + } + + private Object readFloat() { + int number = (((buffer[position + 3] & 0xFF) ) + + ((buffer[position + 2] & 0xFF) << 8) + + ((buffer[position + 1] & 0xFF) << 16) + + ((buffer[position ] & 0xFF) << 24)); + position +=4; + return Float.intBitsToFloat(number); + } + } + + /** + * wson builder + * */ + private static final class Builder { + + private byte[] buffer; + private int position; + private ArrayList refs; + private final static ThreadLocal<byte[]> bufLocal = new ThreadLocal<byte[]>(); + private final static ThreadLocal<ArrayList> refsLocal = new ThreadLocal<ArrayList>(); + + + + private Builder(){ + buffer = bufLocal.get(); + if(buffer != null) { + bufLocal.set(null); + }else{ + buffer = new byte[1024]; + } + refs = refsLocal.get(); + if(refs != null){ + refsLocal.set(null); + }else{ + refs = new ArrayList<>(16); + } + } + + + private final byte[] toWson(Object object){ + writeObject(object); + byte[] bts = new byte[position]; + System.arraycopy(buffer, 0, bts, 0, position); + return bts; + } + + private final void close(){ + if(buffer.length <= 1024*16){ + bufLocal.set(buffer); + } + if(refs.isEmpty()){ + refsLocal.set(refs); + }else{ + refs.clear(); + } + refs = null; + buffer = null; + position = 0; + } + + private final void writeObject(Object object) { + if(object instanceof CharSequence){ + ensureCapacity(2); + writeByte(STRING_TYPE); + writeUTF16String((CharSequence) object); + return; + }else if (object instanceof Map){ + if(refs.contains(object)){ + ensureCapacity(2); + writeByte(NULL_TYPE); + return; + } + refs.add(object); + Map map = (Map) object; + writeMap(map); + refs.remove(refs.size()-1); + return; + }else if (object instanceof List){ + if(refs.contains(object)){ + ensureCapacity(2); + writeByte(NULL_TYPE); + return; + } + refs.add(object); + ensureCapacity(8); + List list = (List) object; + writeByte(ARRAY_TYPE); + writeUInt(list.size()); + for(Object value : list){ + writeObject(value); + } + refs.remove(refs.size()-1); + return; + }else if (object instanceof Number){ + Number number = (Number) object; + writeNumber(number); + return; + }else if (object instanceof Boolean){ + ensureCapacity(2); + Boolean value = (Boolean) object; + if(value){ + writeByte(BOOLEAN_TYPE_TRUE); + }else{ + writeByte(BOOLEAN_TYPE_FALSE); + } + return; + }else if(object == null){ + ensureCapacity(2); + writeByte(NULL_TYPE); + return; + }else if (object.getClass().isArray()){ + if(refs.contains(object)){ + ensureCapacity(2); + writeByte(NULL_TYPE); + return; + } + refs.add(object); + ensureCapacity(8); + int length = Array.getLength(object); + writeByte(ARRAY_TYPE); + writeUInt(length); + for(int i=0; i<length; i++){ + Object value = Array.get(object, i); + writeObject(value); + } + refs.remove(refs.size()-1); + return; + }else if(object instanceof Date){ + ensureCapacity(10); + double date = ((Date)object).getTime(); + writeByte(NUMBER_DOUBLE_TYPE); + writeDouble(date); + }else if(object instanceof Calendar){ + ensureCapacity(10); + double date = ((Calendar)object).getTime().getTime(); + writeByte(NUMBER_DOUBLE_TYPE); + writeDouble(date); + }else if(object instanceof Collection){ + if(refs.contains(object)){ + ensureCapacity(2); + writeByte(NULL_TYPE); + return; + } + refs.add(object); + ensureCapacity(8); + Collection list = (Collection) object; + writeByte(ARRAY_TYPE); + writeUInt(list.size()); + for(Object value : list){ + writeObject(value); + } + refs.remove(refs.size()-1); + }else{ + if(refs.contains(object)){ + ensureCapacity(2); + writeByte(NULL_TYPE); + }else { + refs.add(object); + if(object.getClass().isEnum()){ + writeObject(JSON.toJSONString(object)); + }else{ + writeAdapterObject(object); + } + refs.remove(refs.size()-1); + } + return; + } + } + + private final void writeNumber(Number number) { + ensureCapacity(12); + if(number instanceof Integer){ + writeByte(NUMBER_INT_TYPE); + writeVarInt(number.intValue()); + return; + } + + if(number instanceof Float){ + writeByte(NUMBER_FLOAT_TYPE); + writeFloat(number.floatValue()); + return; + } + if(number instanceof Double){ + writeByte(NUMBER_DOUBLE_TYPE); + writeDouble(number.doubleValue()); + return; + } + + if(number instanceof Long){ + writeByte(NUMBER_LONG_TYPE); + writeLong(number.longValue()); + return; + } + + if(number instanceof Short + || number instanceof Byte){ + writeByte(NUMBER_INT_TYPE); + writeVarInt(number.intValue()); + return; + } + + if(number instanceof BigInteger){ + writeByte(NUMBER_BIG_INTEGER_TYPE); + writeUTF16String(number.toString()); + return; + } + + if(number instanceof BigDecimal){ + String value = number.toString(); + double doubleValue = number.doubleValue(); + if(value.equals(Double.toString(doubleValue))){ + writeByte(NUMBER_DOUBLE_TYPE); + writeDouble(doubleValue); + }else { + writeByte(NUMBER_BIG_DECIMAL_TYPE); + writeUTF16String(value); + } + return; + } + writeByte(STRING_TYPE); + writeUTF16String(number.toString()); + + } + + private final void writeMap(Map map) { + if(WriteMapNullValue){ + ensureCapacity(8); + writeByte(MAP_TYPE); + writeUInt(map.size()); + Set<Map.Entry<Object,Object>> entries = map.entrySet(); + for(Map.Entry<Object,Object> entry : entries){ + writeMapKeyUTF16(entry.getKey().toString()); + writeObject(entry.getValue()); + } + }else{ + Set<Map.Entry<Object,Object>> entries = map.entrySet(); + int nullValueSize = 0; + for(Map.Entry<Object,Object> entry : entries){ + if(entry.getValue() == null){ + nullValueSize++; + } + } + + ensureCapacity(8); + writeByte(MAP_TYPE); + writeUInt(map.size()-nullValueSize); + for(Map.Entry<Object,Object> entry : entries){ + if(entry.getValue() == null){ + continue; + } + writeMapKeyUTF16(entry.getKey().toString()); + writeObject(entry.getValue()); + } + } + } + + + private final void writeByte(byte type){ + buffer[position] = type; + position++; + } + + private final void writeAdapterObject(Object object){ + if(specialClass.get(object.getClass().getName()) != null){ + writeObject(JSON.toJSON(object)); + return; + } + try{ + writeMap(toMap(object)); + }catch (Exception e){ + specialClass.put(object.getClass().getName(), true); + writeObject(JSON.toJSON(object)); + } + } + + private final Map toMap(Object object){ + Map map = new JSONObject(); + try { + Class<?> targetClass = object.getClass(); + String key = targetClass.getName(); + List<Method> methods = getBeanMethod(key, targetClass); + for (Method method : methods) { + String methodName = method.getName(); + if (methodName.startsWith(METHOD_PREFIX_GET)) { + Object value = method.invoke(object); + if(value != null){ + StringBuilder builder = new StringBuilder(method.getName().substring(3)); + builder.setCharAt(0, Character.toLowerCase(builder.charAt(0))); + map.put(builder.toString(), (Object) value); + } + }else if(methodName.startsWith(METHOD_PREFIX_IS)){ + Object value = method.invoke(object); + if(value != null){ + StringBuilder builder = new StringBuilder(method.getName().substring(2)); + builder.setCharAt(0, Character.toLowerCase(builder.charAt(0))); + map.put(builder.toString(), value); + } + } + } + List<Field> fields = getBeanFields(key, targetClass); + for(Field field : fields){ + String fieldName = field.getName(); + if(map.containsKey(fieldName)){ + continue; + } + Object value = field.get(object); + if(value == null){ + continue; + } + map.put(fieldName, value); + } + }catch (Exception e){ + if(e instanceof RuntimeException){ + throw (RuntimeException)e; + }else{ + throw new RuntimeException(e); + } + } + return map; + } + + private final void writeMapKeyUTF16(String value){ + writeUTF16String(value); + } + + + + + /** + * writeString UTF-16 + * */ + private final void writeUTF16String(CharSequence value){ + int length = value.length(); + ensureCapacity(length*2 + 8); + writeUInt(length*2); + if(IS_NATIVE_LITTLE_ENDIAN){ + for(int i=0; i<length; i++){ + char ch = value.charAt(i); + buffer[position] = (byte) (ch); + buffer[position+1] = (byte) (ch >>> 8); + position+=2; + } + }else{ + for(int i=0; i<length; i++){ + char ch = value.charAt(i); + buffer[position + 1] = (byte) (ch ); + buffer[position] = (byte) (ch >>> 8); + position+=2; + } + } + } + + + private final void writeDouble(double value){ + writeLong(Double.doubleToLongBits(value)); + } + + private final void writeFloat(float value){ + int val = Float.floatToIntBits(value); + buffer[position + 3] = (byte) (val ); + buffer[position + 2] = (byte) (val >>> 8); + buffer[position + 1] = (byte) (val >>> 16); + buffer[position ] = (byte) (val >>> 24); + position += 4; + } + + private final void writeLong(long val){ + buffer[position + 7] = (byte) (val ); + buffer[position + 6] = (byte) (val >>> 8); + buffer[position + 5] = (byte) (val >>> 16); + buffer[position + 4] = (byte) (val >>> 24); + buffer[position + 3] = (byte) (val >>> 32); + buffer[position + 2] = (byte) (val >>> 40); + buffer[position + 1] = (byte) (val >>> 48); + buffer[position ] = (byte) (val >>> 56); + position += 8; + } + + private final void writeVarInt(int value){ + writeUInt((value << 1) ^ (value >> 31)); + } + + private final void writeUInt(int value){ + while ((value & 0xFFFFFF80) != 0) { + buffer[position] = (byte)((value & 0x7F) | 0x80); + position++; + value >>>= 7; + } + buffer[position] = (byte)(value & 0x7F); + position++; + } + + + private final void ensureCapacity(int minCapacity) { + minCapacity += position; + // overflow-conscious code + if (minCapacity - buffer.length > 0){ + int oldCapacity = buffer.length; + int newCapacity = oldCapacity << 1; + if(newCapacity < 1024*16){ + newCapacity = 1024*16; + } + if (newCapacity - minCapacity < 0) { + newCapacity = minCapacity; + } + buffer = Arrays.copyOf(buffer, newCapacity); + } + } + } + + + /** + * cache json property key, most of them all same + * */ + private static final int GLOBAL_STRING_CACHE_SIZE = 2*1024; + private static final ThreadLocal<char[]> localCharsBufferCache = new ThreadLocal<>(); + private static final String[] globalStringBytesCache = new String[GLOBAL_STRING_CACHE_SIZE]; + + + + + /** + * lru cache, to map helper + * */ + private static final String METHOD_PREFIX_GET = "get"; + private static final String METHOD_PREFIX_IS = "is"; + private static LruCache<String, List<Method>> methodsCache = new LruCache<>(128); + private static LruCache<String, List<Field>> fieldsCache = new LruCache<>(128); + private static LruCache<String, Boolean> specialClass = new LruCache<>(16); + + + private static final List<Method> getBeanMethod(String key, Class targetClass){ + List<Method> methods = methodsCache.get(key); + if(methods == null){ + methods = new ArrayList<>(); + Method[] allMethods = targetClass.getMethods(); + for(Method method : allMethods){ + if(method.getDeclaringClass() == Object.class){ + continue; + } + if( (method.getModifiers() & Modifier.STATIC) != 0){ + continue; + } + String methodName = method.getName(); + if(methodName.startsWith(METHOD_PREFIX_GET) + || methodName.startsWith(METHOD_PREFIX_IS)) { + if(method.getAnnotation(JSONField.class) != null){ + throw new UnsupportedOperationException("getBeanMethod JSONField Annotation Not Handled, Use toJSON"); + } + methods.add(method); + } + } + methodsCache.put(key, methods); + } + return methods; + } + + + + private static final List<Field> getBeanFields(String key, Class targetClass){ + List<Field> fieldList = fieldsCache.get(key); + if(fieldList == null) { + Field[] fields = targetClass.getFields(); + fieldList = new ArrayList<>(fields.length); + for(Field field : fields){ + if((field.getModifiers() & Modifier.STATIC) != 0){ + continue; + } + if(field.getAnnotation(JSONField.class) != null){ + throw new UnsupportedOperationException("getBeanMethod JSONField Annotation Not Handled, Use toJSON"); + } + fieldList.add(field); + } + fieldsCache.put(key, fieldList); + } + return fieldList; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/android/sdk/src/main/java/com/taobao/weex/wson/WsonUtils.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/wson/WsonUtils.java b/android/sdk/src/main/java/com/taobao/weex/wson/WsonUtils.java new file mode 100644 index 0000000..dc51438 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/wson/WsonUtils.java @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.wson; + +import com.taobao.weex.utils.WXLogUtils; + +/** + * Created by furture on 2018/5/17. + */ + +public class WsonUtils { + /** + * total entry, with wson support, always parse json + * */ + public static final Object parseWson(byte[] data){ + if(data == null){ + return null; + } + try{ + return Wson.parse(data); + }catch (Exception e){ + WXLogUtils.e("weex wson parse error ", e); + return null; + } + } + + public static final byte[] toWson(Object data){ + if(data == null){ + return null; + } + try{ + return Wson.toWson(data); + }catch (Exception e){ + WXLogUtils.e("weex wson to wson error ", e); + return null; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/weex_core/Source/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/weex_core/Source/CMakeLists.txt b/weex_core/Source/CMakeLists.txt index d2d41d7..53d70e5 100644 --- a/weex_core/Source/CMakeLists.txt +++ b/weex_core/Source/CMakeLists.txt @@ -39,8 +39,6 @@ set(COMMON_SRCS ./core/render/action/render_action_update_attr.cpp ./core/render/action/render_action_update_style.cpp - ./core/parser/dom_parser.cpp - ./core/layout/layout.cpp ./core/layout/style.cpp @@ -53,6 +51,9 @@ set(COMMON_SRCS if (ANDROID) set (ANDROID_SRCS + ./wson/wson.c + ./wson/wson_util.cpp + ./wson/wson_parser.cpp ./android/jniprebuild/jni_load.cc ./android/base/jni/android_jni.cpp ./android/base/jni/scoped_java_ref.cpp @@ -71,6 +72,11 @@ if (ANDROID) ./android/jsengine/multiprocess/WeexJSConnection.cpp ./android/jsengine/multiprocess/WeexProxy.cpp ./android/jsengine/multiprocess/ExtendJSApi.cpp + + + ./core/parser/dom_wson.cpp + + ) add_library(${WEEXCORE_LIBRARY_NAME} SHARED http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/weex_core/Source/android/base/string/scoped_jstring_utf8.h ---------------------------------------------------------------------- diff --git a/weex_core/Source/android/base/string/scoped_jstring_utf8.h b/weex_core/Source/android/base/string/scoped_jstring_utf8.h index ccf2d18..fa739ba 100644 --- a/weex_core/Source/android/base/string/scoped_jstring_utf8.h +++ b/weex_core/Source/android/base/string/scoped_jstring_utf8.h @@ -19,12 +19,10 @@ #ifndef _SCOPED_JSTRING_UTF_8_H_ #define _SCOPED_JSTRING_UTF_8_H_ -#include <locale.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <thread> #include <type_traits> #include "../base64/base64.h" #include <jni.h> http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/weex_core/Source/android/base/string/string_utils.h ---------------------------------------------------------------------- diff --git a/weex_core/Source/android/base/string/string_utils.h b/weex_core/Source/android/base/string/string_utils.h index fd29371..ae3d5f5 100644 --- a/weex_core/Source/android/base/string/string_utils.h +++ b/weex_core/Source/android/base/string/string_utils.h @@ -89,6 +89,18 @@ static std::string jByteArray2Str(JNIEnv *env, jbyteArray barr) { } + +static inline jbyteArray newJByteArray(JNIEnv *env, const char* data, int length) { + jbyteArray jarray = nullptr; + if (data == nullptr || length <= 0) + return jarray; + int byteSize = length; + jbyte *jb = (jbyte*) data; + jarray = env->NewByteArray(byteSize); + env->SetByteArrayRegion(jarray, 0, byteSize, jb); + return jarray; +} + static inline jbyteArray newJByteArray(JNIEnv *env, const char* pat) { jbyteArray jarray = nullptr; if (pat == nullptr) @@ -116,15 +128,23 @@ static inline char* getArumentAsCStr(IPCArguments *arguments, int argument) { const IPCByteArray *ipcBA = arguments->getByteArray(argument); int strLen = ipcBA->length; ret = new char[strLen+1]; - for (int i = 0; i < strLen; ++i) { - ret[i] = ipcBA->content[i]; - } + memcpy(ret, ipcBA->content, strLen); ret[strLen] = '\0'; } return ret; } +static inline int getArumentAsCStrLen(IPCArguments *arguments, int argument) { + if (argument >= arguments->getCount()) + return 0; + if (arguments->getType(argument) == IPCType::BYTEARRAY) { + const IPCByteArray *ipcBA = arguments->getByteArray(argument); + return ipcBA->length; + } + return 0; +} + static inline jbyteArray getArgumentAsJByteArray(JNIEnv* env, IPCArguments* arguments, size_t argument) { jbyteArray ba = nullptr; @@ -176,5 +196,13 @@ static inline void addJSONString(JNIEnv *env, IPCSerializer *serializer, jstring size_t charsLength = scopedString.getCharsLength(); serializer->addJSON(chars, charsLength); } + +static void addBinaryByteArray(JNIEnv* env, IPCSerializer* serializer, jbyteArray array) +{ + size_t length = env->GetArrayLength(array); + jbyte* data = env->GetByteArrayElements(array, 0); + serializer->add((const char*)data, length); + env->ReleaseByteArrayElements(array, data, 0); +} } #endif //_STRING_UTILS_H_ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/weex_core/Source/android/bridge/impl/bridge_impl_android.cpp ---------------------------------------------------------------------- diff --git a/weex_core/Source/android/bridge/impl/bridge_impl_android.cpp b/weex_core/Source/android/bridge/impl/bridge_impl_android.cpp index dbff771..fa230cd 100644 --- a/weex_core/Source/android/bridge/impl/bridge_impl_android.cpp +++ b/weex_core/Source/android/bridge/impl/bridge_impl_android.cpp @@ -221,17 +221,16 @@ namespace WeexCore { } jobject Bridge_Impl_Android::callNativeModule(const char* pageId, const char *module, const char *method, - const char *argString, const char *optString) { + const char *arguments, int argumentsLen, const char *options, int optionsLen) { RenderPage *page = RenderManager::GetInstance()->GetPage(pageId); long long startTime = getCurrentTime(); JNIEnv *env = getJNIEnv(); jstring jModule = env->NewStringUTF(module); jstring jMethod = env->NewStringUTF(method); - jbyteArray jArgString = newJByteArray(env, argString); - jbyteArray jOptString = newJByteArray(env, optString); + jbyteArray jArgString = newJByteArray(env, arguments, argumentsLen); + jbyteArray jOptString = newJByteArray(env, options, optionsLen); jstring jPageId = getKeyFromCache(env, pageId); - jobject result = nullptr; if (jModule != nullptr && jMethod != nullptr) { @@ -258,16 +257,15 @@ namespace WeexCore { return result; } - void Bridge_Impl_Android::callNativeComponent(const char* pageId, const char* ref, - const char *method, const char *argString, - const char *optString) { + void Bridge_Impl_Android::callNativeComponent(const char* pageId, const char* ref, const char *method, + const char *arguments, int argumentsLength, const char *options, int optionsLength) { RenderPage *page = RenderManager::GetInstance()->GetPage(pageId); long long startTime = getCurrentTime(); JNIEnv *env = getJNIEnv(); jstring jMethod = env->NewStringUTF(method); - jbyteArray jArgString = newJByteArray(env, argString); - jbyteArray jOptString = newJByteArray(env, optString); + jbyteArray jArgString = newJByteArray(env, arguments, argumentsLength); + jbyteArray jOptString = newJByteArray(env, options, optionsLength); jstring jPageId = getKeyFromCache(env, pageId); jstring jRef = getKeyFromCache(env, ref); @@ -929,4 +927,4 @@ namespace WeexCore { } return env->CallObjectMethod(jThis, jCallGetMeasurementMethodId, jPageId, jRef); } -} //end WeexCore \ No newline at end of file +} //end WeexCore http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/weex_core/Source/android/bridge/impl/bridge_impl_android.h ---------------------------------------------------------------------- diff --git a/weex_core/Source/android/bridge/impl/bridge_impl_android.h b/weex_core/Source/android/bridge/impl/bridge_impl_android.h index 50c8ba0..0272ae5 100644 --- a/weex_core/Source/android/bridge/impl/bridge_impl_android.h +++ b/weex_core/Source/android/bridge/impl/bridge_impl_android.h @@ -69,10 +69,10 @@ namespace WeexCore { int callNative(const char* pageId, const char *task, const char *callback); jobject callNativeModule(const char* pageId, const char *module, const char *method, - const char *argString, const char *optString); + const char *arguments, int argumentsLength, const char *options, int optionsLength); void callNativeComponent(const char* pageId, const char* ref, const char *method, - const char *argString, const char *optString); + const char *arguments, int argumentsLength, const char *options, int optionsLength); void setTimeout(const char* callbackID, const char* time); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/weex_core/Source/android/bridge/impl/jsfunction_impl_android.cpp ---------------------------------------------------------------------- diff --git a/weex_core/Source/android/bridge/impl/jsfunction_impl_android.cpp b/weex_core/Source/android/bridge/impl/jsfunction_impl_android.cpp index d81c144..e5e89af 100644 --- a/weex_core/Source/android/bridge/impl/jsfunction_impl_android.cpp +++ b/weex_core/Source/android/bridge/impl/jsfunction_impl_android.cpp @@ -41,6 +41,15 @@ static const char *getCharFromJByte(JNIEnv *env, jbyteArray jbyteArray1) { return jByteArray2Str(env, jbyteArray1).c_str(); } +static const int getJByteArraySize(JNIEnv *env, jbyteArray array){ + if(array == nullptr){ + return 0; + } + jsize size = env->GetArrayLength(array); + return size; +} + + static const char *getCharFromJString(JNIEnv *env, jstring string) { if (string == nullptr) return ""; @@ -91,7 +100,7 @@ void jsHandleCallNative(JNIEnv *env, jobject object, jstring instanceId, jbyteAr void jsHandleCallNativeModule(JNIEnv *env, jobject object, jstring instanceId, jstring module, jstring method, jbyteArray - arguments, jbyteArray options) { + arguments, jbyteArray options, jboolean from) { #if JSAPI_LOG @@ -107,7 +116,9 @@ jsHandleCallNativeModule(JNIEnv *env, jobject object, jstring instanceId, jstrin getCharFromJString(env, module), getCharFromJString(env, method), getCharFromJByte(env, arguments), - getCharFromJByte(env, options)); + getJByteArraySize(env, arguments), + getCharFromJByte(env, options), + getJByteArraySize(env, options)); jfieldID jTypeId = env->GetFieldID(jWXJSObject, "type", "I"); jint jTypeInt = env->GetIntField(result, jTypeId); @@ -126,31 +137,44 @@ jsHandleCallNativeModule(JNIEnv *env, jobject object, jstring instanceId, jstrin } else if (jTypeInt == 3) { jstring jDataStr = (jstring) jDataObj; //ret = std::move(createJSONStringResult(env, jDataStr)); + } else if (jTypeInt == 4) { + jbyteArray array = (jbyteArray)jDataObj; + if(array != nullptr){ + int length = env->GetArrayLength(array); + void* data = env->GetByteArrayElements(array, 0); + //ret = std::move(createByteArrayResult((const char*)data, length)); + env->ReleaseByteArrayElements(array, (jbyte*)data, 0); + } } env->DeleteLocalRef(jDataObj); + if(result != nullptr){ + env->DeleteLocalRef(result); + } //return ret; } void jsHandleCallNativeComponent(JNIEnv *env, jobject object, jstring instanceId, jstring componentRef, jstring method, - jbyteArray arguments, jbyteArray options) { + jbyteArray arguments, jbyteArray options, jboolean from) { Bridge_Impl_Android::getInstance()->callNativeComponent(getCharFromJString(env, instanceId), getCharFromJString(env, componentRef), getCharFromJString(env, method), getCharFromJByte(env, arguments), - getCharFromJByte(env, options)); + getJByteArraySize(env, arguments), + getCharFromJByte(env, options), + getJByteArraySize(env, options)); } void -jsHandleCallAddElement(JNIEnv *env, jobject object, jstring instanceId, jstring ref, jstring dom, +jsHandleCallAddElement(JNIEnv *env, jobject object, jstring instanceId, jstring ref, jbyteArray dom, jstring index) { const char *instanceChar = env->GetStringUTFChars(instanceId, 0); const char *refChar = env->GetStringUTFChars(ref, 0); - const char *domChar = env->GetStringUTFChars(dom, 0); + const char *domChar = getCharFromJByte(env, dom); const char *indexChar = env->GetStringUTFChars(index, 0); int indexI = atoi(indexChar); @@ -173,13 +197,12 @@ void jsHandleCallNativeLog(JNIEnv *env, jobject object, jbyteArray str_array) { Bridge_Impl_Android::getInstance()->callNativeLog(getCharFromJByte(env, str_array)); } -void jsFunctionCallCreateBody(JNIEnv *env, jobject object, jstring pageId, jstring domStr) { - +void jsFunctionCallCreateBody(JNIEnv *env, jobject object, jstring pageId, jbyteArray domStr, jboolean from) { if (pageId == nullptr || domStr == nullptr) return; const char *page = env->GetStringUTFChars(pageId, NULL); - const char *dom = env->GetStringUTFChars(domStr, NULL); + const char *dom = getCharFromJByte(env, domStr); if (page == nullptr || dom == nullptr || strlen(dom) == 0) return; RenderManager::GetInstance()->CreatePage(page, dom); @@ -208,17 +231,17 @@ jsFunctionCallRefreshFinish(JNIEnv *env, jobject object, jstring instanceId, jby } void -jsFunctionCallUpdateAttrs(JNIEnv *env, jobject object, jstring pageId, jstring ref, jstring data) { +jsFunctionCallUpdateAttrs(JNIEnv *env, jobject object, jstring pageId, jstring ref, jbyteArray data, jboolean from) { RenderManager::GetInstance()->UpdateAttr(env->GetStringUTFChars(pageId, 0), env->GetStringUTFChars(ref, 0), - env->GetStringUTFChars(data, 0)); + getCharFromJByte(env, data)); } void -jsFunctionCallUpdateStyle(JNIEnv *env, jobject object, jstring pageId, jstring ref, jstring data) { +jsFunctionCallUpdateStyle(JNIEnv *env, jobject object, jstring pageId, jstring ref, jbyteArray data, jboolean from) { RenderManager::GetInstance()->UpdateStyle(env->GetStringUTFChars(pageId, 0), env->GetStringUTFChars(ref, 0), - env->GetStringUTFChars(data, 0)); + getCharFromJByte(env, data)); } void jsFunctionCallRemoveElement(JNIEnv *env, jobject object, jstring pageId, jstring ref) { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/weex_core/Source/android/bridge/impl/native_render_object_utils_impl_android.cpp ---------------------------------------------------------------------- diff --git a/weex_core/Source/android/bridge/impl/native_render_object_utils_impl_android.cpp b/weex_core/Source/android/bridge/impl/native_render_object_utils_impl_android.cpp index 42b903c..493015b 100644 --- a/weex_core/Source/android/bridge/impl/native_render_object_utils_impl_android.cpp +++ b/weex_core/Source/android/bridge/impl/native_render_object_utils_impl_android.cpp @@ -92,6 +92,11 @@ static jlong CopyRenderObject(JNIEnv* env, jclass jcaller, jlong ptr){ } static void showRenderObjectLayout(RenderObject *renderObject, int level){ + LOGE("RenderObject layout %s %d %p %f %f %f %f ", renderObject->Type().c_str(), + renderObject->getStypePositionType(), + renderObject, renderObject->getLayoutHeight(), renderObject->getLayoutWidth(), + renderObject->getLayoutPositionLeft(), renderObject->getLayoutPositionRight()); + for(auto it = renderObject->ChildListIterBegin(); it != renderObject->ChildListIterEnd(); it++){ RenderObject* child = static_cast<RenderObject*>(*it); showRenderObjectLayout(child, level + 1); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/weex_core/Source/android/jniprebuild/jni_files ---------------------------------------------------------------------- diff --git a/weex_core/Source/android/jniprebuild/jni_files b/weex_core/Source/android/jniprebuild/jni_files index 0fc5493..7b88e9f 100644 --- a/weex_core/Source/android/jniprebuild/jni_files +++ b/weex_core/Source/android/jniprebuild/jni_files @@ -1,6 +1,6 @@ +com/taobao/weex/bridge/WXJsFunctions.java com/taobao/weex/ui/component/list/template/jni/NativeRenderObjectUtils.java com/taobao/weex/base/SystemMessageHandler.java com/taobao/weex/bridge/WXBridge.java com/taobao/weex/layout/MeasureMode.java -com/taobao/weex/layout/ContentBoxMeasurement.java -com/taobao/weex/bridge/WXJsFunctions.java \ No newline at end of file +com/taobao/weex/layout/ContentBoxMeasurement.java \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/50ae70ce/weex_core/Source/android/jniprebuild/jniheader/WXJsFunctions_jni.h ---------------------------------------------------------------------- diff --git a/weex_core/Source/android/jniprebuild/jniheader/WXJsFunctions_jni.h b/weex_core/Source/android/jniprebuild/jniheader/WXJsFunctions_jni.h index 1f7d2c0..a6cad5a 100644 --- a/weex_core/Source/android/jniprebuild/jniheader/WXJsFunctions_jni.h +++ b/weex_core/Source/android/jniprebuild/jniheader/WXJsFunctions_jni.h @@ -34,22 +34,22 @@ static void jsHandleCallNative(JNIEnv *env, jobject object, jstring instanceId, static void jsHandleCallNativeModule(JNIEnv *env, jobject object, jstring instanceId, jstring module, jstring method, jbyteArray - arguments, jbyteArray options); + arguments, jbyteArray options,jboolean from); static void jsHandleCallNativeComponent(JNIEnv *env, jobject object, jstring instanceId, jstring componentRef, jstring method, - jbyteArray arguments, jbyteArray options); + jbyteArray arguments, jbyteArray options, jboolean from); static void -jsHandleCallAddElement(JNIEnv *env, jobject object, jstring instanceId, jstring ref, jstring dom, +jsHandleCallAddElement(JNIEnv *env, jobject object, jstring instanceId, jstring ref, jbyteArray dom, jstring index); static void jsHandleSetTimeout(JNIEnv *env, jobject object, jstring callbackId, jstring time); static void jsHandleCallNativeLog(JNIEnv *env, jobject object, jbyteArray str_array); -static void jsFunctionCallCreateBody(JNIEnv *env, jobject object, jstring pageId, jstring domStr); +static void jsFunctionCallCreateBody(JNIEnv *env, jobject object, jstring pageId, jbyteArray domStr, jboolean from); static void jsFunctionCallUpdateFinish(JNIEnv *env, jobject object, jstring instanceId, jbyteArray tasks, @@ -62,10 +62,10 @@ jsFunctionCallRefreshFinish(JNIEnv *env, jobject object, jstring instanceId, jby jstring callback); static void -jsFunctionCallUpdateAttrs(JNIEnv *env, jobject object, jstring pageId, jstring ref, jstring data); +jsFunctionCallUpdateAttrs(JNIEnv *env, jobject object, jstring pageId, jstring ref, jbyteArray data, jboolean from); static void -jsFunctionCallUpdateStyle(JNIEnv *env, jobject object, jstring pageId, jstring ref, jstring data); +jsFunctionCallUpdateStyle(JNIEnv *env, jobject object, jstring pageId, jstring ref, jbyteArray data, jboolean from); static void jsFunctionCallRemoveElement(JNIEnv *env, jobject object, jstring pageId, jstring ref); @@ -103,13 +103,13 @@ static const JNINativeMethod kMethodsWXJsFunctions[] = { "(Ljava/lang/String;[BLjava/lang/String;)V", reinterpret_cast<void *>(jsHandleCallNative)}, {"jsHandleCallNativeModule", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[B[B)V", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[B[BZ)V", reinterpret_cast<void *>(jsHandleCallNativeModule)}, {"jsHandleCallNativeComponent", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[B[B)V", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[B[BZ)V", reinterpret_cast<void *>(jsHandleCallNativeComponent)}, {"jsHandleCallAddElement", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", + "(Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;Z)V", reinterpret_cast<void *>(jsHandleCallAddElement)}, {"jsHandleSetTimeout", "(Ljava/lang/String;Ljava/lang/String;)V", @@ -118,7 +118,7 @@ static const JNINativeMethod kMethodsWXJsFunctions[] = { "([B)V", reinterpret_cast<void *>(jsHandleCallNativeLog)}, {"jsFunctionCallCreateBody", - "(Ljava/lang/String;Ljava/lang/String;)V", + "(Ljava/lang/String;[BZ)V", reinterpret_cast<void *>(jsFunctionCallCreateBody)}, {"jsFunctionCallUpdateFinish", "(Ljava/lang/String;[BLjava/lang/String;)V", @@ -130,10 +130,10 @@ static const JNINativeMethod kMethodsWXJsFunctions[] = { "(Ljava/lang/String;[BLjava/lang/String;)V", reinterpret_cast<void *>(jsFunctionCallRefreshFinish)}, {"jsFunctionCallUpdateAttrs", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", + "(Ljava/lang/String;Ljava/lang/String;[BZ)V", reinterpret_cast<void *>(jsFunctionCallUpdateAttrs)}, {"jsFunctionCallUpdateStyle", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", + "(Ljava/lang/String;Ljava/lang/String;[BZ)V", reinterpret_cast<void *>(jsFunctionCallUpdateStyle)}, {"jsFunctionCallRemoveElement", "(Ljava/lang/String;Ljava/lang/String;)V",
