From 61296ece8c597793100255e5cbbc465a8a5ead64 Mon Sep 17 00:00:00 2001 From: luciolong Date: Mon, 7 Jan 2019 16:48:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[Android]=20fix=20callGcanvas=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E9=87=8E=E6=8C=87=E9=92=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../android/bridge/script_bridge_in_multi_process.cpp | 9 +++++---- .../android/jsengine/object/weex_global_object.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/weex_core/Source/android/bridge/script_bridge_in_multi_process.cpp b/weex_core/Source/android/bridge/script_bridge_in_multi_process.cpp index 29deee1527..c5bea35a52 100644 --- a/weex_core/Source/android/bridge/script_bridge_in_multi_process.cpp +++ b/weex_core/Source/android/bridge/script_bridge_in_multi_process.cpp @@ -267,14 +267,15 @@ static std::unique_ptr HandleCallGCanvasLinkNative( // retVal = WeexCoreManager::Instance()->script_bridge()->core_side()->CallGCanvasLinkNative(pageId, type, // args); - std::unique_ptr ret = createVoidResult(); - if (retVal) { + std::unique_ptr ret = createVoidResult(); + if (retVal) { jstring jDataStr = env->NewStringUTF(retVal); ret = std::unique_ptr( - new IPCStringResult(jstring2WeexString(env, jDataStr))); + new IPCStringResult(jstring2WeexString(env, jDataStr))); env->DeleteLocalRef(jDataStr); + delete retVal; retVal = NULL; - } + } // env->DeleteLocalRef(jPageId); // env->DeleteLocalRef(val); return ret; diff --git a/weex_core/Source/android/jsengine/object/weex_global_object.cpp b/weex_core/Source/android/jsengine/object/weex_global_object.cpp index 33952b05d8..0fc314782b 100644 --- a/weex_core/Source/android/jsengine/object/weex_global_object.cpp +++ b/weex_core/Source/android/jsengine/object/weex_global_object.cpp @@ -369,9 +369,12 @@ JSFUNCTION functionGCanvasLinkNative(ExecState *state) { JSValue arg_js = state->argument(2); String arg_str = arg_js.toWTFString(state); - auto result = globalObject->js_bridge()->core_side()->CallGCanvasLinkNative(id_str.utf8().data(), + const char * resultChar = globalObject->js_bridge()->core_side()->CallGCanvasLinkNative(id_str.utf8().data(), type, arg_str.utf8().data()); - return JSValue::encode(String2JSValue(state, result)); + auto result = resultChar; + auto ret = JSValue::encode(String2JSValue(state, result)); + delete resultChar; + return ret; } JSFUNCTION functionT3DLinkNative(ExecState *state) { From 69b112fee967b097808cbbee8ba0d9f4847a588f Mon Sep 17 00:00:00 2001 From: luciolong Date: Tue, 8 Jan 2019 10:12:12 +0800 Subject: [PATCH 2/2] [Android]fix GcanvasLinkNative result empty char cause error --- .../bridge/script_bridge_in_multi_process.cpp | 12 +++++++----- .../android/jsengine/object/weex_global_object.cpp | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/weex_core/Source/android/bridge/script_bridge_in_multi_process.cpp b/weex_core/Source/android/bridge/script_bridge_in_multi_process.cpp index c5bea35a52..8c2711c2c6 100644 --- a/weex_core/Source/android/bridge/script_bridge_in_multi_process.cpp +++ b/weex_core/Source/android/bridge/script_bridge_in_multi_process.cpp @@ -269,11 +269,13 @@ static std::unique_ptr HandleCallGCanvasLinkNative( std::unique_ptr ret = createVoidResult(); if (retVal) { - jstring jDataStr = env->NewStringUTF(retVal); - ret = std::unique_ptr( - new IPCStringResult(jstring2WeexString(env, jDataStr))); - env->DeleteLocalRef(jDataStr); - delete retVal; + jstring jDataStr = env->NewStringUTF(retVal); + ret = std::unique_ptr( + new IPCStringResult(jstring2WeexString(env, jDataStr))); + env->DeleteLocalRef(jDataStr); + if (strlen(retVal) > 0) { + delete retVal; + } retVal = NULL; } // env->DeleteLocalRef(jPageId); diff --git a/weex_core/Source/android/jsengine/object/weex_global_object.cpp b/weex_core/Source/android/jsengine/object/weex_global_object.cpp index 0fc314782b..0d87c04ee6 100644 --- a/weex_core/Source/android/jsengine/object/weex_global_object.cpp +++ b/weex_core/Source/android/jsengine/object/weex_global_object.cpp @@ -373,7 +373,9 @@ JSFUNCTION functionGCanvasLinkNative(ExecState *state) { type, arg_str.utf8().data()); auto result = resultChar; auto ret = JSValue::encode(String2JSValue(state, result)); - delete resultChar; + if (strlen(resultChar) > 0) { + delete resultChar; + } return ret; }