IssueNo:#I61B3L

Description:Fix issue in js_runtime.cpp and js_data_struct_converter.cpp
Sig:SIG_ApplicationFramework
Feature or BugFix: Feature
Binary Source: No

Signed-off-by: zhangyafei.echo <zhangyafei12@huawei.com>
Change-Id: I6590ec186d29e7366027811bc486ffe275256f90
This commit is contained in:
zhangyafei.echo
2022-11-15 17:15:02 +08:00
parent 050e51ba9b
commit bb50f3cd70
5 changed files with 59 additions and 7 deletions
+4 -2
View File
@@ -18,7 +18,8 @@
#include <string>
namespace OHOS::AbilityRuntime {
namespace OHOS {
namespace AbilityRuntime {
class HdcRegister final {
public:
static HdcRegister& Get();
@@ -37,6 +38,7 @@ private:
HdcRegister& operator=(const HdcRegister&) = delete;
HdcRegister& operator=(HdcRegister&&) = delete;
};
} // namespace OHOS::AbilityRuntime
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_HDC_REGISTER_H
@@ -23,6 +23,7 @@
namespace OHOS {
namespace AbilityRuntime {
namespace {
constexpr uint32_t JS_CONSOLE_LOG_MAX_LOG_LEN = 1024;
constexpr uint32_t JS_CONSOLE_LOG_DOMAIN = 0xFEFE;
constexpr char JS_CONSOLE_LOG_TAG[] = "JsApp";
@@ -43,6 +44,11 @@ std::string MakeLogContent(NativeCallbackInfo& info)
}
size_t bufferLen = str->GetLength();
if (bufferLen >= JS_CONSOLE_LOG_MAX_LOG_LEN) {
HILOG_ERROR("Log length exceeds maximum");
return content;
}
auto buff = new (std::nothrow) char[bufferLen + 1];
if (buff == nullptr) {
HILOG_ERROR("Failed to allocate buffer, size = %zu", bufferLen + 1);
@@ -27,6 +27,10 @@ NativeValue* CreateJsWantObject(NativeEngine& engine, const AAFwk::Want& want)
{
NativeValue* objValue = engine.CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
HILOG_ERROR("Native object is nullptr.");
return objValue;
}
object->SetProperty("deviceId", CreateJsValue(engine, want.GetOperation().GetDeviceId()));
object->SetProperty("bundleName", CreateJsValue(engine, want.GetBundle()));
@@ -43,6 +47,10 @@ NativeValue* CreateJsAbilityInfo(NativeEngine& engine, const AppExecFwk::Ability
{
NativeValue* objValue = engine.CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
HILOG_ERROR("Native object is nullptr.");
return objValue;
}
object->SetProperty("bundleName", CreateJsValue(engine, abilityInfo.bundleName));
object->SetProperty("name", CreateJsValue(engine, abilityInfo.name));
@@ -89,6 +97,11 @@ NativeValue* CreateJsMetadataArray(NativeEngine& engine, const std::vector<AppEx
{
NativeValue* arrayValue = engine.CreateArray(info.size());
NativeArray* array = ConvertNativeValueTo<NativeArray>(arrayValue);
if (array == nullptr) {
HILOG_ERROR("Native object is nullptr.");
return arrayValue;
}
uint32_t index = 0;
for (const auto& item : info) {
array->SetElement(index++, CreateJsMetadata(engine, item));
@@ -100,6 +113,10 @@ NativeValue* CreateJsMetadata(NativeEngine& engine, const AppExecFwk::Metadata &
{
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
HILOG_ERROR("Native object is nullptr.");
return objValue;
}
object->SetProperty("name", CreateJsValue(engine, info.name));
object->SetProperty("value", CreateJsValue(engine, info.value));
@@ -111,6 +128,10 @@ NativeValue* CreateJsCustomizeData(NativeEngine& engine, const AppExecFwk::Custo
{
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
HILOG_ERROR("Native object is nullptr.");
return objValue;
}
object->SetProperty("name", CreateJsValue(engine, info.name));
object->SetProperty("value", CreateJsValue(engine, info.value));
@@ -122,6 +143,11 @@ NativeValue* CreateJsCustomizeDataArray(NativeEngine& engine, const std::vector<
{
NativeValue* arrayValue = engine.CreateArray(info.size());
NativeArray* array = ConvertNativeValueTo<NativeArray>(arrayValue);
if (array == nullptr) {
HILOG_ERROR("Native object is nullptr.");
return arrayValue;
}
uint32_t index = 0;
for (const auto& item : info) {
array->SetElement(index++, CreateJsCustomizeData(engine, item));
@@ -133,6 +159,10 @@ NativeValue* CreateJsModuleInfo(NativeEngine& engine, const AppExecFwk::ModuleIn
{
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
HILOG_ERROR("Native object is nullptr.");
return objValue;
}
object->SetProperty("moduleName", CreateJsValue(engine, moduleInfo.moduleName));
object->SetProperty("moduleSourceDir", CreateJsValue(engine, moduleInfo.moduleSourceDir));
@@ -144,6 +174,10 @@ NativeValue* CreateJsApplicationInfo(NativeEngine& engine, const AppExecFwk::App
{
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
HILOG_ERROR("Native object is nullptr.");
return objValue;
}
object->SetProperty("name", CreateJsValue(engine, applicationInfo.name));
object->SetProperty("description", CreateJsValue(engine, applicationInfo.description));
@@ -188,6 +222,10 @@ NativeValue* CreateJsLaunchParam(NativeEngine& engine, const AAFwk::LaunchParam&
{
NativeValue *objValue = engine.CreateObject();
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
HILOG_ERROR("Native object is nullptr.");
return objValue;
}
object->SetProperty("launchReason", CreateJsValue(engine, launchParam.launchReason));
object->SetProperty("lastExitReason", CreateJsValue(engine, launchParam.lastExitReason));
@@ -199,6 +237,10 @@ NativeValue* CreateJsConfiguration(NativeEngine& engine, const AppExecFwk::Confi
{
NativeValue* objValue = engine.CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
HILOG_ERROR("Native object is nullptr.");
return objValue;
}
object->SetProperty("language", CreateJsValue(engine,
configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE)));
@@ -229,6 +271,7 @@ NativeValue* CreateJsExtensionAbilityInfo(NativeEngine& engine, const AppExecFwk
if (object == nullptr) {
return objValue;
}
object->SetProperty("bundleName", CreateJsValue(engine, info.bundleName));
object->SetProperty("moduleName", CreateJsValue(engine, info.moduleName));
object->SetProperty("name", CreateJsValue(engine, info.name));
@@ -240,7 +283,7 @@ NativeValue* CreateJsExtensionAbilityInfo(NativeEngine& engine, const AppExecFwk
NativeValue *permissionArrayValue = engine.CreateArray(info.permissions.size());
NativeArray *permissionArray = ConvertNativeValueTo<NativeArray>(permissionArrayValue);
if (permissionArray != nullptr) {
int index = 0;
uint32_t index = 0;
for (auto permission : info.permissions) {
permissionArray->SetElement(index++, CreateJsValue(engine, permission));
}
+1 -1
View File
@@ -22,7 +22,7 @@ namespace OHOS {
namespace AbilityRuntime {
namespace {
constexpr const char* ERR_MSG_TOO_FEW_PARAM = "Parameter error. Too few parameters.";
}
} // namespace
void ThrowError(NativeEngine& engine, int32_t errCode, const std::string& errorMsg)
{
+4 -3
View File
@@ -15,13 +15,14 @@
#include "js_runtime.h"
#include <atomic>
#include <cerrno>
#include <climits>
#include <cstdlib>
#include <regex>
#include <atomic>
#include <sys/epoll.h>
#include <unistd.h>
#include <regex>
#include "ability_constants.h"
#include "connect_server_manager.h"
@@ -88,7 +89,7 @@ public:
void StartDebugMode(bool needBreakPoint) override
{
if (vm_ == nullptr) {
HILOG_ERROR("virtual machine does not exist");
HILOG_ERROR("Virtual machine does not exist");
return;
}