diff --git a/js/builtin/deviceinfokit/src/nativeapi_deviceinfo.cpp b/js/builtin/deviceinfokit/src/nativeapi_deviceinfo.cpp index 0f809c618e3ed8416230cebaff3132846e92dfb1..111def780c402ee48b02d9bfc959472cc0f3f4fe 100755 --- a/js/builtin/deviceinfokit/src/nativeapi_deviceinfo.cpp +++ b/js/builtin/deviceinfokit/src/nativeapi_deviceinfo.cpp @@ -14,6 +14,7 @@ */ #include "nativeapi_deviceinfo.h" +#include #include "js_async_work.h" #include "nativeapi_common.h" #include "nativeapi_config.h" @@ -43,36 +44,28 @@ JSIValue ExecuteAsyncWork(const JSIValue thisVal, const JSIValue* args, void ExecuteGetInfo(void* data) { - FuncParams* params = reinterpret_cast(data); - if (params == nullptr) { + if (data == nullptr) { return; } + + FuncParams* params = reinterpret_cast(data); JSIValue args = params->args; JSIValue thisVal = params->thisVal; - char* brand = GetBrand(); + bool getFailed = true; + char* brand = GetBrand(); if (brand == nullptr) { - NativeapiCommon::FailCallBack(args, thisVal, ERROR_CODE_GENERAL); - JSI::ReleaseValueList(args, thisVal, ARGS_END); - delete params; - return; + goto GET_BRAND_FAILED; } char* manufacture = GetManufacture(); if (manufacture == nullptr) { - free(brand); - NativeapiCommon::FailCallBack(args, thisVal, ERROR_CODE_GENERAL); - JSI::ReleaseValueList(args, thisVal, ARGS_END); - delete params; - return; + goto GET_MANUFACTURE_FAILED; } char* model = GetProductModel(); if (model == nullptr) { - free(brand); - free(manufacture); - NativeapiCommon::FailCallBack(args, thisVal, ERROR_CODE_GENERAL); - JSI::ReleaseValueList(args, thisVal, ARGS_END); - delete params; - return; + goto GET_PRODUCT_MODLE_FAILED; } + getFailed = false; + JSIValue result = JSI::CreateObject(); JSI::SetStringProperty(result, "brand", brand); JSI::SetStringProperty(result, "manufacturer", manufacture); @@ -81,14 +74,21 @@ void ExecuteGetInfo(void* data) Screen &screen = Screen::GetInstance(); JSI::SetNumberProperty(result, "windowWidth", (double)screen.GetWidth()); JSI::SetNumberProperty(result, "windowHeight", (double)screen.GetHeight()); - free(brand); - free(manufacture); + free(model); - NativeapiCommon::SuccessCallBack(thisVal, args, result); - JSI::ReleaseValueList(args, thisVal, result, ARGS_END); +GET_PRODUCT_MODLE_FAILED: + free(manufacture); +GET_MANUFACTURE_FAILED: + free(brand); +GET_BRAND_FAILED: + if (getFailed) { + NativeapiCommon::FailCallBack(args, thisVal, ERROR_CODE_GENERAL); + JSI::ReleaseValueList(args, thisVal, ARGS_END); + } else { + NativeapiCommon::SuccessCallBack(thisVal, args, result); + JSI::ReleaseValueList(args, thisVal, result, ARGS_END); + } delete params; - params = nullptr; -} } void InitDeviceModule(JSIValue exports)