mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-21 01:45:30 -04:00
!1992 Add support for Previewer running on Ark engine
Merge pull request !1992 from Pan Zhenyu/master
This commit is contained in:
@@ -76,145 +76,6 @@ bool UnwrapRawImageDataMap(NativeEngine* engine, NativeValue* argv, std::map<std
|
||||
return true;
|
||||
}
|
||||
|
||||
int PrintLog(int id, int level, const char* tag, const char* fmt, const char* message)
|
||||
{
|
||||
switch (JsLogLevel(level - 3)) {
|
||||
case JsLogLevel::INFO:
|
||||
LOGI("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
LOGW("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
LOGE("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
case JsLogLevel::DEBUG:
|
||||
LOGD("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
default:
|
||||
LOGF("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string ParseLogContent(const std::vector<std::string>& params)
|
||||
{
|
||||
std::string ret;
|
||||
if (params.empty()) {
|
||||
return ret;
|
||||
}
|
||||
std::string formatStr = params[0];
|
||||
uint32_t size = params.size();
|
||||
uint32_t len = formatStr.size();
|
||||
uint32_t pos = 0;
|
||||
uint32_t count = 1;
|
||||
for (; pos < len; ++pos) {
|
||||
if (count >= size) {
|
||||
break;
|
||||
}
|
||||
if (formatStr[pos] == '%') {
|
||||
if (pos + 1 >= len) {
|
||||
break;
|
||||
}
|
||||
switch (formatStr[pos + 1]) {
|
||||
case 's':
|
||||
case 'j':
|
||||
case 'd':
|
||||
case 'O':
|
||||
case 'o':
|
||||
case 'i':
|
||||
case 'f':
|
||||
case 'c':
|
||||
ret += params[count++];
|
||||
++pos;
|
||||
break;
|
||||
case '%':
|
||||
ret += formatStr[pos];
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
ret += formatStr[pos];
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ret += formatStr[pos];
|
||||
}
|
||||
}
|
||||
if (pos < len) {
|
||||
ret += formatStr.substr(pos, len - pos);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string GetLogContent(
|
||||
const shared_ptr<JsRuntime>& runtime, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
if (argc == 1) {
|
||||
return argv[0]->ToString(runtime);
|
||||
}
|
||||
std::vector<std::string> params;
|
||||
for (int32_t i = 0; i < argc; ++i) {
|
||||
params.emplace_back(argv[i]->ToString(runtime));
|
||||
}
|
||||
return ParseLogContent(params);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> AppLogPrint(
|
||||
const shared_ptr<JsRuntime>& runtime, JsLogLevel level, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
// Should have at least 1 parameters.
|
||||
if (argc == 0) {
|
||||
LOGE("the arg is error");
|
||||
return runtime->NewUndefined();
|
||||
}
|
||||
std::string content = GetLogContent(runtime, argv, argc);
|
||||
switch (level) {
|
||||
case JsLogLevel::DEBUG:
|
||||
APP_LOGD("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::INFO:
|
||||
APP_LOGI("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
APP_LOGW("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
APP_LOGE("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
return runtime->NewUndefined();
|
||||
}
|
||||
|
||||
// native implementation for js function: console.debug()
|
||||
shared_ptr<JsValue> AppDebugLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::DEBUG, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: console.info()
|
||||
shared_ptr<JsValue> AppInfoLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::INFO, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: console.warn()
|
||||
shared_ptr<JsValue> AppWarnLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::WARNING, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: console.error()
|
||||
shared_ptr<JsValue> AppErrorLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::ERROR, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: Particle.onCreateFinish()
|
||||
shared_ptr<JsValue> JsOnCreateFinish(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
@@ -337,79 +198,14 @@ void JsiPaEngineInstance::RegisterConsoleModule()
|
||||
|
||||
// app log method
|
||||
shared_ptr<JsValue> consoleObj = runtime_->NewObject();
|
||||
consoleObj->SetProperty(runtime_, "log", runtime_->NewFunction(AppDebugLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "debug", runtime_->NewFunction(AppDebugLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "info", runtime_->NewFunction(AppInfoLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "warn", runtime_->NewFunction(AppWarnLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "error", runtime_->NewFunction(AppErrorLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "log", runtime_->NewFunction(JsiBaseUtils::AppDebugLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "debug", runtime_->NewFunction(JsiBaseUtils::AppDebugLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "info", runtime_->NewFunction(JsiBaseUtils::AppInfoLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "warn", runtime_->NewFunction(JsiBaseUtils::AppWarnLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "error", runtime_->NewFunction(JsiBaseUtils::AppErrorLogPrint));
|
||||
global->SetProperty(runtime_, "console", consoleObj);
|
||||
}
|
||||
|
||||
std::string GetLogContent(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
std::string content;
|
||||
for (size_t i = 0; i < info->argc; ++i) {
|
||||
if (info->argv[i]->TypeOf() != NATIVE_STRING) {
|
||||
LOGE("argv is not NativeString");
|
||||
continue;
|
||||
}
|
||||
auto nativeString = reinterpret_cast<NativeString*>(info->argv[i]->GetInterface(NativeString::INTERFACE_ID));
|
||||
size_t bufferSize = nativeString->GetLength();
|
||||
size_t strLength = 0;
|
||||
char* buffer = new char[bufferSize + 1] { 0 };
|
||||
nativeString->GetCString(buffer, bufferSize + 1, &strLength);
|
||||
content.append(buffer);
|
||||
delete[] buffer;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
NativeValue* AppLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info, JsLogLevel level)
|
||||
{
|
||||
// Should have at least 1 parameters.
|
||||
if (info->argc == 0) {
|
||||
LOGE("the arg is error");
|
||||
return nativeEngine->CreateUndefined();
|
||||
}
|
||||
std::string content = GetLogContent(nativeEngine, info);
|
||||
switch (level) {
|
||||
case JsLogLevel::DEBUG:
|
||||
APP_LOGD("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::INFO:
|
||||
APP_LOGI("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
APP_LOGW("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
APP_LOGE("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
return nativeEngine->CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* AppDebugLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::DEBUG);
|
||||
}
|
||||
|
||||
NativeValue* AppInfoLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::INFO);
|
||||
}
|
||||
|
||||
NativeValue* AppWarnLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::WARNING);
|
||||
}
|
||||
|
||||
NativeValue* AppErrorLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::ERROR);
|
||||
}
|
||||
|
||||
void JsiPaEngineInstance::RegisterConsoleModule(ArkNativeEngine* engine)
|
||||
{
|
||||
ACE_SCOPED_TRACE("JsiEngineInstance::RegisterConsoleModule");
|
||||
@@ -617,7 +413,9 @@ JsiPaEngine::~JsiPaEngine()
|
||||
UnloadLibrary();
|
||||
engineInstance_->GetDelegate()->RemoveTaskObserver();
|
||||
if (nativeEngine_ != nullptr) {
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
|
||||
nativeEngine_->CancelCheckUVLoop();
|
||||
#endif
|
||||
delete nativeEngine_;
|
||||
}
|
||||
}
|
||||
@@ -716,7 +514,9 @@ bool JsiPaEngine::Initialize(const RefPtr<BackendDelegate>& delegate)
|
||||
});
|
||||
JsBackendTimerModule::GetInstance()->InitTimerModule(nativeEngine_, delegate);
|
||||
SetPostTask(nativeEngine_);
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
|
||||
nativeEngine_->CheckUVLoop();
|
||||
#endif
|
||||
if (delegate && delegate->GetAssetManager()) {
|
||||
std::string packagePath = delegate->GetAssetManager()->GetLibPath();
|
||||
if (!packagePath.empty()) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/jsi_base_utils.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
int32_t GetLineOffset()
|
||||
int32_t GetLineOffset(const AceType *data)
|
||||
{
|
||||
const int32_t offset = 14;
|
||||
return offset;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed 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.
|
||||
|
||||
declare_args() {
|
||||
# Enable Ark as Previewer JS engine, set it 'false' to use QuickJS instead
|
||||
enable_ark_preview = false
|
||||
}
|
||||
@@ -11,28 +11,45 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("config_js_engine.gni")
|
||||
|
||||
# js engine common configs
|
||||
js_engines = []
|
||||
js_pa_support = false
|
||||
use_build_in_js_engine = true
|
||||
|
||||
if (enable_ark_preview) {
|
||||
ark_engine = {
|
||||
engine_name = "ark"
|
||||
engine_path = "jsi"
|
||||
engine_defines = [ "USE_ARK_ENGINE" ]
|
||||
}
|
||||
js_engines += [ ark_engine ]
|
||||
build_for_preview = true
|
||||
xcomponent_components_support = true
|
||||
use_external_icu = "shared"
|
||||
} else {
|
||||
qjs_engine = {
|
||||
engine_name = "qjs"
|
||||
engine_path = "quickjs"
|
||||
engine_defines = [ "USE_QUICKJS_ENGINE" ]
|
||||
}
|
||||
js_engines += [ qjs_engine ]
|
||||
xcomponent_components_support = false
|
||||
}
|
||||
|
||||
# windows platform defines and configs
|
||||
defines = [
|
||||
"MAC_PLATFORM",
|
||||
"UNICODE",
|
||||
"SK_BUILD_FONT_MGR_FOR_PREVIEW_MAC",
|
||||
]
|
||||
|
||||
js_engines = []
|
||||
qjs_engine = {
|
||||
engine_name = "qjs"
|
||||
engine_path = "quickjs"
|
||||
engine_defines = [ "USE_QUICKJS_ENGINE" ]
|
||||
}
|
||||
js_engines += [ qjs_engine ]
|
||||
use_build_in_js_engine = true
|
||||
use_curl_download = true
|
||||
accessibility_support = true
|
||||
rich_components_support = true
|
||||
advance_components_support = false
|
||||
form_components_support = true
|
||||
xcomponent_components_support = false
|
||||
plugin_components_support = false
|
||||
js_pa_support = false
|
||||
connect_server_support = false
|
||||
enable_rosen_backend = false
|
||||
enable_standard_input = false
|
||||
|
||||
@@ -11,6 +11,34 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("config_js_engine.gni")
|
||||
|
||||
# js engine common configs
|
||||
js_engines = []
|
||||
js_pa_support = false
|
||||
use_build_in_js_engine = true
|
||||
|
||||
if (enable_ark_preview) {
|
||||
ark_engine = {
|
||||
engine_name = "ark"
|
||||
engine_path = "jsi"
|
||||
engine_defines = [ "USE_ARK_ENGINE" ]
|
||||
}
|
||||
js_engines += [ ark_engine ]
|
||||
build_for_preview = true
|
||||
xcomponent_components_support = true
|
||||
use_external_icu = "shared"
|
||||
} else {
|
||||
qjs_engine = {
|
||||
engine_name = "qjs"
|
||||
engine_path = "quickjs"
|
||||
engine_defines = [ "USE_QUICKJS_ENGINE" ]
|
||||
}
|
||||
js_engines += [ qjs_engine ]
|
||||
xcomponent_components_support = false
|
||||
}
|
||||
|
||||
# windows platform defines and configs
|
||||
defines = [
|
||||
"WINDOWS_PLATFORM",
|
||||
"_USE_MATH_DEFINES",
|
||||
@@ -20,23 +48,12 @@ defines = [
|
||||
"SK_BUILD_FOR_WIN",
|
||||
"SK_BUILD_FONT_MGR_FOR_PREVIEW_WIN",
|
||||
]
|
||||
|
||||
js_engines = []
|
||||
qjs_engine = {
|
||||
engine_name = "qjs"
|
||||
engine_path = "quickjs"
|
||||
engine_defines = [ "USE_QUICKJS_ENGINE" ]
|
||||
}
|
||||
js_engines += [ qjs_engine ]
|
||||
use_build_in_js_engine = true
|
||||
use_curl_download = true
|
||||
accessibility_support = true
|
||||
rich_components_support = true
|
||||
advance_components_support = false
|
||||
form_components_support = true
|
||||
plugin_components_support = false
|
||||
xcomponent_components_support = false
|
||||
js_pa_support = false
|
||||
connect_server_support = false
|
||||
enable_rosen_backend = false
|
||||
enable_standard_input = false
|
||||
|
||||
@@ -827,11 +827,16 @@ void AceContainer::LoadDocument(const std::string& url, const std::string& compo
|
||||
LOGE("frontend is null, AceContainer::LoadDocument failed");
|
||||
return;
|
||||
}
|
||||
auto jsEngine = frontend->GetJsEngine();
|
||||
if (!jsEngine) {
|
||||
LOGE("jsEngine is null, AceContainer::LoadDocument failed");
|
||||
return;
|
||||
}
|
||||
std::string dstUrl = url + COMPONENT_PREVIEW + componentName;
|
||||
taskExecutor_->PostTask(
|
||||
[front = frontend, componentName, dstUrl]() {
|
||||
[front = frontend, componentName, dstUrl, jsEngine]() {
|
||||
front->SetPagePath(dstUrl);
|
||||
front->ReplaceJSContent(dstUrl, componentName);
|
||||
jsEngine->ReplaceJSContent(dstUrl, componentName);
|
||||
},
|
||||
TaskExecutor::TaskType::JS);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/ace/ace_engine/ace_config.gni")
|
||||
import("//foundation/ace/ace_engine/adapter/preview/build/config_js_engine.gni")
|
||||
|
||||
config("ace_pc_preview_config") {
|
||||
cflags_cc = [
|
||||
@@ -39,12 +40,19 @@ template("ace_test") {
|
||||
|
||||
deps = [
|
||||
":copy_napi_modules_shared_library_for_test(${current_toolchain})",
|
||||
":copy_napi_shared_library_for_test(${current_toolchain})",
|
||||
":copy_resource_dynamic_library(${current_toolchain})",
|
||||
"$ace_napi:ace_napi(${current_toolchain})",
|
||||
"$ace_napi/sample/native_module_demo:demo(${current_toolchain})",
|
||||
"$ace_root/adapter/preview/build:libace_engine_$platform(${current_toolchain})",
|
||||
]
|
||||
if (enable_ark_preview) {
|
||||
deps += [
|
||||
":copy_ark_shared_library(${current_toolchain})",
|
||||
":copy_napi_shared_library(${current_toolchain})",
|
||||
]
|
||||
} else {
|
||||
deps += [ ":copy_napi_shared_library_for_test(${current_toolchain})" ]
|
||||
}
|
||||
if (platform == "windows") {
|
||||
libs = [ "pthread" ]
|
||||
}
|
||||
@@ -84,64 +92,73 @@ foreach(item, ace_platforms) {
|
||||
}
|
||||
}
|
||||
|
||||
ohos_copy("copy_resource_dynamic_library") {
|
||||
if (use_mac) {
|
||||
if (is_standard_system) {
|
||||
resource_manager_library = get_label_info(
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_mac",
|
||||
"root_out_dir") + "/global/resmgr_standard/libglobal_resmgr_mac.dylib"
|
||||
deps = [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_mac(${current_toolchain})" ]
|
||||
sources = [ resource_manager_library ]
|
||||
} else {
|
||||
sources = [
|
||||
"//prebuilts/ace-toolkit/preview/rich/lib/mac/tv/libhmicuuc.dylib",
|
||||
"//prebuilts/ace-toolkit/preview/rich/lib/mac/tv/libresourcemanager_mac.dylib",
|
||||
]
|
||||
}
|
||||
outputs =
|
||||
[ root_build_dir + "/clang_x64/common/common/{{source_file_part}}" ]
|
||||
} else {
|
||||
if (is_standard_system) {
|
||||
resource_manager_library = get_label_info(
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_win",
|
||||
"root_out_dir") + "/global/resmgr_standard/libglobal_resmgr_win.dll"
|
||||
deps = [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_win(${current_toolchain})" ]
|
||||
sources = [ resource_manager_library ]
|
||||
} else {
|
||||
sources = [
|
||||
"//prebuilts/ace-toolkit/preview/rich/lib/windows/tv/libhmicuuc.dll",
|
||||
"//prebuilts/ace-toolkit/preview/rich/lib/windows/tv/libresourcemanager_win.dll",
|
||||
]
|
||||
}
|
||||
if (enable_ark_preview) {
|
||||
ohos_copy("copy_ark_shared_library") {
|
||||
sources = []
|
||||
deps = []
|
||||
ark_core_shared_library =
|
||||
get_label_info("//ark/runtime_core/libpandabase:libarkbase",
|
||||
"root_out_dir") + "/ark/ark"
|
||||
sources += [
|
||||
"$ark_core_shared_library/libarkbase.dll",
|
||||
"$ark_core_shared_library/libarkfile.dll",
|
||||
"$ark_core_shared_library/libarkziparchive.dll",
|
||||
]
|
||||
deps += [
|
||||
"//ark/runtime_core/libpandabase:libarkbase(${current_toolchain})",
|
||||
"//ark/runtime_core/libpandafile:libarkfile(${current_toolchain})",
|
||||
"//ark/runtime_core/libziparchive:libarkziparchive(${current_toolchain})",
|
||||
]
|
||||
ark_js_shared_library =
|
||||
get_label_info("//ark/js_runtime:libark_jsruntime", "root_out_dir") +
|
||||
"/ark/ark_js_runtime"
|
||||
sources += [ "$ark_js_shared_library/libark_jsruntime.dll" ]
|
||||
deps += [ "//ark/js_runtime:libark_jsruntime" ]
|
||||
outputs =
|
||||
[ root_build_dir + "/mingw_x86_64/common/common/{{source_file_part}}" ]
|
||||
}
|
||||
}
|
||||
|
||||
ohos_copy("copy_napi_shared_library_for_test") {
|
||||
shared_library_path =
|
||||
get_label_info("$ace_napi:ace_napi(${current_toolchain})", "root_out_dir")
|
||||
deps = [
|
||||
"$ace_napi:ace_napi(${current_toolchain})",
|
||||
"$ace_napi:ace_napi_quickjs(${current_toolchain})",
|
||||
]
|
||||
if (use_mac) {
|
||||
sources = [
|
||||
"$shared_library_path/ace/napi/libace_napi.dylib",
|
||||
"$shared_library_path/ace/napi/libace_napi_quickjs.dylib",
|
||||
"$shared_library_path/ace/napi/libuv.dylib",
|
||||
]
|
||||
outputs =
|
||||
[ root_build_dir + "/clang_x64/common/common/{{source_file_part}}" ]
|
||||
} else {
|
||||
ohos_copy("copy_napi_shared_library") {
|
||||
shared_library_path =
|
||||
get_label_info("$ace_napi:ace_napi(${current_toolchain})",
|
||||
"root_out_dir")
|
||||
sources = [
|
||||
"$shared_library_path/ace/napi/libace_napi.dll",
|
||||
"$shared_library_path/ace/napi/libace_napi_quickjs.dll",
|
||||
"$shared_library_path/ace/napi/libuv.dll",
|
||||
"$shared_library_path/ace/napi/libace_napi_ark.dll",
|
||||
]
|
||||
deps = [
|
||||
"$ace_napi:ace_napi(${current_toolchain})",
|
||||
"$ace_napi:ace_napi_ark(${current_toolchain})",
|
||||
]
|
||||
outputs =
|
||||
[ root_build_dir + "/mingw_x86_64/common/common/{{source_file_part}}" ]
|
||||
}
|
||||
} else {
|
||||
ohos_copy("copy_napi_shared_library_for_test") {
|
||||
shared_library_path =
|
||||
get_label_info("$ace_napi:ace_napi(${current_toolchain})",
|
||||
"root_out_dir")
|
||||
deps = [
|
||||
"$ace_napi:ace_napi(${current_toolchain})",
|
||||
"$ace_napi:ace_napi_quickjs(${current_toolchain})",
|
||||
]
|
||||
if (use_mac) {
|
||||
sources = [
|
||||
"$shared_library_path/ace/napi/libace_napi.dylib",
|
||||
"$shared_library_path/ace/napi/libace_napi_quickjs.dylib",
|
||||
"$shared_library_path/ace/napi/libuv.dylib",
|
||||
]
|
||||
outputs =
|
||||
[ root_build_dir + "/clang_x64/common/common/{{source_file_part}}" ]
|
||||
} else {
|
||||
sources = [
|
||||
"$shared_library_path/ace/napi/libace_napi.dll",
|
||||
"$shared_library_path/ace/napi/libace_napi_quickjs.dll",
|
||||
"$shared_library_path/ace/napi/libuv.dll",
|
||||
]
|
||||
outputs = [ root_build_dir +
|
||||
"/mingw_x86_64/common/common/{{source_file_part}}" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ohos_copy("copy_napi_modules_shared_library_for_test") {
|
||||
@@ -191,3 +208,37 @@ ohos_copy("copy_napi_modules_shared_library_for_test") {
|
||||
"/mingw_x86_64/common/common/module/{{source_file_part}}" ]
|
||||
}
|
||||
}
|
||||
|
||||
ohos_copy("copy_resource_dynamic_library") {
|
||||
if (use_mac) {
|
||||
if (is_standard_system) {
|
||||
resource_manager_library = get_label_info(
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_mac",
|
||||
"root_out_dir") + "/global/resmgr_standard/libglobal_resmgr_mac.dylib"
|
||||
deps = [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_mac(${current_toolchain})" ]
|
||||
sources = [ resource_manager_library ]
|
||||
} else {
|
||||
sources = [
|
||||
"//prebuilts/ace-toolkit/preview/rich/lib/mac/tv/libhmicuuc.dylib",
|
||||
"//prebuilts/ace-toolkit/preview/rich/lib/mac/tv/libresourcemanager_mac.dylib",
|
||||
]
|
||||
}
|
||||
outputs =
|
||||
[ root_build_dir + "/clang_x64/common/common/{{source_file_part}}" ]
|
||||
} else {
|
||||
if (is_standard_system) {
|
||||
resource_manager_library = get_label_info(
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_win",
|
||||
"root_out_dir") + "/global/resmgr_standard/libglobal_resmgr_win.dll"
|
||||
deps = [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr_win(${current_toolchain})" ]
|
||||
sources = [ resource_manager_library ]
|
||||
} else {
|
||||
sources = [
|
||||
"//prebuilts/ace-toolkit/preview/rich/lib/windows/tv/libhmicuuc.dll",
|
||||
"//prebuilts/ace-toolkit/preview/rich/lib/windows/tv/libresourcemanager_win.dll",
|
||||
]
|
||||
}
|
||||
outputs =
|
||||
[ root_build_dir + "/mingw_x86_64/common/common/{{source_file_part}}" ]
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -29,7 +29,7 @@ template("libace_static") {
|
||||
deps += config.platform_deps
|
||||
}
|
||||
|
||||
# only qjs support build-in
|
||||
# build-in qjs engine
|
||||
if (defined(config.use_build_in_js_engine) &&
|
||||
config.use_build_in_js_engine && defined(config.qjs_engine)) {
|
||||
if (defined(use_js_debug) && use_js_debug) {
|
||||
@@ -47,6 +47,15 @@ template("libace_static") {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# build-in ark js engine for preview
|
||||
if (defined(config.use_build_in_js_engine) &&
|
||||
config.use_build_in_js_engine && defined(config.ark_engine)) {
|
||||
deps += [
|
||||
"$ace_root/frameworks/bridge/declarative_frontend:declarative_js_engine_ark_$platform",
|
||||
"$ace_root/frameworks/bridge/js_frontend/engine:js_engine_ark_$platform",
|
||||
]
|
||||
}
|
||||
part_name = ace_engine_part
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,9 @@ template("declarative_js_engine") {
|
||||
part_name = ace_engine_part
|
||||
defines += invoker.defines
|
||||
if (target_cpu == "arm64") {
|
||||
defines += [ "_ARM64_" ]
|
||||
if (!is_mingw) {
|
||||
defines += [ "_ARM64_" ]
|
||||
}
|
||||
}
|
||||
|
||||
deps = []
|
||||
|
||||
@@ -568,16 +568,6 @@ void DeclarativeFrontend::TransferJsResponseDataPreview(int callbackId, int32_t
|
||||
{
|
||||
delegate_->TransferJsResponseDataPreview(callbackId, code, responseData);
|
||||
}
|
||||
|
||||
void DeclarativeFrontend::ReplaceJSContent(const std::string& url, const std::string componentName) const
|
||||
{
|
||||
auto jsEngineInstance = AceType::DynamicCast<Framework::QJSDeclarativeEngine>(jsEngine_);
|
||||
if (!jsEngineInstance) {
|
||||
LOGE("jsEngineInstance is null");
|
||||
return;
|
||||
}
|
||||
jsEngineInstance->ReplaceJSContent(url, componentName);
|
||||
}
|
||||
#endif
|
||||
|
||||
void DeclarativeFrontend::TransferJsPluginGetError(int callbackId, int32_t errorCode, std::string&& errorMessage) const
|
||||
|
||||
@@ -87,7 +87,6 @@ public:
|
||||
}
|
||||
|
||||
void TransferJsResponseDataPreview(int32_t callbackId, int32_t code, ResponseData responseData) const;
|
||||
void ReplaceJSContent(const std::string& url, const std::string componentName) const;
|
||||
#endif
|
||||
void TransferJsPluginGetError(int32_t callbackId, int32_t errorCode, std::string&& errorMessage) const override;
|
||||
void TransferJsEventData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const override;
|
||||
|
||||
@@ -42,7 +42,7 @@ ts2abc_gen_abc("gen_jsEnumStyle_abc") {
|
||||
|
||||
gen_obj("abc_proxyclass") {
|
||||
input = base_output_path + "/stateMgmt.abc"
|
||||
if (use_mac) {
|
||||
if (use_mac || use_mingw_win) {
|
||||
abcproxyclass_obj_path = base_output_path + "/js_proxy_class.c"
|
||||
}
|
||||
output = abcproxyclass_obj_path
|
||||
@@ -75,13 +75,9 @@ template("declarative_js_engine_ark") {
|
||||
public_configs = [ "//ark/js_runtime:ark_jsruntime_public_config" ]
|
||||
|
||||
sources = [
|
||||
"$ace_root/frameworks/bridge/js_frontend/engine/jsi/jsi_base_utils.cpp",
|
||||
"ark/ark_js_runtime.cpp",
|
||||
"ark/ark_js_value.cpp",
|
||||
"js_converter.cpp",
|
||||
"jsi_declarative_engine.cpp",
|
||||
"jsi_declarative_group_js_bridge.cpp",
|
||||
"jsi_declarative_utils.cpp",
|
||||
"jsi_object_template.cpp",
|
||||
"jsi_types.cpp",
|
||||
"jsi_view_register.cpp",
|
||||
@@ -95,16 +91,28 @@ template("declarative_js_engine_ark") {
|
||||
"modules/jsi_timer_module.cpp",
|
||||
]
|
||||
|
||||
if (!defined(config.build_for_preview) || !config.build_for_preview) {
|
||||
sources += [
|
||||
"$ace_root/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp",
|
||||
"$ace_root/frameworks/bridge/js_frontend/engine/jsi/ark_js_value.cpp",
|
||||
"$ace_root/frameworks/bridge/js_frontend/engine/jsi/jsi_base_utils.cpp",
|
||||
"jsi_declarative_utils.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [ "//ark/js_runtime:libark_jsruntime" ]
|
||||
|
||||
# if napi support
|
||||
deps += [ "//foundation/ace/napi:ace_napi_ark" ]
|
||||
public_deps = [ "//foundation/ace/napi:ace_napi" ]
|
||||
|
||||
deps += [
|
||||
":gen_obj_src_abc_enum_style",
|
||||
":gen_obj_src_abc_proxyclass",
|
||||
]
|
||||
# do not support windows platform
|
||||
if (!is_mingw) {
|
||||
deps += [
|
||||
":gen_obj_src_abc_enum_style",
|
||||
":gen_obj_src_abc_proxyclass",
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,224 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/ark_js_runtime.h"
|
||||
|
||||
#include "base/log/log.h"
|
||||
#include "base/utils/system_properties.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/ark_js_value.h"
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
namespace OHOS::Ace::Framework {
|
||||
static constexpr auto PANDA_MAIN_FUNCTION = "_GLOBAL::func_main_0";
|
||||
|
||||
Local<JSValueRef> FunctionCallback(EcmaVM *vm, Local<JSValueRef> thisValue,
|
||||
const Local<JSValueRef> argument[], // NOLINT(modernize-avoid-c-arrays)
|
||||
int32_t length, void *data)
|
||||
{
|
||||
auto package = reinterpret_cast<PandaFunctionData *>(data);
|
||||
if (package == nullptr) {
|
||||
return JSValueRef::Undefined(vm);
|
||||
}
|
||||
return package->Callback(thisValue, argument, length);
|
||||
}
|
||||
|
||||
bool ArkJSRuntime::Initialize(const std::string &libraryPath, bool isDebugMode)
|
||||
{
|
||||
RuntimeOption option;
|
||||
option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC);
|
||||
option.SetArkProperties(SystemProperties::GetArkProperties());
|
||||
option.SetAsmInterOption(SystemProperties::GetAsmInterOption());
|
||||
const int64_t poolSize = 0x10000000; // 256M
|
||||
option.SetGcPoolSize(poolSize);
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
option.SetLogBufPrint(print_);
|
||||
option.SetDebuggerLibraryPath(libraryPath);
|
||||
libPath_ = libraryPath;
|
||||
isDebugMode_ = isDebugMode;
|
||||
|
||||
vm_ = JSNApi::CreateJSVM(option);
|
||||
return vm_ != nullptr;
|
||||
}
|
||||
|
||||
bool ArkJSRuntime::InitializeFromExistVM(EcmaVM* vm)
|
||||
{
|
||||
vm_ = vm;
|
||||
usingExistVM_ = true;
|
||||
LOGI("InitializeFromExistVM %{public}p", vm);
|
||||
return vm_ != nullptr;
|
||||
}
|
||||
|
||||
void ArkJSRuntime::Reset()
|
||||
{
|
||||
if (vm_ != nullptr) {
|
||||
if (!usingExistVM_) {
|
||||
JSNApi::StopDebugger(libPath_.c_str());
|
||||
JSNApi::DestroyJSVM(vm_);
|
||||
}
|
||||
vm_ = nullptr;
|
||||
}
|
||||
for (auto data : dataList_) {
|
||||
delete data;
|
||||
}
|
||||
dataList_.clear();
|
||||
}
|
||||
|
||||
void ArkJSRuntime::SetLogPrint(LOG_PRINT out)
|
||||
{
|
||||
print_ = out;
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::EvaluateJsCode([[maybe_unused]] const std::string &src)
|
||||
{
|
||||
return NewUndefined();
|
||||
}
|
||||
|
||||
bool ArkJSRuntime::EvaluateJsCode(const uint8_t *buffer, int32_t size)
|
||||
{
|
||||
JSExecutionScope executionScope(vm_);
|
||||
LocalScope scope(vm_);
|
||||
bool ret = JSNApi::Execute(vm_, buffer, size, PANDA_MAIN_FUNCTION);
|
||||
HandleUncaughtException();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ArkJSRuntime::ExecuteJsBin(const std::string &fileName)
|
||||
{
|
||||
JSExecutionScope executionScope(vm_);
|
||||
static bool debugFlag = true;
|
||||
if (debugFlag && !libPath_.empty()) {
|
||||
JSNApi::StartDebugger(libPath_.c_str(), vm_, isDebugMode_);
|
||||
debugFlag = false;
|
||||
}
|
||||
LocalScope scope(vm_);
|
||||
bool ret = JSNApi::Execute(vm_, fileName, PANDA_MAIN_FUNCTION);
|
||||
HandleUncaughtException();
|
||||
return ret;
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::GetGlobal()
|
||||
{
|
||||
LocalScope scope(vm_);
|
||||
return std::make_shared<ArkJSValue>(shared_from_this(), JSNApi::GetGlobalObject(vm_));
|
||||
}
|
||||
|
||||
void ArkJSRuntime::RunGC()
|
||||
{
|
||||
JSExecutionScope executionScope(vm_);
|
||||
LocalScope scope(vm_);
|
||||
JSNApi::TriggerGC(vm_);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::NewInt32(int32_t value)
|
||||
{
|
||||
LocalScope scope(vm_);
|
||||
return std::make_shared<ArkJSValue>(shared_from_this(), IntegerRef::New(vm_, value));
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::NewBoolean(bool value)
|
||||
{
|
||||
LocalScope scope(vm_);
|
||||
return std::make_shared<ArkJSValue>(shared_from_this(), BooleanRef::New(vm_, value));
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::NewNumber(double d)
|
||||
{
|
||||
LocalScope scope(vm_);
|
||||
return std::make_shared<ArkJSValue>(shared_from_this(), NumberRef::New(vm_, d));
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::NewNull()
|
||||
{
|
||||
LocalScope scope(vm_);
|
||||
return std::make_shared<ArkJSValue>(shared_from_this(), JSValueRef::Null(vm_));
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::NewUndefined()
|
||||
{
|
||||
LocalScope scope(vm_);
|
||||
return std::make_shared<ArkJSValue>(shared_from_this(), JSValueRef::Undefined(vm_));
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::NewString(const std::string &str)
|
||||
{
|
||||
LocalScope scope(vm_);
|
||||
return std::make_shared<ArkJSValue>(shared_from_this(), StringRef::NewFromUtf8(vm_, str.c_str()));
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::ParseJson(const std::string &str)
|
||||
{
|
||||
LocalScope scope(vm_);
|
||||
Local<StringRef> string = StringRef::NewFromUtf8(vm_, str.c_str());
|
||||
return std::make_shared<ArkJSValue>(shared_from_this(), JSON::Parse(vm_, string));
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::NewObject()
|
||||
{
|
||||
LocalScope scope(vm_);
|
||||
return std::make_shared<ArkJSValue>(shared_from_this(), ObjectRef::New(vm_));
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::NewArray()
|
||||
{
|
||||
LocalScope scope(vm_);
|
||||
return std::make_shared<ArkJSValue>(shared_from_this(), ArrayRef::New(vm_));
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::NewFunction(RegisterFunctionType func)
|
||||
{
|
||||
LocalScope scope(vm_);
|
||||
auto data = new PandaFunctionData(shared_from_this(), func);
|
||||
dataList_.emplace_back(data);
|
||||
return std::make_shared<ArkJSValue>(shared_from_this(), FunctionRef::New(vm_, FunctionCallback, data));
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSRuntime::NewNativePointer(void *ptr)
|
||||
{
|
||||
LocalScope scope(vm_);
|
||||
return std::make_shared<ArkJSValue>(shared_from_this(), NativePointerRef::New(vm_, ptr));
|
||||
}
|
||||
|
||||
void ArkJSRuntime::RegisterUncaughtExceptionHandler(UncaughtExceptionCallback callback)
|
||||
{
|
||||
JSNApi::EnableUserUncaughtErrorHandler(vm_);
|
||||
uncaughtErrorHandler_ = callback;
|
||||
}
|
||||
|
||||
void ArkJSRuntime::HandleUncaughtException()
|
||||
{
|
||||
Local<ObjectRef> exception = JSNApi::GetAndClearUncaughtException(vm_);
|
||||
if (!exception.IsEmpty() && !exception->IsHole() && uncaughtErrorHandler_ != nullptr) {
|
||||
shared_ptr<JsValue> errorPtr =
|
||||
std::static_pointer_cast<JsValue>(std::make_shared<ArkJSValue>(shared_from_this(), exception));
|
||||
uncaughtErrorHandler_(errorPtr, shared_from_this());
|
||||
}
|
||||
}
|
||||
|
||||
Local<JSValueRef> PandaFunctionData::Callback(const Local<JSValueRef> &thisValue,
|
||||
const Local<JSValueRef> argument[], // NOLINT(modernize-avoid-c-arrays)
|
||||
int32_t length) const
|
||||
{
|
||||
EscapeLocalScope scope(runtime_->GetEcmaVm());
|
||||
shared_ptr<JsValue> thisPtr = std::static_pointer_cast<JsValue>(std::make_shared<ArkJSValue>(runtime_, thisValue));
|
||||
|
||||
std::vector<shared_ptr<JsValue>> argv;
|
||||
argv.reserve(length);
|
||||
for (int i = 0; i < length; ++i) {
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
argv.emplace_back(std::static_pointer_cast<JsValue>(std::make_shared<ArkJSValue>(runtime_, argument[i])));
|
||||
}
|
||||
shared_ptr<JsValue> result = func_(runtime_, thisPtr, argv, length);
|
||||
return scope.Escape(std::static_pointer_cast<ArkJSValue>(result)->GetValue(runtime_));
|
||||
}
|
||||
} // namespace OHOS::Ace::Framework
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_ARK_ARK_JS_RUNTIME_H
|
||||
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_ARK_ARK_JS_RUNTIME_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_runtime.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
class EcmaVM;
|
||||
} // namespace panda::ecmascript
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
namespace OHOS::Ace::Framework {
|
||||
using panda::ArrayRef;
|
||||
using panda::BooleanRef;
|
||||
using panda::EscapeLocalScope;
|
||||
using panda::FunctionRef;
|
||||
using panda::Global;
|
||||
using panda::IntegerRef;
|
||||
using panda::JSExecutionScope;
|
||||
using panda::JSNApi;
|
||||
using panda::JSON;
|
||||
using panda::JSValueRef;
|
||||
using panda::Local;
|
||||
using panda::LocalScope;
|
||||
using panda::NativePointerRef;
|
||||
using panda::NumberRef;
|
||||
using panda::ObjectRef;
|
||||
using panda::RuntimeOption;
|
||||
using panda::StringRef;
|
||||
using panda::ecmascript::EcmaVM;
|
||||
class PandaFunctionData;
|
||||
|
||||
// NOLINTNEXTLINE(fuchsia-multiple-inheritance)
|
||||
class ArkJSRuntime final : public JsRuntime, public std::enable_shared_from_this<ArkJSRuntime> {
|
||||
public:
|
||||
bool StartDebugger(const char *libraryPath, EcmaVM *vm) const;
|
||||
bool Initialize(const std::string &libraryPath, bool isDebugMode) override;
|
||||
bool InitializeFromExistVM(EcmaVM* vm);
|
||||
void Reset() override;
|
||||
void SetLogPrint(LOG_PRINT out) override;
|
||||
shared_ptr<JsValue> EvaluateJsCode(const std::string &src) override;
|
||||
bool EvaluateJsCode(const uint8_t *buffer, int32_t size) override;
|
||||
bool ExecuteJsBin(const std::string &fileName) override;
|
||||
shared_ptr<JsValue> GetGlobal() override;
|
||||
void RunGC() override;
|
||||
|
||||
shared_ptr<JsValue> NewNumber(double d) override;
|
||||
shared_ptr<JsValue> NewInt32(int32_t value) override;
|
||||
shared_ptr<JsValue> NewBoolean(bool value) override;
|
||||
shared_ptr<JsValue> NewNull() override;
|
||||
shared_ptr<JsValue> NewUndefined() override;
|
||||
shared_ptr<JsValue> NewString(const std::string &str) override;
|
||||
shared_ptr<JsValue> ParseJson(const std::string &str) override;
|
||||
shared_ptr<JsValue> NewObject() override;
|
||||
shared_ptr<JsValue> NewArray() override;
|
||||
shared_ptr<JsValue> NewFunction(RegisterFunctionType func) override;
|
||||
shared_ptr<JsValue> NewNativePointer(void *ptr) override;
|
||||
void RegisterUncaughtExceptionHandler(UncaughtExceptionCallback callback) override;
|
||||
void HandleUncaughtException() override;
|
||||
|
||||
const EcmaVM *GetEcmaVm() const
|
||||
{
|
||||
return vm_;
|
||||
}
|
||||
|
||||
private:
|
||||
EcmaVM *vm_ = nullptr;
|
||||
std::vector<PandaFunctionData *> dataList_;
|
||||
LOG_PRINT print_ { nullptr };
|
||||
UncaughtExceptionCallback uncaughtErrorHandler_ { nullptr };
|
||||
std::string libPath_ {};
|
||||
bool usingExistVM_ = false;
|
||||
bool isDebugMode_ = true;
|
||||
};
|
||||
|
||||
class PandaFunctionData {
|
||||
public:
|
||||
PandaFunctionData(shared_ptr<ArkJSRuntime> runtime, RegisterFunctionType func)
|
||||
: runtime_(std::move(runtime)), func_(std::move(func))
|
||||
{
|
||||
}
|
||||
|
||||
~PandaFunctionData() = default;
|
||||
|
||||
NO_COPY_SEMANTIC(PandaFunctionData);
|
||||
NO_MOVE_SEMANTIC(PandaFunctionData);
|
||||
|
||||
private:
|
||||
Local<JSValueRef> Callback(const Local<JSValueRef> &thisValue,
|
||||
const Local<JSValueRef> argument[], // NOLINT(modernize-avoid-c-arrays)
|
||||
int32_t length) const;
|
||||
shared_ptr<ArkJSRuntime> runtime_;
|
||||
RegisterFunctionType func_;
|
||||
friend Local<JSValueRef> FunctionCallback(EcmaVM *vm, Local<JSValueRef> thisValue,
|
||||
const Local<JSValueRef> argument[], // NOLINT(modernize-avoid-c-arrays)
|
||||
int32_t length, void *data);
|
||||
};
|
||||
} // namespace OHOS::Ace::Framework
|
||||
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_ARK_ARK_JS_RUNTIME_H
|
||||
@@ -1,328 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/ark_js_value.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
namespace OHOS::Ace::Framework {
|
||||
int32_t ArkJSValue::ToInt32(shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
if (value_.CheckException()) {
|
||||
return 0;
|
||||
}
|
||||
return value_->Int32Value(pandaRuntime->GetEcmaVm());
|
||||
}
|
||||
|
||||
double ArkJSValue::ToDouble(shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
if (value_.CheckException()) {
|
||||
return 0;
|
||||
}
|
||||
Local<NumberRef> number = value_->ToNumber(pandaRuntime->GetEcmaVm());
|
||||
if (!number.CheckException()) {
|
||||
return number->Value();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string ArkJSValue::ToString(shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
if (value_.CheckException()) {
|
||||
return "";
|
||||
}
|
||||
Local<StringRef> string = value_->ToString(pandaRuntime->GetEcmaVm());
|
||||
if (!string.CheckException()) {
|
||||
return string->ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool ArkJSValue::ToBoolean(shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
return !value_.CheckException() && value_->BooleaValue();
|
||||
}
|
||||
|
||||
bool ArkJSValue::IsUndefined([[maybe_unused]] shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
return !value_.IsEmpty() && value_->IsUndefined();
|
||||
}
|
||||
|
||||
bool ArkJSValue::IsNull([[maybe_unused]] shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
return !value_.IsEmpty() && value_->IsNull();
|
||||
}
|
||||
|
||||
bool ArkJSValue::IsBoolean([[maybe_unused]] shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
return !value_.IsEmpty() && value_->IsBoolean();
|
||||
}
|
||||
|
||||
bool ArkJSValue::IsInt32([[maybe_unused]] shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
return !value_.IsEmpty() && value_->IsInt();
|
||||
}
|
||||
|
||||
bool ArkJSValue::WithinInt32([[maybe_unused]] shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
return !value_.IsEmpty() && value_->WithinInt32();
|
||||
}
|
||||
|
||||
bool ArkJSValue::IsString([[maybe_unused]] shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
return !value_.IsEmpty() && value_->IsString();
|
||||
}
|
||||
|
||||
bool ArkJSValue::IsNumber([[maybe_unused]] shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
return !value_.IsEmpty() && value_->IsNumber();
|
||||
}
|
||||
|
||||
bool ArkJSValue::IsObject([[maybe_unused]] shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
return !value_.IsEmpty() && value_->IsObject();
|
||||
}
|
||||
|
||||
bool ArkJSValue::IsArray([[maybe_unused]] shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
return !value_.IsEmpty() && value_->IsArray(pandaRuntime->GetEcmaVm());
|
||||
}
|
||||
|
||||
bool ArkJSValue::IsFunction([[maybe_unused]] shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
return !value_.IsEmpty() && value_->IsFunction();
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(performance-unnecessary-value-param)
|
||||
bool ArkJSValue::IsException([[maybe_unused]] shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
return value_.IsEmpty() || value_->IsException();
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSValue::Call(shared_ptr<JsRuntime> runtime, shared_ptr<JsValue> thisObj,
|
||||
std::vector<shared_ptr<JsValue>> argv, int32_t argc)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
JSExecutionScope executionScope(pandaRuntime->GetEcmaVm());
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
if (!IsFunction(pandaRuntime)) {
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, JSValueRef::Exception(pandaRuntime->GetEcmaVm()));
|
||||
}
|
||||
std::vector<Local<JSValueRef>> arguments;
|
||||
arguments.reserve(argc);
|
||||
for (const shared_ptr<JsValue> &arg : argv) {
|
||||
arguments.emplace_back(std::static_pointer_cast<ArkJSValue>(arg)->GetValue(pandaRuntime));
|
||||
}
|
||||
Local<JSValueRef> thisValue = std::static_pointer_cast<ArkJSValue>(thisObj)->GetValue(pandaRuntime);
|
||||
Local<FunctionRef> function(GetValue(pandaRuntime));
|
||||
Local<JSValueRef> result = function->Call(pandaRuntime->GetEcmaVm(), thisValue, arguments.data(), argc);
|
||||
runtime->HandleUncaughtException();
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, result);
|
||||
}
|
||||
|
||||
bool ArkJSValue::GetPropertyNames(shared_ptr<JsRuntime> runtime, shared_ptr<JsValue> &propName, int32_t &len)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
if (value_.CheckException()) {
|
||||
return false;
|
||||
}
|
||||
Local<ObjectRef> obj = value_->ToObject(pandaRuntime->GetEcmaVm());
|
||||
if (obj.CheckException()) {
|
||||
return false;
|
||||
}
|
||||
Local<ArrayRef> names = obj->GetOwnPropertyNames(pandaRuntime->GetEcmaVm());
|
||||
len = names->Length(pandaRuntime->GetEcmaVm());
|
||||
if (!propName) {
|
||||
propName = std::make_shared<ArkJSValue>(pandaRuntime, names);
|
||||
} else {
|
||||
std::static_pointer_cast<ArkJSValue>(propName)->SetValue(pandaRuntime, names);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArkJSValue::GetEnumerablePropertyNames(shared_ptr<JsRuntime> runtime, shared_ptr<JsValue> &propName, int32_t &len)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
if (value_.CheckException()) {
|
||||
return false;
|
||||
}
|
||||
Local<ObjectRef> obj = value_->ToObject(pandaRuntime->GetEcmaVm());
|
||||
if (obj.CheckException()) {
|
||||
return false;
|
||||
}
|
||||
Local<ArrayRef> names = obj->GetOwnEnumerablePropertyNames(pandaRuntime->GetEcmaVm());
|
||||
len = names->Length(pandaRuntime->GetEcmaVm());
|
||||
if (!propName) {
|
||||
propName = std::make_shared<ArkJSValue>(pandaRuntime, names);
|
||||
} else {
|
||||
std::static_pointer_cast<ArkJSValue>(propName)->SetValue(pandaRuntime, names);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSValue::GetProperty(shared_ptr<JsRuntime> runtime, int32_t idx)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
if (value_.CheckException()) {
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, JSValueRef::Exception(pandaRuntime->GetEcmaVm()));
|
||||
}
|
||||
Local<ObjectRef> obj = value_->ToObject(pandaRuntime->GetEcmaVm());
|
||||
if (obj.CheckException()) {
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, JSValueRef::Exception(pandaRuntime->GetEcmaVm()));
|
||||
}
|
||||
Local<JSValueRef> property = obj->Get(pandaRuntime->GetEcmaVm(), idx);
|
||||
if (property.CheckException()) {
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, JSValueRef::Exception(pandaRuntime->GetEcmaVm()));
|
||||
}
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, property);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSValue::GetProperty(shared_ptr<JsRuntime> runtime, const std::string &name)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
shared_ptr<JsValue> key = pandaRuntime->NewString(name);
|
||||
return GetProperty(runtime, key);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSValue::GetProperty(shared_ptr<JsRuntime> runtime, const shared_ptr<JsValue> &name)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
if (value_.CheckException()) {
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, JSValueRef::Exception(pandaRuntime->GetEcmaVm()));
|
||||
}
|
||||
Local<ObjectRef> obj = value_->ToObject(pandaRuntime->GetEcmaVm());
|
||||
if (obj.CheckException()) {
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, JSValueRef::Exception(pandaRuntime->GetEcmaVm()));
|
||||
}
|
||||
Local<JSValueRef> key = std::static_pointer_cast<ArkJSValue>(name)->GetValue(pandaRuntime);
|
||||
Local<JSValueRef> property = obj->Get(pandaRuntime->GetEcmaVm(), key);
|
||||
if (property.CheckException()) {
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, JSValueRef::Exception(pandaRuntime->GetEcmaVm()));
|
||||
}
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, property);
|
||||
}
|
||||
|
||||
bool ArkJSValue::SetProperty(shared_ptr<JsRuntime> runtime, const std::string &name, const shared_ptr<JsValue> &value)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
shared_ptr<JsValue> key = pandaRuntime->NewString(name);
|
||||
return SetProperty(runtime, key, value);
|
||||
}
|
||||
|
||||
bool ArkJSValue::SetProperty(shared_ptr<JsRuntime> runtime, const shared_ptr<JsValue> &name,
|
||||
const shared_ptr<JsValue> &value)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
if (value_.CheckException()) {
|
||||
return false;
|
||||
}
|
||||
Local<ObjectRef> obj = value_->ToObject(pandaRuntime->GetEcmaVm());
|
||||
if (obj.CheckException()) {
|
||||
return false;
|
||||
}
|
||||
Local<JSValueRef> key = std::static_pointer_cast<ArkJSValue>(name)->GetValue(pandaRuntime);
|
||||
Local<JSValueRef> value_ref = std::static_pointer_cast<ArkJSValue>(value)->GetValue(pandaRuntime);
|
||||
return obj->Set(pandaRuntime->GetEcmaVm(), key, value_ref);
|
||||
}
|
||||
|
||||
bool ArkJSValue::SetAccessorProperty(shared_ptr<JsRuntime> runtime, const std::string &name,
|
||||
const shared_ptr<JsValue> &getter, const shared_ptr<JsValue> &setter)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
shared_ptr<JsValue> key = pandaRuntime->NewString(name);
|
||||
return SetAccessorProperty(runtime, key, getter, setter);
|
||||
}
|
||||
|
||||
bool ArkJSValue::SetAccessorProperty(shared_ptr<JsRuntime> runtime, const shared_ptr<JsValue> &name,
|
||||
const shared_ptr<JsValue> &getter, const shared_ptr<JsValue> &setter)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
if (value_.CheckException()) {
|
||||
return false;
|
||||
}
|
||||
Local<ObjectRef> obj = value_->ToObject(pandaRuntime->GetEcmaVm());
|
||||
if (obj.CheckException()) {
|
||||
return false;
|
||||
}
|
||||
Local<JSValueRef> key = std::static_pointer_cast<ArkJSValue>(name)->GetValue(pandaRuntime);
|
||||
Local<JSValueRef> getterValue = std::static_pointer_cast<ArkJSValue>(getter)->GetValue(pandaRuntime);
|
||||
Local<JSValueRef> setterValue = std::static_pointer_cast<ArkJSValue>(setter)->GetValue(pandaRuntime);
|
||||
return obj->SetAccessorProperty(pandaRuntime->GetEcmaVm(), key, getterValue, setterValue);
|
||||
}
|
||||
|
||||
int32_t ArkJSValue::GetArrayLength(shared_ptr<JsRuntime> runtime)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
if (value_.CheckException()) {
|
||||
return -1;
|
||||
}
|
||||
Local<ArrayRef> array(GetValue(pandaRuntime));
|
||||
return array->Length(pandaRuntime->GetEcmaVm());
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ArkJSValue::GetElement(shared_ptr<JsRuntime> runtime, int32_t idx)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
if (value_.CheckException()) {
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, JSValueRef::Exception(pandaRuntime->GetEcmaVm()));
|
||||
}
|
||||
Local<ArrayRef> obj(GetValue(pandaRuntime));
|
||||
if (obj.CheckException()) {
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, JSValueRef::Exception(pandaRuntime->GetEcmaVm()));
|
||||
}
|
||||
Local<JSValueRef> property = obj->Get(pandaRuntime->GetEcmaVm(), idx);
|
||||
if (property.CheckException()) {
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, JSValueRef::Exception(pandaRuntime->GetEcmaVm()));
|
||||
}
|
||||
return std::make_shared<ArkJSValue>(pandaRuntime, property);
|
||||
}
|
||||
|
||||
std::string ArkJSValue::GetJsonString(const shared_ptr<JsRuntime>& runtime)
|
||||
{
|
||||
shared_ptr<ArkJSRuntime> pandaRuntime = std::static_pointer_cast<ArkJSRuntime>(runtime);
|
||||
LocalScope scope(pandaRuntime->GetEcmaVm());
|
||||
auto stringify = panda::JSON::Stringify(pandaRuntime->GetEcmaVm(), GetValue(pandaRuntime));
|
||||
if (stringify.CheckException()) {
|
||||
return "";
|
||||
}
|
||||
auto valueStr = panda::Local<panda::StringRef>(stringify);
|
||||
if (valueStr.CheckException()) {
|
||||
return "";
|
||||
}
|
||||
return valueStr->ToString();
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_ARK_ARK_JS_VALUE_H
|
||||
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_ARK_ARK_JS_VALUE_H
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/ark_js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_value.h"
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
namespace OHOS::Ace::Framework {
|
||||
using panda::ArrayRef;
|
||||
using panda::EscapeLocalScope;
|
||||
using panda::FunctionRef;
|
||||
using panda::Global;
|
||||
using panda::JSON;
|
||||
using panda::JSValueRef;
|
||||
using panda::Local;
|
||||
using panda::LocalScope;
|
||||
using panda::NumberRef;
|
||||
using panda::ObjectRef;
|
||||
using panda::StringRef;
|
||||
class PandaFunctionData;
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions, hicpp-special-member-functions)
|
||||
class ArkJSValue final : public JsValue {
|
||||
public:
|
||||
ArkJSValue(const shared_ptr<ArkJSRuntime> &runtime, Local<JSValueRef> value) : value_(runtime->GetEcmaVm(), value)
|
||||
{
|
||||
}
|
||||
~ArkJSValue() override
|
||||
{
|
||||
value_.FreeGlobalHandleAddr();
|
||||
}
|
||||
|
||||
int32_t ToInt32(shared_ptr<JsRuntime> runtime) override;
|
||||
double ToDouble(shared_ptr<JsRuntime> runtime) override;
|
||||
std::string ToString(shared_ptr<JsRuntime> runtime) override;
|
||||
bool ToBoolean(shared_ptr<JsRuntime> runtime) override;
|
||||
|
||||
bool IsUndefined(shared_ptr<JsRuntime> runtime) override;
|
||||
bool IsNull(shared_ptr<JsRuntime> runtime) override;
|
||||
bool IsBoolean(shared_ptr<JsRuntime> runtime) override;
|
||||
bool IsInt32(shared_ptr<JsRuntime> runtime) override;
|
||||
bool WithinInt32(shared_ptr<JsRuntime> runtime) override;
|
||||
bool IsString(shared_ptr<JsRuntime> runtime) override;
|
||||
bool IsNumber(shared_ptr<JsRuntime> runtime) override;
|
||||
bool IsObject(shared_ptr<JsRuntime> runtime) override;
|
||||
bool IsArray(shared_ptr<JsRuntime> runtime) override;
|
||||
bool IsFunction(shared_ptr<JsRuntime> runtime) override;
|
||||
bool IsException(shared_ptr<JsRuntime> runtime) override;
|
||||
|
||||
shared_ptr<JsValue> Call(shared_ptr<JsRuntime> runtime, shared_ptr<JsValue> thisObj,
|
||||
std::vector<shared_ptr<JsValue>> argv, int32_t argc) override;
|
||||
|
||||
bool GetPropertyNames(shared_ptr<JsRuntime> runtime, shared_ptr<JsValue> &propName, int32_t &len) override;
|
||||
bool GetEnumerablePropertyNames(shared_ptr<JsRuntime> runtime,
|
||||
shared_ptr<JsValue> &propName, int32_t &len) override;
|
||||
shared_ptr<JsValue> GetProperty(shared_ptr<JsRuntime> runtime, int32_t idx) override;
|
||||
shared_ptr<JsValue> GetProperty(shared_ptr<JsRuntime> runtime, const std::string &name) override;
|
||||
shared_ptr<JsValue> GetProperty(shared_ptr<JsRuntime> runtime, const shared_ptr<JsValue> &name) override;
|
||||
|
||||
bool SetProperty(shared_ptr<JsRuntime> runtime, const std::string &name, const shared_ptr<JsValue> &value) override;
|
||||
bool SetProperty(shared_ptr<JsRuntime> runtime, const shared_ptr<JsValue> &name,
|
||||
const shared_ptr<JsValue> &value) override;
|
||||
bool SetAccessorProperty(shared_ptr<JsRuntime> runtime, const std::string &name, const shared_ptr<JsValue> &getter,
|
||||
const shared_ptr<JsValue> &setter) override;
|
||||
bool SetAccessorProperty(shared_ptr<JsRuntime> runtime, const shared_ptr<JsValue> &name,
|
||||
const shared_ptr<JsValue> &getter, const shared_ptr<JsValue> &setter) override;
|
||||
|
||||
int32_t GetArrayLength(shared_ptr<JsRuntime> runtime) override;
|
||||
shared_ptr<JsValue> GetElement(shared_ptr<JsRuntime> runtime, int32_t idx) override;
|
||||
std::string GetJsonString(const shared_ptr<JsRuntime>& runtime) override;
|
||||
|
||||
Local<JSValueRef> GetValue(const shared_ptr<ArkJSRuntime> &runtime)
|
||||
{
|
||||
return value_.ToLocal(runtime->GetEcmaVm());
|
||||
}
|
||||
|
||||
void SetValue(const shared_ptr<ArkJSRuntime> &runtime, const Local<JSValueRef> &value)
|
||||
{
|
||||
value_ = Global<JSValueRef>(runtime->GetEcmaVm(), value);
|
||||
}
|
||||
|
||||
private:
|
||||
Global<JSValueRef> value_ {};
|
||||
};
|
||||
} // namespace OHOS::Ace::Framework
|
||||
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_ARK_ARK_JS_VALUE_H
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_ENGINE_JSI_JS_RUNTIME_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_ENGINE_JSI_JS_RUNTIME_H
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
namespace OHOS::Ace::Framework {
|
||||
class JsValue;
|
||||
class JsRuntime;
|
||||
|
||||
using std::shared_ptr;
|
||||
using RegisterFunctionType = std::function<shared_ptr<JsValue>(shared_ptr<JsRuntime>, shared_ptr<JsValue>,
|
||||
const std::vector<shared_ptr<JsValue>> &, int32_t)>;
|
||||
using LOG_PRINT = int (*)(int id, int level, const char *tag, const char *fmt, const char *message);
|
||||
using UncaughtExceptionCallback = std::function<void(shared_ptr<JsValue>, std::shared_ptr<JsRuntime>)>;
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions, hicpp-special-member-functions)
|
||||
class JsRuntime {
|
||||
public:
|
||||
virtual ~JsRuntime() = default;
|
||||
|
||||
// Prepare js environment, returns true if success.
|
||||
virtual bool Initialize(const std::string &libraryPath, bool isDebugMode) = 0;
|
||||
virtual void Reset() = 0;
|
||||
virtual void SetLogPrint(LOG_PRINT out) = 0;
|
||||
|
||||
// Evaluate a piece of js code, returns true if success.
|
||||
// If exception occurs during execution, it is handled inside this interface.
|
||||
virtual shared_ptr<JsValue> EvaluateJsCode(const std::string &src) = 0;
|
||||
virtual bool EvaluateJsCode(const uint8_t *buffer, int32_t size) = 0;
|
||||
|
||||
virtual bool ExecuteJsBin([[maybe_unused]] const std::string &fileName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the global object.
|
||||
virtual shared_ptr<JsValue> GetGlobal() = 0;
|
||||
virtual void RunGC() = 0;
|
||||
|
||||
virtual shared_ptr<JsValue> NewNumber(double d) = 0;
|
||||
virtual shared_ptr<JsValue> NewInt32(int32_t value) = 0;
|
||||
virtual shared_ptr<JsValue> NewBoolean(bool value) = 0;
|
||||
virtual shared_ptr<JsValue> NewNull() = 0;
|
||||
virtual shared_ptr<JsValue> NewUndefined() = 0;
|
||||
virtual shared_ptr<JsValue> NewString(const std::string &str) = 0;
|
||||
virtual shared_ptr<JsValue> ParseJson(const std::string &str) = 0;
|
||||
virtual shared_ptr<JsValue> NewObject() = 0;
|
||||
virtual shared_ptr<JsValue> NewArray() = 0;
|
||||
virtual shared_ptr<JsValue> NewFunction(RegisterFunctionType func) = 0;
|
||||
virtual shared_ptr<JsValue> NewNativePointer(void *ptr) = 0;
|
||||
virtual void RegisterUncaughtExceptionHandler(UncaughtExceptionCallback callback) = 0;
|
||||
virtual void HandleUncaughtException() = 0;
|
||||
|
||||
// Set c++ data to js environment.
|
||||
void SetEmbedderData(void *data)
|
||||
{
|
||||
embedderData_ = data;
|
||||
}
|
||||
// Get c++ data from js environment.
|
||||
void *GetEmbedderData() const
|
||||
{
|
||||
return embedderData_;
|
||||
}
|
||||
|
||||
private:
|
||||
void *embedderData_ = nullptr;
|
||||
};
|
||||
} // namespace OHOS::Ace::Framework
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_ENGINE_JSI_JS_RUNTIME_H
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_ENGINE_JSI_JS_VALUE_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_ENGINE_JSI_JS_VALUE_H
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
namespace OHOS::Ace::Framework {
|
||||
using std::shared_ptr;
|
||||
class JsRuntime;
|
||||
/* A class that represent all types of js value. Since we don't have separate class for each type, please check it's
|
||||
* type before calling a type specific method such as GetProperty.
|
||||
*/
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions, hicpp-special-member-functions)
|
||||
class JsValue {
|
||||
public:
|
||||
JsValue() = default;
|
||||
virtual ~JsValue() = default;
|
||||
|
||||
virtual int32_t ToInt32(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual double ToDouble(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual std::string ToString(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual bool ToBoolean(shared_ptr<JsRuntime> runtime) = 0;
|
||||
|
||||
virtual bool IsObject(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual bool IsArray(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual bool IsUndefined(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual bool IsNull(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual bool IsNumber(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual bool IsInt32(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual bool WithinInt32(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual bool IsBoolean(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual bool IsString(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual bool IsFunction(shared_ptr<JsRuntime> runtime) = 0;
|
||||
virtual bool IsException(shared_ptr<JsRuntime> runtime) = 0;
|
||||
|
||||
virtual bool GetPropertyNames(shared_ptr<JsRuntime> runtime, shared_ptr<JsValue> &propertyNames, int32_t &len) = 0;
|
||||
virtual bool GetEnumerablePropertyNames(shared_ptr<JsRuntime> runtime,
|
||||
shared_ptr<JsValue> &propertyNames, int32_t &len) = 0;
|
||||
|
||||
// Get object property by name or index, returns an nullptr if failed to get the specified property.
|
||||
virtual shared_ptr<JsValue> GetProperty(shared_ptr<JsRuntime> runtime, int32_t idx) = 0;
|
||||
virtual shared_ptr<JsValue> GetProperty(shared_ptr<JsRuntime> runtime, const std::string &name) = 0;
|
||||
virtual shared_ptr<JsValue> GetProperty(shared_ptr<JsRuntime> runtime, const shared_ptr<JsValue> &name) = 0;
|
||||
|
||||
// Set a property with the given name and value, returns true if success.
|
||||
virtual bool SetProperty(shared_ptr<JsRuntime> runtime, const std::string &name,
|
||||
const shared_ptr<JsValue> &value) = 0;
|
||||
virtual bool SetProperty(shared_ptr<JsRuntime> runtime, const shared_ptr<JsValue> &name,
|
||||
const shared_ptr<JsValue> &value) = 0;
|
||||
virtual bool SetAccessorProperty(shared_ptr<JsRuntime> runtime, const std::string &name,
|
||||
const shared_ptr<JsValue> &getter, const shared_ptr<JsValue> &setter) = 0;
|
||||
virtual bool SetAccessorProperty(shared_ptr<JsRuntime> runtime, const shared_ptr<JsValue> &name,
|
||||
const shared_ptr<JsValue> &getter, const shared_ptr<JsValue> &setter) = 0;
|
||||
|
||||
// Get an array's length. Return -1 if fails.
|
||||
virtual int32_t GetArrayLength(shared_ptr<JsRuntime> runtime) = 0;
|
||||
// Get an array element by index, Return nullptr if fails.
|
||||
virtual shared_ptr<JsValue> GetElement(shared_ptr<JsRuntime> runtime, int32_t idx) = 0;
|
||||
|
||||
virtual shared_ptr<JsValue> Call(shared_ptr<JsRuntime> runtime, shared_ptr<JsValue> thisObj,
|
||||
std::vector<shared_ptr<JsValue>> argv, int32_t argc) = 0;
|
||||
|
||||
virtual std::string GetJsonString(const shared_ptr<JsRuntime>& runtime) = 0;
|
||||
};
|
||||
} // namespace OHOS::Ace::Framework
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_ENGINE_JSI_JS_VALUE_H
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "base/log/log.h"
|
||||
#include "native_engine/native_value.h"
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/ark_js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
#include "frameworks/bridge/declarative_frontend/engine/js_converter.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/js_ref_ptr.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/js_types.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/ark_js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/ark_js_value.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/ark_js_value.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_group_js_bridge.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_context_module.h"
|
||||
@@ -43,216 +43,28 @@
|
||||
#include "frameworks/bridge/js_frontend/engine/common/runtime_constants.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/jsi_base_utils.h"
|
||||
|
||||
#ifndef WINDOWS_PLATFORM
|
||||
extern const char _binary_stateMgmt_abc_start[];
|
||||
extern const char _binary_stateMgmt_abc_end[];
|
||||
extern const char _binary_jsEnumStyle_abc_start[];
|
||||
extern const char _binary_jsEnumStyle_abc_end[];
|
||||
#endif
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
namespace {
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
const char COMPONENT_PREVIEW_LOAD_DOCUMENT_NEW[] = "loadDocument(new";
|
||||
const char LEFT_PARENTTHESIS[] = "(";
|
||||
constexpr int32_t LOAD_DOCUMENT_STR_LENGTH = 16;
|
||||
#endif
|
||||
|
||||
#ifdef APP_USE_ARM
|
||||
const std::string ARK_DEBUGGER_LIB_PATH = "/system/lib/libark_debugger.z.so";
|
||||
#else
|
||||
const std::string ARK_DEBUGGER_LIB_PATH = "/system/lib64/libark_debugger.z.so";
|
||||
#endif
|
||||
|
||||
std::string ParseLogContent(const std::vector<std::string>& params)
|
||||
{
|
||||
std::string ret;
|
||||
if (params.empty()) {
|
||||
return ret;
|
||||
}
|
||||
std::string formatStr = params[0];
|
||||
int32_t size = static_cast<int32_t>(params.size());
|
||||
int32_t len = static_cast<int32_t>(formatStr.size());
|
||||
int32_t pos = 0;
|
||||
int32_t count = 1;
|
||||
for (; pos < len; ++pos) {
|
||||
if (count >= size) {
|
||||
break;
|
||||
}
|
||||
if (formatStr[pos] == '%') {
|
||||
if (pos + 1 >= len) {
|
||||
break;
|
||||
}
|
||||
switch (formatStr[pos + 1]) {
|
||||
case 's':
|
||||
case 'j':
|
||||
case 'd':
|
||||
case 'O':
|
||||
case 'o':
|
||||
case 'i':
|
||||
case 'f':
|
||||
case 'c':
|
||||
ret += params[count++];
|
||||
++pos;
|
||||
break;
|
||||
case '%':
|
||||
ret += formatStr[pos];
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
ret += formatStr[pos];
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ret += formatStr[pos];
|
||||
}
|
||||
}
|
||||
if (pos < len) {
|
||||
ret += formatStr.substr(pos, len - pos);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string GetLogContent(
|
||||
const shared_ptr<JsRuntime>& runtime, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
if (argc == 1) {
|
||||
return argv[0]->ToString(runtime);
|
||||
}
|
||||
std::vector<std::string> params;
|
||||
for (int32_t i = 0; i < argc; ++i) {
|
||||
params.emplace_back(argv[i]->ToString(runtime));
|
||||
}
|
||||
return ParseLogContent(params);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> AppLogPrint(
|
||||
const shared_ptr<JsRuntime>& runtime, JsLogLevel level, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
// Should have at least 1 parameter.
|
||||
if (argc == 0) {
|
||||
LOGE("the arg is error");
|
||||
return runtime->NewUndefined();
|
||||
}
|
||||
std::string content = GetLogContent(runtime, argv, argc);
|
||||
switch (level) {
|
||||
case JsLogLevel::DEBUG:
|
||||
APP_LOGD("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::INFO:
|
||||
APP_LOGI("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
APP_LOGW("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
APP_LOGE("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
return runtime->NewUndefined();
|
||||
}
|
||||
|
||||
// native implementation for js function: console.debug()
|
||||
shared_ptr<JsValue> AppDebugLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::DEBUG, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: console.info()
|
||||
shared_ptr<JsValue> AppInfoLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::INFO, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: console.warn()
|
||||
shared_ptr<JsValue> AppWarnLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::WARNING, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: console.error()
|
||||
shared_ptr<JsValue> AppErrorLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::ERROR, argv, argc);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> JsLogPrint(
|
||||
const shared_ptr<JsRuntime>& runtime, JsLogLevel level, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
// Should have 1 parameters.
|
||||
if (argc == 0) {
|
||||
LOGE("the arg is error");
|
||||
return runtime->NewUndefined();
|
||||
}
|
||||
|
||||
std::string content = GetLogContent(runtime, argv, argc);
|
||||
switch (level) {
|
||||
case JsLogLevel::DEBUG:
|
||||
LOGD("ace Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::INFO:
|
||||
LOGI("ace Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
LOGW("ace Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
LOGE("ace Log: %{public}s", content.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ret = runtime->NewUndefined();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int PrintLog(int id, int level, const char* tag, const char* fmt, const char* message)
|
||||
{
|
||||
switch (JsLogLevel(level - 3)) {
|
||||
case JsLogLevel::INFO:
|
||||
LOGI("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
LOGW("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
LOGE("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
case JsLogLevel::DEBUG:
|
||||
LOGD("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
default:
|
||||
LOGF("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// native implementation for js function: aceConsole.debug()
|
||||
shared_ptr<JsValue> JsDebugLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return JsLogPrint(runtime, JsLogLevel::DEBUG, std::move(argv), argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: aceConsole.info()
|
||||
shared_ptr<JsValue> JsInfoLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return JsLogPrint(runtime, JsLogLevel::INFO, std::move(argv), argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: aceConsole.warn()
|
||||
shared_ptr<JsValue> JsWarnLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return JsLogPrint(runtime, JsLogLevel::WARNING, std::move(argv), argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: aceConsole.error()
|
||||
shared_ptr<JsValue> JsErrorLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return JsLogPrint(runtime, JsLogLevel::ERROR, std::move(argv), argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: perfutil.print()
|
||||
shared_ptr<JsValue> JsPerfPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
@@ -310,7 +122,6 @@ shared_ptr<JsValue> RequireNativeModule(const shared_ptr<JsRuntime>& runtime, co
|
||||
|
||||
return runtime->NewNull();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// -----------------------
|
||||
@@ -426,6 +237,7 @@ bool JsiDeclarativeEngineInstance::FireJsEvent(const std::string& eventStr)
|
||||
|
||||
void JsiDeclarativeEngineInstance::InitAceModule()
|
||||
{
|
||||
#ifndef WINDOWS_PLATFORM
|
||||
bool stateMgmtResult = runtime_->EvaluateJsCode(
|
||||
(uint8_t*)_binary_stateMgmt_abc_start, _binary_stateMgmt_abc_end - _binary_stateMgmt_abc_start);
|
||||
if (!stateMgmtResult) {
|
||||
@@ -436,6 +248,7 @@ void JsiDeclarativeEngineInstance::InitAceModule()
|
||||
if (!jsEnumStyleResult) {
|
||||
LOGE("EvaluateJsCode jsEnumStyle failed");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" ACE_EXPORT void OHOS_ACE_PreloadAceModule(void* runtime)
|
||||
@@ -475,11 +288,11 @@ void JsiDeclarativeEngineInstance::PreloadAceModule(void* runtime)
|
||||
// preload aceConsole
|
||||
shared_ptr<JsValue> global = arkRuntime->GetGlobal();
|
||||
shared_ptr<JsValue> aceConsoleObj = arkRuntime->NewObject();
|
||||
aceConsoleObj->SetProperty(arkRuntime, "log", arkRuntime->NewFunction(JsDebugLogPrint));
|
||||
aceConsoleObj->SetProperty(arkRuntime, "debug", arkRuntime->NewFunction(JsDebugLogPrint));
|
||||
aceConsoleObj->SetProperty(arkRuntime, "info", arkRuntime->NewFunction(JsInfoLogPrint));
|
||||
aceConsoleObj->SetProperty(arkRuntime, "warn", arkRuntime->NewFunction(JsWarnLogPrint));
|
||||
aceConsoleObj->SetProperty(arkRuntime, "error", arkRuntime->NewFunction(JsErrorLogPrint));
|
||||
aceConsoleObj->SetProperty(arkRuntime, "log", arkRuntime->NewFunction(JsiBaseUtils::JsDebugLogPrint));
|
||||
aceConsoleObj->SetProperty(arkRuntime, "debug", arkRuntime->NewFunction(JsiBaseUtils::JsDebugLogPrint));
|
||||
aceConsoleObj->SetProperty(arkRuntime, "info", arkRuntime->NewFunction(JsiBaseUtils::JsInfoLogPrint));
|
||||
aceConsoleObj->SetProperty(arkRuntime, "warn", arkRuntime->NewFunction(JsiBaseUtils::JsWarnLogPrint));
|
||||
aceConsoleObj->SetProperty(arkRuntime, "error", arkRuntime->NewFunction(JsiBaseUtils::JsErrorLogPrint));
|
||||
global->SetProperty(arkRuntime, "aceConsole", aceConsoleObj);
|
||||
|
||||
// preload perfutil
|
||||
@@ -495,6 +308,7 @@ void JsiDeclarativeEngineInstance::PreloadAceModule(void* runtime)
|
||||
global->SetProperty(arkRuntime, "exports", exportsUtilObj);
|
||||
global->SetProperty(arkRuntime, "requireNativeModule", arkRuntime->NewFunction(RequireNativeModule));
|
||||
|
||||
#ifndef WINDOWS_PLATFORM
|
||||
// preload js enums
|
||||
bool jsEnumStyleResult = arkRuntime->EvaluateJsCode(
|
||||
(uint8_t*)_binary_jsEnumStyle_abc_start, _binary_jsEnumStyle_abc_end - _binary_jsEnumStyle_abc_start);
|
||||
@@ -514,6 +328,7 @@ void JsiDeclarativeEngineInstance::PreloadAceModule(void* runtime)
|
||||
isModulePreloaded_ = evalResult;
|
||||
globalRuntime_ = nullptr;
|
||||
LOGI("PreloadAceModule loaded:%{public}d", isModulePreloaded_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void JsiDeclarativeEngineInstance::InitConsoleModule()
|
||||
@@ -525,11 +340,11 @@ void JsiDeclarativeEngineInstance::InitConsoleModule()
|
||||
// app log method
|
||||
if (!usingSharedRuntime_) {
|
||||
shared_ptr<JsValue> consoleObj = runtime_->NewObject();
|
||||
consoleObj->SetProperty(runtime_, "log", runtime_->NewFunction(AppDebugLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "debug", runtime_->NewFunction(AppDebugLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "info", runtime_->NewFunction(AppInfoLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "warn", runtime_->NewFunction(AppWarnLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "error", runtime_->NewFunction(AppErrorLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "log", runtime_->NewFunction(JsiBaseUtils::AppDebugLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "debug", runtime_->NewFunction(JsiBaseUtils::AppDebugLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "info", runtime_->NewFunction(JsiBaseUtils::AppInfoLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "warn", runtime_->NewFunction(JsiBaseUtils::AppWarnLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "error", runtime_->NewFunction(JsiBaseUtils::AppErrorLogPrint));
|
||||
global->SetProperty(runtime_, "console", consoleObj);
|
||||
}
|
||||
|
||||
@@ -540,79 +355,14 @@ void JsiDeclarativeEngineInstance::InitConsoleModule()
|
||||
|
||||
// js framework log method
|
||||
shared_ptr<JsValue> aceConsoleObj = runtime_->NewObject();
|
||||
aceConsoleObj->SetProperty(runtime_, "log", runtime_->NewFunction(JsDebugLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "debug", runtime_->NewFunction(JsDebugLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "info", runtime_->NewFunction(JsInfoLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "warn", runtime_->NewFunction(JsWarnLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "error", runtime_->NewFunction(JsErrorLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "log", runtime_->NewFunction(JsiBaseUtils::JsDebugLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "debug", runtime_->NewFunction(JsiBaseUtils::JsDebugLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "info", runtime_->NewFunction(JsiBaseUtils::JsInfoLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "warn", runtime_->NewFunction(JsiBaseUtils::JsWarnLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "error", runtime_->NewFunction(JsiBaseUtils::JsErrorLogPrint));
|
||||
global->SetProperty(runtime_, "aceConsole", aceConsoleObj);
|
||||
}
|
||||
|
||||
std::string GetLogContent(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
std::string content;
|
||||
for (size_t i = 0; i < info->argc; ++i) {
|
||||
if (info->argv[i]->TypeOf() != NATIVE_STRING) {
|
||||
LOGE("argv is not NativeString");
|
||||
continue;
|
||||
}
|
||||
auto nativeString = reinterpret_cast<NativeString*>(info->argv[i]->GetInterface(NativeString::INTERFACE_ID));
|
||||
size_t bufferSize = nativeString->GetLength();
|
||||
size_t strLength = 0;
|
||||
char* buffer = new char[bufferSize + 1] { 0 };
|
||||
nativeString->GetCString(buffer, bufferSize + 1, &strLength);
|
||||
content.append(buffer);
|
||||
delete[] buffer;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
NativeValue* AppLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info, JsLogLevel level)
|
||||
{
|
||||
// Should have at least 1 parameters.
|
||||
if (info->argc == 0) {
|
||||
LOGE("the arg is error");
|
||||
return nativeEngine->CreateUndefined();
|
||||
}
|
||||
std::string content = GetLogContent(nativeEngine, info);
|
||||
switch (level) {
|
||||
case JsLogLevel::DEBUG:
|
||||
APP_LOGD("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::INFO:
|
||||
APP_LOGI("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
APP_LOGW("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
APP_LOGE("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
return nativeEngine->CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* AppDebugLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::DEBUG);
|
||||
}
|
||||
|
||||
NativeValue* AppInfoLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::INFO);
|
||||
}
|
||||
|
||||
NativeValue* AppWarnLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::WARNING);
|
||||
}
|
||||
|
||||
NativeValue* AppErrorLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::ERROR);
|
||||
}
|
||||
|
||||
void JsiDeclarativeEngineInstance::InitConsoleModule(ArkNativeEngine* engine)
|
||||
{
|
||||
ACE_SCOPED_TRACE("JsiDeclarativeEngineInstance::RegisterConsoleModule");
|
||||
@@ -909,7 +659,9 @@ void JsiDeclarativeEngine::Destroy()
|
||||
|
||||
engineInstance_->GetDelegate()->RemoveTaskObserver();
|
||||
if (!runtime_ && nativeEngine_ != nullptr) {
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
|
||||
nativeEngine_->CancelCheckUVLoop();
|
||||
#endif
|
||||
engineInstance_->DestroyAllRootViewHandle();
|
||||
delete nativeEngine_;
|
||||
nativeEngine_ = nullptr;
|
||||
@@ -967,7 +719,9 @@ bool JsiDeclarativeEngine::Initialize(const RefPtr<FrontendDelegate>& delegate)
|
||||
engineInstance_->SetNativeEngine(nativeEngine_);
|
||||
if (!sharedRuntime) {
|
||||
SetPostTask(nativeEngine_);
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
|
||||
nativeEngine_->CheckUVLoop();
|
||||
#endif
|
||||
|
||||
if (delegate && delegate->GetAssetManager()) {
|
||||
std::string packagePath = delegate->GetAssetManager()->GetLibPath();
|
||||
@@ -1026,11 +780,13 @@ void JsiDeclarativeEngine::RegisterInitWorkerFunc()
|
||||
}
|
||||
instance->InitConsoleModule(arkNativeEngine);
|
||||
|
||||
#ifndef WINDOWS_PLATFORM
|
||||
std::vector<uint8_t> buffer((uint8_t*)_binary_jsEnumStyle_abc_start, (uint8_t*)_binary_jsEnumStyle_abc_end);
|
||||
auto stateMgmtResult = arkNativeEngine->RunBufferScript(buffer);
|
||||
if (stateMgmtResult == nullptr) {
|
||||
LOGE("init worker error");
|
||||
}
|
||||
#endif
|
||||
};
|
||||
nativeEngine_->SetInitWorkerFunc(initWorkerFunc);
|
||||
}
|
||||
@@ -1133,6 +889,41 @@ void JsiDeclarativeEngine::LoadJs(const std::string& url, const RefPtr<JsAcePage
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
void JsiDeclarativeEngine::ReplaceJSContent(const std::string& url, const std::string componentName)
|
||||
{
|
||||
ACE_DCHECK(engineInstance_);
|
||||
// replace the component name in the last loadDocument from current js content.
|
||||
std::string::size_type loadDocomentPos = 0;
|
||||
std::string::size_type lastLoadDocomentPos = 0;
|
||||
while ((loadDocomentPos = preContent_.find(COMPONENT_PREVIEW_LOAD_DOCUMENT_NEW, loadDocomentPos))
|
||||
!= std::string::npos) {
|
||||
lastLoadDocomentPos = loadDocomentPos;
|
||||
loadDocomentPos++;
|
||||
}
|
||||
|
||||
std::string::size_type position = lastLoadDocomentPos + LOAD_DOCUMENT_STR_LENGTH;
|
||||
std::string::size_type finalPostion = 0;
|
||||
while ((position = preContent_.find(LEFT_PARENTTHESIS, position)) != std::string::npos) {
|
||||
if (position > loadDocomentPos + LOAD_DOCUMENT_STR_LENGTH) {
|
||||
finalPostion = position;
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
std::string dstReplaceStr = COMPONENT_PREVIEW_LOAD_DOCUMENT_NEW;
|
||||
dstReplaceStr += " " + componentName;
|
||||
preContent_.replace(lastLoadDocomentPos, finalPostion - lastLoadDocomentPos, dstReplaceStr);
|
||||
|
||||
if (engineInstance_ == nullptr) {
|
||||
LOGE("engineInstance is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
engineInstance_->GetDelegate()->Replace(url, "");
|
||||
}
|
||||
#endif
|
||||
|
||||
void JsiDeclarativeEngine::UpdateRunningPage(const RefPtr<JsAcePage>& page)
|
||||
{
|
||||
LOGD("JsiDeclarativeEngine UpdateRunningPage");
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "core/common/ace_application_info.h"
|
||||
#include "core/common/ace_page.h"
|
||||
#include "core/components/xcomponent/native_interface_xcomponent_impl.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/common/js_engine.h"
|
||||
#include "frameworks/bridge/js_frontend/js_ace_page.h"
|
||||
|
||||
@@ -265,6 +265,10 @@ public:
|
||||
return renderContext_;
|
||||
}
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
void ReplaceJSContent(const std::string& url, const std::string componentName) override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool CallAppFunc(const std::string& appFuncName);
|
||||
|
||||
@@ -290,6 +294,10 @@ private:
|
||||
void* runtime_ = nullptr;
|
||||
shared_ptr<JsValue> renderContext_;
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
std::string preContent_ = "";
|
||||
#endif
|
||||
|
||||
ACE_DISALLOW_COPY_AND_MOVE(JsiDeclarativeEngine);
|
||||
};
|
||||
|
||||
|
||||
@@ -586,4 +586,12 @@ void JsiDeclarativeGroupJsBridge::Destroy()
|
||||
runtime_.reset();
|
||||
}
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
void JsiDeclarativeGroupJsBridge::TriggerModuleJsCallbackPreview(
|
||||
int32_t callbackId, int32_t code, ResponseData responseData)
|
||||
{
|
||||
LOGE("Not implemented yet");
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
#include "adapter/preview/osal/request_data.h"
|
||||
#include "adapter/preview/osal/response_data.h"
|
||||
#endif
|
||||
#include "base/memory/ace_type.h"
|
||||
#include "base/utils/singleton.h"
|
||||
#include "frameworks/bridge/codec/standard_function_codec.h"
|
||||
@@ -71,6 +75,10 @@ public:
|
||||
|
||||
void Destroy() override;
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
void TriggerModuleJsCallbackPreview(int32_t callbackId, int32_t code, ResponseData responseData) override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
int32_t GetPendingCallbackIdAndIncrement()
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
int32_t GetLineOffset()
|
||||
int32_t GetLineOffset(const AceType *data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.h"
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/ark_js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "frameworks/base/utils/string_utils.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/ark_js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_ref.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.h"
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
|
||||
#include "base/log/log.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/ark_js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_value.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_value.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "base/utils/noncopyable.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_value.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_value.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_value.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_value.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_value.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_value.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "base/utils/noncopyable.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_value.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_value.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_timer_module.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_syscap_module.h"
|
||||
|
||||
|
||||
@@ -24,9 +24,10 @@
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
std::string ParseRouteUrl(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& arg, const std::string& key)
|
||||
std::string DeclarativeParseRouteUrl(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& arg,
|
||||
const std::string& key)
|
||||
{
|
||||
LOGD("ParseRouteUrl");
|
||||
LOGD("DeclarativeParseRouteUrl");
|
||||
std::string argStr = arg->GetJsonString(runtime);
|
||||
if (argStr.empty()) {
|
||||
return argStr;
|
||||
@@ -37,12 +38,12 @@ std::string ParseRouteUrl(const shared_ptr<JsRuntime>& runtime, const shared_ptr
|
||||
if (argsPtr != nullptr && argsPtr->GetValue(key) != nullptr && argsPtr->GetValue(key)->IsString()) {
|
||||
pageRoute = argsPtr->GetValue(key)->GetString();
|
||||
}
|
||||
LOGD("JsParseRouteUrl pageRoute = %{private}s", pageRoute.c_str());
|
||||
LOGD("JsDeclarativeParseRouteUrl pageRoute = %{private}s", pageRoute.c_str());
|
||||
|
||||
return pageRoute;
|
||||
}
|
||||
|
||||
std::string ParseRouteParams(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& arg,
|
||||
std::string DeclarativeParseRouteParams(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& arg,
|
||||
const std::string& key)
|
||||
{
|
||||
std::string argStr = arg->GetJsonString(runtime);
|
||||
@@ -63,8 +64,8 @@ shared_ptr<JsValue> PagePush(const shared_ptr<JsRuntime>& runtime, const shared_
|
||||
return runtime->NewNull();
|
||||
}
|
||||
|
||||
std::string uri = ParseRouteUrl(runtime, argv[0], ROUTE_KEY_URI);
|
||||
std::string params = ParseRouteParams(runtime, argv[0], ROUTE_KEY_PARAMS);
|
||||
std::string uri = DeclarativeParseRouteUrl(runtime, argv[0], ROUTE_KEY_URI);
|
||||
std::string params = DeclarativeParseRouteParams(runtime, argv[0], ROUTE_KEY_PARAMS);
|
||||
auto delegate = EngineHelper::GetCurrentDelegate();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("get jsi delegate failed");
|
||||
@@ -84,8 +85,8 @@ shared_ptr<JsValue> PageReplace(const shared_ptr<JsRuntime>& runtime, const shar
|
||||
return runtime->NewNull();
|
||||
}
|
||||
|
||||
std::string uri = ParseRouteUrl(runtime, argv[0], ROUTE_KEY_URI);
|
||||
std::string params = ParseRouteParams(runtime, argv[0], ROUTE_KEY_PARAMS);
|
||||
std::string uri = DeclarativeParseRouteUrl(runtime, argv[0], ROUTE_KEY_URI);
|
||||
std::string params = DeclarativeParseRouteParams(runtime, argv[0], ROUTE_KEY_PARAMS);
|
||||
auto delegate = EngineHelper::GetCurrentDelegate();
|
||||
if (delegate == nullptr) {
|
||||
LOGE("get jsi delegate failed");
|
||||
@@ -108,8 +109,8 @@ shared_ptr<JsValue> PageBack(const shared_ptr<JsRuntime>& runtime, const shared_
|
||||
std::string uri;
|
||||
std::string params;
|
||||
if (argc == 1) {
|
||||
uri = ParseRouteUrl(runtime, argv[0], ROUTE_KEY_URI);
|
||||
params = ParseRouteParams(runtime, argv[0], ROUTE_KEY_PARAMS);
|
||||
uri = DeclarativeParseRouteUrl(runtime, argv[0], ROUTE_KEY_URI);
|
||||
params = DeclarativeParseRouteParams(runtime, argv[0], ROUTE_KEY_PARAMS);
|
||||
}
|
||||
auto delegate = EngineHelper::GetCurrentDelegate();
|
||||
if (delegate == nullptr) {
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_value.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_value.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "base/utils/noncopyable.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_value.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_value.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
class JsiSyscapModule {
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "base/utils/noncopyable.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_value.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_value.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
}
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
void ReplaceJSContent(const std::string& url, const std::string componentName);
|
||||
void ReplaceJSContent(const std::string& url, const std::string componentName) override;
|
||||
#endif
|
||||
|
||||
RefPtr<NativeXComponentImpl> nativeXComponentImpl_;
|
||||
|
||||
@@ -242,6 +242,14 @@ public:
|
||||
static PixelMapNapiEntry GetPixelMapNapiEntry();
|
||||
#endif
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
virtual void ReplaceJSContent(const std::string& url, const std::string componentName)
|
||||
{
|
||||
LOGE("V8 does not support replaceJSContent");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
NativeEngine* nativeEngine_ = nullptr;
|
||||
std::function<void(JsEngine*)> mediaUpdateCallback_;
|
||||
|
||||
@@ -46,11 +46,28 @@ template("js_engine_ark") {
|
||||
"jsi_list_bridge.cpp",
|
||||
"jsi_offscreen_canvas_bridge.cpp",
|
||||
"jsi_stepper_bridge.cpp",
|
||||
"jsi_utils.cpp",
|
||||
"jsi_xcomponent_bridge.cpp",
|
||||
]
|
||||
|
||||
deps = [ "//third_party/jsframework:ark_build" ]
|
||||
if (defined(config.use_build_in_js_engine) &&
|
||||
config.use_build_in_js_engine) {
|
||||
defines += [ "BUILT_IN_JS_ENGINE" ]
|
||||
}
|
||||
|
||||
deps = []
|
||||
if (defined(config.build_for_preview) && config.build_for_preview) {
|
||||
sources += [ "jsi_utils_windows.cpp" ]
|
||||
deps +=
|
||||
[ "//foundation/ace/napi/native_engine/impl/ark:ace_napi_impl_ark" ]
|
||||
} else {
|
||||
sources += [ "jsi_utils.cpp" ]
|
||||
deps += [ "//third_party/jsframework:ark_build" ]
|
||||
external_deps = [
|
||||
"multimedia_image_standard:image",
|
||||
"multimedia_image_standard:image_native",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
}
|
||||
if (target_cpu == "arm64") {
|
||||
defines += [ "APP_USE_ARM64" ]
|
||||
} else if (target_cpu == "arm") {
|
||||
@@ -60,11 +77,6 @@ template("js_engine_ark") {
|
||||
"//ark/js_runtime:libark_jsruntime",
|
||||
"//foundation/ace/napi:ace_napi_ark",
|
||||
]
|
||||
external_deps = [
|
||||
"multimedia_image_standard:image",
|
||||
"multimedia_image_standard:image_native",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,10 @@ bool ArkJSRuntime::Initialize(const std::string &libraryPath, bool isDebugMode)
|
||||
LOGI("Ark: create jsvm");
|
||||
RuntimeOption option;
|
||||
option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC);
|
||||
#ifndef WINDOWS_PLATFORM
|
||||
option.SetArkProperties(SystemProperties::GetArkProperties());
|
||||
option.SetAsmInterOption(SystemProperties::GetAsmInterOption());
|
||||
#endif
|
||||
const int64_t poolSize = 0x10000000; // 256M
|
||||
option.SetGcPoolSize(poolSize);
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
@@ -54,11 +56,23 @@ bool ArkJSRuntime::Initialize(const std::string &libraryPath, bool isDebugMode)
|
||||
return vm_ != nullptr;
|
||||
}
|
||||
|
||||
bool ArkJSRuntime::InitializeFromExistVM(EcmaVM* vm)
|
||||
{
|
||||
vm_ = vm;
|
||||
usingExistVM_ = true;
|
||||
LOGI("InitializeFromExistVM %{public}p", vm);
|
||||
return vm_ != nullptr;
|
||||
}
|
||||
|
||||
void ArkJSRuntime::Reset()
|
||||
{
|
||||
if (vm_ != nullptr) {
|
||||
JSNApi::StopDebugger(libPath_.c_str());
|
||||
JSNApi::DestroyJSVM(vm_);
|
||||
if (!usingExistVM_) {
|
||||
#ifndef WINDOWS_PLATFORM
|
||||
JSNApi::StopDebugger(libPath_.c_str());
|
||||
#endif
|
||||
JSNApi::DestroyJSVM(vm_);
|
||||
}
|
||||
vm_ = nullptr;
|
||||
}
|
||||
for (auto data : dataList_) {
|
||||
@@ -91,7 +105,9 @@ bool ArkJSRuntime::ExecuteJsBin(const std::string &fileName)
|
||||
JSExecutionScope executionScope(vm_);
|
||||
static bool debugFlag = true;
|
||||
if (debugFlag && !libPath_.empty()) {
|
||||
#ifndef WINDOWS_PLATFORM
|
||||
JSNApi::StartDebugger(libPath_.c_str(), vm_, isDebugMode_);
|
||||
#endif
|
||||
debugFlag = false;
|
||||
}
|
||||
LocalScope scope(vm_);
|
||||
|
||||
@@ -50,7 +50,11 @@ class PandaFunctionData;
|
||||
// NOLINTNEXTLINE(fuchsia-multiple-inheritance)
|
||||
class ArkJSRuntime final : public JsRuntime, public std::enable_shared_from_this<ArkJSRuntime> {
|
||||
public:
|
||||
#if !defined(WINDOWS_PLATFORM)
|
||||
bool StartDebugger(const char *libraryPath, EcmaVM *vm) const;
|
||||
#endif
|
||||
bool Initialize(const std::string &libraryPath, bool isDebugMode) override;
|
||||
bool InitializeFromExistVM(EcmaVM* vm);
|
||||
void Reset() override;
|
||||
void SetLogPrint(LOG_PRINT out) override;
|
||||
shared_ptr<JsValue> EvaluateJsCode(const std::string &src) override;
|
||||
@@ -85,7 +89,8 @@ private:
|
||||
LOG_PRINT print_ { nullptr };
|
||||
UncaughtExceptionCallback uncaughtErrorHandler_ { nullptr };
|
||||
std::string libPath_ {};
|
||||
bool isDebugMode_ {true};
|
||||
bool usingExistVM_ = false;
|
||||
bool isDebugMode_ = true;
|
||||
};
|
||||
|
||||
class PandaFunctionData {
|
||||
|
||||
@@ -62,7 +62,7 @@ std::string JsiBaseUtils::GenerateSummaryBody(std::shared_ptr<JsValue> error, st
|
||||
summaryBody.append("Stacktrace:\n");
|
||||
|
||||
if (pageMap || appMap) {
|
||||
std::string tempStack = JsiDumpSourceFile(stackStr, pageMap, appMap);
|
||||
std::string tempStack = JsiDumpSourceFile(stackStr, pageMap, appMap, data);
|
||||
summaryBody.append(tempStack);
|
||||
} else {
|
||||
summaryBody.append("Cannot get SourceMap info, dump raw stack:\n");
|
||||
@@ -101,7 +101,7 @@ std::string JsiBaseUtils::TransSourceStack(RefPtr<JsAcePage> runningPage, const
|
||||
}
|
||||
|
||||
std::string JsiBaseUtils::JsiDumpSourceFile(const std::string& stackStr, const RefPtr<RevSourceMap>& pageMap,
|
||||
const RefPtr<RevSourceMap>& appMap)
|
||||
const RefPtr<RevSourceMap>& appMap, const AceType *data)
|
||||
{
|
||||
std::string ans = "";
|
||||
std::string tempStack = stackStr;
|
||||
@@ -124,7 +124,7 @@ std::string JsiBaseUtils::JsiDumpSourceFile(const std::string& stackStr, const R
|
||||
break;
|
||||
}
|
||||
|
||||
const std::string sourceInfo = GetSourceInfo(line, column, pageMap, appMap, isAppPage);
|
||||
const std::string sourceInfo = GetSourceInfo(line, column, pageMap, appMap, isAppPage, data);
|
||||
if (sourceInfo.empty()) {
|
||||
break;
|
||||
}
|
||||
@@ -175,9 +175,9 @@ void JsiBaseUtils::GetPosInfo(const std::string& temp, std::string& line, std::s
|
||||
}
|
||||
|
||||
std::string JsiBaseUtils::GetSourceInfo(const std::string& line, const std::string& column,
|
||||
const RefPtr<RevSourceMap>& pageMap, const RefPtr<RevSourceMap>& appMap, bool isAppPage)
|
||||
const RefPtr<RevSourceMap>& pageMap, const RefPtr<RevSourceMap>& appMap, bool isAppPage, const AceType *data)
|
||||
{
|
||||
int32_t offSet = GetLineOffset();
|
||||
int32_t offSet = GetLineOffset(data);
|
||||
std::string sourceInfo;
|
||||
MappingInfo mapInfo;
|
||||
if (isAppPage) {
|
||||
@@ -219,4 +219,261 @@ void JsiBaseUtils::ReportJsErrorEvent(std::shared_ptr<JsValue> error, std::share
|
||||
LOGE("summaryBody: \n%{public}s", summaryBody.c_str());
|
||||
EventReport::JsErrReport(AceApplicationInfo::GetInstance().GetPackageName(), "", summaryBody);
|
||||
}
|
||||
|
||||
std::string ParseLogContent(const std::vector<std::string>& params)
|
||||
{
|
||||
std::string ret;
|
||||
if (params.empty()) {
|
||||
return ret;
|
||||
}
|
||||
std::string formatStr = params[0];
|
||||
int32_t size = static_cast<int32_t>(params.size());
|
||||
int32_t len = static_cast<int32_t>(formatStr.size());
|
||||
int32_t pos = 0;
|
||||
int32_t count = 1;
|
||||
for (; pos < len; ++pos) {
|
||||
if (count >= size) {
|
||||
break;
|
||||
}
|
||||
if (formatStr[pos] == '%') {
|
||||
if (pos + 1 >= len) {
|
||||
break;
|
||||
}
|
||||
switch (formatStr[pos + 1]) {
|
||||
case 's':
|
||||
case 'j':
|
||||
case 'd':
|
||||
case 'O':
|
||||
case 'o':
|
||||
case 'i':
|
||||
case 'f':
|
||||
case 'c':
|
||||
ret += params[count++];
|
||||
++pos;
|
||||
break;
|
||||
case '%':
|
||||
ret += formatStr[pos];
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
ret += formatStr[pos];
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ret += formatStr[pos];
|
||||
}
|
||||
}
|
||||
if (pos < len) {
|
||||
ret += formatStr.substr(pos, len - pos);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string GetLogContent(
|
||||
const shared_ptr<JsRuntime>& runtime, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
if (argc == 1) {
|
||||
return argv[0]->ToString(runtime);
|
||||
}
|
||||
std::vector<std::string> params;
|
||||
for (int32_t i = 0; i < argc; ++i) {
|
||||
params.emplace_back(argv[i]->ToString(runtime));
|
||||
}
|
||||
return ParseLogContent(params);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> AppLogPrint(
|
||||
const shared_ptr<JsRuntime>& runtime, JsLogLevel level, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
// Should have at least 1 parameters.
|
||||
if (argc == 0) {
|
||||
LOGE("the arg is error");
|
||||
return runtime->NewUndefined();
|
||||
}
|
||||
std::string content = GetLogContent(runtime, argv, argc);
|
||||
switch (level) {
|
||||
case JsLogLevel::DEBUG:
|
||||
APP_LOGD("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::INFO:
|
||||
APP_LOGI("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
APP_LOGW("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
APP_LOGE("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
return runtime->NewUndefined();
|
||||
}
|
||||
|
||||
// native implementation for js function: console.debug()
|
||||
shared_ptr<JsValue> JsiBaseUtils::AppDebugLogPrint(const shared_ptr<JsRuntime>& runtime,
|
||||
const shared_ptr<JsValue>& thisObj, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::DEBUG, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: console.info()
|
||||
shared_ptr<JsValue> JsiBaseUtils::AppInfoLogPrint(const shared_ptr<JsRuntime>& runtime,
|
||||
const shared_ptr<JsValue>& thisObj, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::INFO, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: console.warn()
|
||||
shared_ptr<JsValue> JsiBaseUtils::AppWarnLogPrint(const shared_ptr<JsRuntime>& runtime,
|
||||
const shared_ptr<JsValue>& thisObj, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::WARNING, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: console.error()
|
||||
shared_ptr<JsValue> JsiBaseUtils::AppErrorLogPrint(const shared_ptr<JsRuntime>& runtime,
|
||||
const shared_ptr<JsValue>& thisObj, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::ERROR, argv, argc);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> JsLogPrint(
|
||||
const shared_ptr<JsRuntime>& runtime, JsLogLevel level, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
// Should have 1 parameters.
|
||||
if (argc == 0) {
|
||||
LOGE("the arg is error");
|
||||
return runtime->NewUndefined();
|
||||
}
|
||||
|
||||
std::string content = GetLogContent(runtime, argv, argc);
|
||||
switch (level) {
|
||||
case JsLogLevel::DEBUG:
|
||||
LOGD("ace Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::INFO:
|
||||
LOGI("ace Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
LOGW("ace Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
LOGE("ace Log: %{public}s", content.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ret = runtime->NewUndefined();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int PrintLog(int id, int level, const char* tag, const char* fmt, const char* message)
|
||||
{
|
||||
switch (JsLogLevel(level - 3)) {
|
||||
case JsLogLevel::INFO:
|
||||
LOGI("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
LOGW("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
LOGE("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
case JsLogLevel::DEBUG:
|
||||
LOGD("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
default:
|
||||
LOGF("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> JsiBaseUtils::JsDebugLogPrint(const shared_ptr<JsRuntime>& runtime,
|
||||
const shared_ptr<JsValue>& thisObj, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return JsLogPrint(runtime, JsLogLevel::DEBUG, std::move(argv), argc);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> JsiBaseUtils::JsInfoLogPrint(const shared_ptr<JsRuntime>& runtime,
|
||||
const shared_ptr<JsValue>& thisObj, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return JsLogPrint(runtime, JsLogLevel::INFO, std::move(argv), argc);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> JsiBaseUtils::JsWarnLogPrint(const shared_ptr<JsRuntime>& runtime,
|
||||
const shared_ptr<JsValue>& thisObj, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return JsLogPrint(runtime, JsLogLevel::WARNING, std::move(argv), argc);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> JsiBaseUtils::JsErrorLogPrint(const shared_ptr<JsRuntime>& runtime,
|
||||
const shared_ptr<JsValue>& thisObj, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return JsLogPrint(runtime, JsLogLevel::ERROR, std::move(argv), argc);
|
||||
}
|
||||
|
||||
std::string GetLogContent(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
std::string content;
|
||||
for (size_t i = 0; i < info->argc; ++i) {
|
||||
if (info->argv[i]->TypeOf() != NATIVE_STRING) {
|
||||
LOGE("argv is not NativeString");
|
||||
continue;
|
||||
}
|
||||
auto nativeString = reinterpret_cast<NativeString*>(info->argv[i]->GetInterface(NativeString::INTERFACE_ID));
|
||||
size_t bufferSize = nativeString->GetLength();
|
||||
size_t strLength = 0;
|
||||
char* buffer = new char[bufferSize + 1] { 0 };
|
||||
nativeString->GetCString(buffer, bufferSize + 1, &strLength);
|
||||
content.append(buffer);
|
||||
delete[] buffer;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
NativeValue* AppLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info, JsLogLevel level)
|
||||
{
|
||||
// Should have at least 1 parameters.
|
||||
if (info->argc == 0) {
|
||||
LOGE("the arg is error");
|
||||
return nativeEngine->CreateUndefined();
|
||||
}
|
||||
std::string content = GetLogContent(nativeEngine, info);
|
||||
switch (level) {
|
||||
case JsLogLevel::DEBUG:
|
||||
APP_LOGD("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::INFO:
|
||||
APP_LOGI("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
APP_LOGW("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
APP_LOGE("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
return nativeEngine->CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* AppDebugLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::DEBUG);
|
||||
}
|
||||
|
||||
NativeValue* AppInfoLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::INFO);
|
||||
}
|
||||
|
||||
NativeValue* AppWarnLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::WARNING);
|
||||
}
|
||||
|
||||
NativeValue* AppErrorLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::ERROR);
|
||||
}
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
||||
@@ -16,27 +16,60 @@
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_JSI_BASE_UTILS_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_JSI_BASE_UTILS_H
|
||||
|
||||
#include "frameworks/base/log/ace_trace.h"
|
||||
#include "frameworks/base/log/event_report.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/common/runtime_constants.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/jsi_engine.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_runtime.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/js_value.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
int32_t GetLineOffset();
|
||||
int32_t GetLineOffset(const AceType *data);
|
||||
RefPtr<JsAcePage> GetRunningPage(const AceType *data);
|
||||
NativeValue* AppDebugLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info);
|
||||
NativeValue* AppInfoLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info);
|
||||
NativeValue* AppWarnLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info);
|
||||
NativeValue* AppErrorLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info);
|
||||
int PrintLog(int id, int level, const char* tag, const char* fmt, const char* message);
|
||||
|
||||
class JsiBaseUtils {
|
||||
public:
|
||||
static void ReportJsErrorEvent(std::shared_ptr<JsValue> error, std::shared_ptr<JsRuntime> runtime);
|
||||
static std::string TransSourceStack(RefPtr<JsAcePage> runningPage, const std::string& rawStack);
|
||||
// native implementation for js function: console.debug()
|
||||
static shared_ptr<JsValue> AppDebugLogPrint(const shared_ptr<JsRuntime>& runtime,
|
||||
const shared_ptr<JsValue>& thisObj, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc);
|
||||
// native implementation for js function: console.info()
|
||||
static shared_ptr<JsValue> AppInfoLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc);
|
||||
// native implementation for js function: console.warn()
|
||||
static shared_ptr<JsValue> AppWarnLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc);
|
||||
// native implementation for js function: console.error()
|
||||
static shared_ptr<JsValue> AppErrorLogPrint(const shared_ptr<JsRuntime>& runtime,
|
||||
const shared_ptr<JsValue>& thisObj, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc);
|
||||
|
||||
// native implementation for js function: aceConsole.debug()
|
||||
static shared_ptr<JsValue> JsDebugLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc);
|
||||
// native implementation for js function: aceConsole.info()
|
||||
static shared_ptr<JsValue> JsInfoLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc);
|
||||
// native implementation for js function: aceConsole.warn()
|
||||
static shared_ptr<JsValue> JsWarnLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc);
|
||||
// native implementation for js function: aceConsole.error()
|
||||
static shared_ptr<JsValue> JsErrorLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc);
|
||||
|
||||
private:
|
||||
static std::string GenerateSummaryBody(std::shared_ptr<JsValue> error, std::shared_ptr<JsRuntime> runtime);
|
||||
static std::string JsiDumpSourceFile(const std::string& stackStr, const RefPtr<RevSourceMap>& pageMap,
|
||||
const RefPtr<RevSourceMap>& appMap);
|
||||
const RefPtr<RevSourceMap>& appMap, const AceType *data = nullptr);
|
||||
static void ExtractEachInfo(const std::string& tempStack, std::vector<std::string>& res);
|
||||
static void GetPosInfo(const std::string& temp, std::string& line, std::string& column);
|
||||
static std::string GetSourceInfo(const std::string& line, const std::string& column,
|
||||
const RefPtr<RevSourceMap>& pageMap, const RefPtr<RevSourceMap>& appMap, bool isAppPage);
|
||||
const RefPtr<RevSourceMap>& pageMap, const RefPtr<RevSourceMap>& appMap, bool isAppPage, const AceType *data);
|
||||
static std::string GetRelativePath(const std::string& sources);
|
||||
};
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
||||
@@ -329,7 +329,9 @@ void JsiCanvasBridge::HandleJsContext(const shared_ptr<JsRuntime>& runtime, Node
|
||||
{ "createImageData", JsCreateImageData },
|
||||
{ "putImageData", JsPutImageData },
|
||||
{ "getImageData", JsGetImageData },
|
||||
#ifdef PIXEL_MAP_SUPPORTED
|
||||
{ "getPixelMap", JsGetPixelMap },
|
||||
#endif
|
||||
{ "getJsonData", JsGetJsonData },
|
||||
{ "transferFromImageBitmap", JsTransferFromImageBitmap },
|
||||
{ "drawBitmapMesh", JsDrawBitmapMesh },
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/jsi_engine.h"
|
||||
|
||||
#ifndef WINDOWS_PLATFORM
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
#include <regex>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -2156,202 +2158,6 @@ shared_ptr<JsValue> JsCallComponent(const shared_ptr<JsRuntime>& runtime, const
|
||||
return resultValue;
|
||||
}
|
||||
|
||||
std::string ParseLogContent(const std::vector<std::string>& params)
|
||||
{
|
||||
std::string ret;
|
||||
if (params.empty()) {
|
||||
return ret;
|
||||
}
|
||||
std::string formatStr = params[0];
|
||||
size_t size = params.size();
|
||||
size_t len = formatStr.size();
|
||||
size_t pos = 0;
|
||||
int32_t count = 1;
|
||||
for (; pos < len; ++pos) {
|
||||
if (static_cast<uint32_t>(count) >= size) {
|
||||
break;
|
||||
}
|
||||
if (formatStr[pos] == '%') {
|
||||
if (pos + 1 >= len) {
|
||||
break;
|
||||
}
|
||||
switch (formatStr[pos + 1]) {
|
||||
case 's':
|
||||
case 'j':
|
||||
case 'd':
|
||||
case 'O':
|
||||
case 'o':
|
||||
case 'i':
|
||||
case 'f':
|
||||
case 'c':
|
||||
ret += params[count++];
|
||||
++pos;
|
||||
break;
|
||||
case '%':
|
||||
ret += formatStr[pos];
|
||||
++pos;
|
||||
break;
|
||||
default:
|
||||
ret += formatStr[pos];
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ret += formatStr[pos];
|
||||
}
|
||||
}
|
||||
if (pos < len) {
|
||||
ret += formatStr.substr(pos, len - pos);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string GetLogContent(
|
||||
const shared_ptr<JsRuntime>& runtime, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
if (argc == 1) {
|
||||
return argv[0]->ToString(runtime);
|
||||
}
|
||||
std::vector<std::string> params;
|
||||
for (int32_t i = 0; i < argc; ++i) {
|
||||
params.emplace_back(argv[i]->ToString(runtime));
|
||||
}
|
||||
return ParseLogContent(params);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> AppLogPrint(
|
||||
const shared_ptr<JsRuntime>& runtime, JsLogLevel level, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
// Should have at least 1 parameters.
|
||||
if (argc == 0) {
|
||||
LOGE("the arg is error");
|
||||
return runtime->NewUndefined();
|
||||
}
|
||||
std::string content = GetLogContent(runtime, argv, argc);
|
||||
switch (level) {
|
||||
case JsLogLevel::DEBUG:
|
||||
APP_LOGD("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::INFO:
|
||||
APP_LOGI("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
APP_LOGW("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
APP_LOGE("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
return runtime->NewUndefined();
|
||||
}
|
||||
|
||||
// native implementation for js function: console.debug()
|
||||
shared_ptr<JsValue> AppDebugLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::DEBUG, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: console.info()
|
||||
shared_ptr<JsValue> AppInfoLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::INFO, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: console.warn()
|
||||
shared_ptr<JsValue> AppWarnLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::WARNING, argv, argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: console.error()
|
||||
shared_ptr<JsValue> AppErrorLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return AppLogPrint(runtime, JsLogLevel::ERROR, argv, argc);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> JsLogPrint(
|
||||
const shared_ptr<JsRuntime>& runtime, JsLogLevel level, const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
// Should have 1 parameters.
|
||||
if (argc == 0) {
|
||||
LOGE("the arg is error");
|
||||
return runtime->NewUndefined();
|
||||
}
|
||||
|
||||
std::string content = GetLogContent(runtime, argv, argc);
|
||||
switch (level) {
|
||||
case JsLogLevel::DEBUG:
|
||||
LOGD("ace Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::INFO:
|
||||
LOGI("ace Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
LOGW("ace Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
LOGE("ace Log: %{public}s", content.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> ret = runtime->NewUndefined();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int PrintLog(int id, int level, const char* tag, const char* fmt, const char* message)
|
||||
{
|
||||
switch (JsLogLevel(level - 3)) {
|
||||
case JsLogLevel::INFO:
|
||||
LOGI("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
LOGW("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
LOGE("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
case JsLogLevel::DEBUG:
|
||||
LOGD("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
default:
|
||||
LOGF("%{public}s::%{public}s", tag, message);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// native implementation for js function: aceConsole.debug()
|
||||
shared_ptr<JsValue> JsDebugLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return JsLogPrint(runtime, JsLogLevel::DEBUG, std::move(argv), argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: aceConsole.info()
|
||||
shared_ptr<JsValue> JsInfoLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return JsLogPrint(runtime, JsLogLevel::INFO, std::move(argv), argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: aceConsole.warn()
|
||||
shared_ptr<JsValue> JsWarnLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return JsLogPrint(runtime, JsLogLevel::WARNING, std::move(argv), argc);
|
||||
}
|
||||
|
||||
// native implementation for js function: aceConsole.error()
|
||||
shared_ptr<JsValue> JsErrorLogPrint(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
return JsLogPrint(runtime, JsLogLevel::ERROR, std::move(argv), argc);
|
||||
}
|
||||
|
||||
int GetNodeId(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& arg)
|
||||
{
|
||||
int32_t id = 0;
|
||||
@@ -2764,89 +2570,24 @@ void JsiEngineInstance::RegisterConsoleModule()
|
||||
|
||||
// app log method
|
||||
shared_ptr<JsValue> consoleObj = runtime_->NewObject();
|
||||
consoleObj->SetProperty(runtime_, "log", runtime_->NewFunction(AppDebugLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "debug", runtime_->NewFunction(AppDebugLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "info", runtime_->NewFunction(AppInfoLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "warn", runtime_->NewFunction(AppWarnLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "error", runtime_->NewFunction(AppErrorLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "log", runtime_->NewFunction(JsiBaseUtils::AppDebugLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "debug", runtime_->NewFunction(JsiBaseUtils::AppDebugLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "info", runtime_->NewFunction(JsiBaseUtils::AppInfoLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "warn", runtime_->NewFunction(JsiBaseUtils::AppWarnLogPrint));
|
||||
consoleObj->SetProperty(runtime_, "error", runtime_->NewFunction(JsiBaseUtils::AppErrorLogPrint));
|
||||
global->SetProperty(runtime_, "console", consoleObj);
|
||||
|
||||
// js framework log method
|
||||
shared_ptr<JsValue> aceConsoleObj = runtime_->NewObject();
|
||||
aceConsoleObj->SetProperty(runtime_, "log", runtime_->NewFunction(JsDebugLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "debug", runtime_->NewFunction(JsDebugLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "info", runtime_->NewFunction(JsInfoLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "warn", runtime_->NewFunction(JsWarnLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "error", runtime_->NewFunction(JsErrorLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "log", runtime_->NewFunction(JsiBaseUtils::JsDebugLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "debug", runtime_->NewFunction(JsiBaseUtils::JsDebugLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "info", runtime_->NewFunction(JsiBaseUtils::JsInfoLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "warn", runtime_->NewFunction(JsiBaseUtils::JsWarnLogPrint));
|
||||
aceConsoleObj->SetProperty(runtime_, "error", runtime_->NewFunction(JsiBaseUtils::JsErrorLogPrint));
|
||||
global->SetProperty(runtime_, "aceConsole", aceConsoleObj);
|
||||
global->SetProperty(runtime_, "callNativeHandler", runtime_->NewFunction(JsCallNativeHandler));
|
||||
}
|
||||
|
||||
std::string GetLogContent(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
std::string content;
|
||||
for (size_t i = 0; i < info->argc; ++i) {
|
||||
if (info->argv[i]->TypeOf() != NATIVE_STRING) {
|
||||
LOGE("argv is not NativeString");
|
||||
continue;
|
||||
}
|
||||
auto nativeString = reinterpret_cast<NativeString*>(info->argv[i]->GetInterface(NativeString::INTERFACE_ID));
|
||||
size_t bufferSize = nativeString->GetLength();
|
||||
size_t strLength = 0;
|
||||
char* buffer = new char[bufferSize + 1] { 0 };
|
||||
nativeString->GetCString(buffer, bufferSize + 1, &strLength);
|
||||
content.append(buffer);
|
||||
delete[] buffer;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
NativeValue* AppLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info, JsLogLevel level)
|
||||
{
|
||||
// Should have at least 1 parameters.
|
||||
if (info->argc == 0) {
|
||||
LOGE("the arg is error");
|
||||
return nativeEngine->CreateUndefined();
|
||||
}
|
||||
std::string content = GetLogContent(nativeEngine, info);
|
||||
switch (level) {
|
||||
case JsLogLevel::DEBUG:
|
||||
APP_LOGD("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::INFO:
|
||||
APP_LOGI("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::WARNING:
|
||||
APP_LOGW("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
case JsLogLevel::ERROR:
|
||||
APP_LOGE("app Log: %{public}s", content.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
return nativeEngine->CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* AppDebugLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::DEBUG);
|
||||
}
|
||||
|
||||
NativeValue* AppInfoLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::INFO);
|
||||
}
|
||||
|
||||
NativeValue* AppWarnLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::WARNING);
|
||||
}
|
||||
|
||||
NativeValue* AppErrorLogPrint(NativeEngine* nativeEngine, NativeCallbackInfo* info)
|
||||
{
|
||||
return AppLogPrint(nativeEngine, info, JsLogLevel::ERROR);
|
||||
}
|
||||
|
||||
void JsiEngineInstance::RegisterConsoleModule(ArkNativeEngine* engine)
|
||||
{
|
||||
ACE_SCOPED_TRACE("JsiEngineInstance::RegisterConsoleModule");
|
||||
@@ -3076,7 +2817,9 @@ bool JsiEngine::Initialize(const RefPtr<FrontendDelegate>& delegate)
|
||||
nativeEngine_ = nativeEngine;
|
||||
engineInstance_->SetNativeEngine(nativeEngine_);
|
||||
SetPostTask(nativeEngine_);
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
|
||||
nativeEngine_->CheckUVLoop();
|
||||
#endif
|
||||
|
||||
ACE_DCHECK(delegate);
|
||||
if (delegate && delegate->GetAssetManager()) {
|
||||
@@ -3176,7 +2919,9 @@ JsiEngine::~JsiEngine()
|
||||
{
|
||||
LOG_DESTROY();
|
||||
if (nativeEngine_ != nullptr) {
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
|
||||
nativeEngine_->CancelCheckUVLoop();
|
||||
#endif
|
||||
delete nativeEngine_;
|
||||
nativeEngine_ = nullptr;
|
||||
}
|
||||
|
||||
@@ -584,4 +584,12 @@ void JsiGroupJsBridge::Destroy()
|
||||
runtime_.reset();
|
||||
}
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
void JsiGroupJsBridge::TriggerModuleJsCallbackPreview(
|
||||
int32_t callbackId, int32_t code, OHOS::Ace::ResponseData responseData)
|
||||
{
|
||||
LOGE("WAIT FOR IMPLEMENTED");
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
#include "adapter/preview/osal/request_data.h"
|
||||
#include "adapter/preview/osal/response_data.h"
|
||||
#endif
|
||||
#include "base/memory/ace_type.h"
|
||||
#include "base/utils/singleton.h"
|
||||
#include "frameworks/bridge/codec/standard_function_codec.h"
|
||||
@@ -65,6 +69,11 @@ public:
|
||||
|
||||
void TriggerEventJsCallback(int32_t callbackId, int32_t code, std::vector<uint8_t>&& eventData) override;
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
void TriggerModuleJsCallbackPreview(
|
||||
int32_t callbackId, int32_t code, OHOS::Ace::ResponseData responseData) override;
|
||||
#endif
|
||||
|
||||
void LoadPluginJsCode(std::string&& jsCode) override;
|
||||
|
||||
void LoadPluginJsByteCode(std::vector<uint8_t>&& jsCode, std::vector<int32_t>&& jsCodeLen) override;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/jsi_engine.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
int32_t GetLineOffset()
|
||||
int32_t GetLineOffset(const AceType *data)
|
||||
{
|
||||
const int32_t offset = 14;
|
||||
return offset;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/jsi_base_utils.h"
|
||||
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/jsi_engine.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
int32_t GetLineOffset(const AceType *data)
|
||||
{
|
||||
if (AceType::InstanceOf<JsiEngineInstance>(data)) {
|
||||
const int32_t jsiOffset = 14;
|
||||
return jsiOffset;
|
||||
}
|
||||
if (AceType::InstanceOf<JsiDeclarativeEngineInstance>(data)) {
|
||||
const int32_t jsiDeclarativeOffset = 0;
|
||||
return jsiDeclarativeOffset;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RefPtr<JsAcePage> GetRunningPage(const AceType *data)
|
||||
{
|
||||
if (data == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (AceType::InstanceOf<JsiEngineInstance>(data)) {
|
||||
auto instance = static_cast<const JsiEngineInstance *>(data);
|
||||
return instance->GetRunningPage();
|
||||
}
|
||||
if (AceType::InstanceOf<JsiDeclarativeEngineInstance>(data)) {
|
||||
auto instance = static_cast<const JsiDeclarativeEngineInstance *>(data);
|
||||
return instance->GetRunningPage();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace OHOS::Ace::Framework
|
||||
Reference in New Issue
Block a user