mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-19 22:54:50 -04:00
@@ -19,6 +19,7 @@ import("//foundation/ace/ace_engine/build/ace_gen_obj.gni")
|
||||
base_output_path = get_label_info(":gen_abc_proxyclass", "target_out_dir")
|
||||
abcproxyclass_obj_path = base_output_path + "/abc_proxy_class.o"
|
||||
abcenumstyle_obj_path = base_output_path + "/abc_enum_style.o"
|
||||
jsmocksystemplugin_obj_path = base_output_path + "/abc_js_mock_system_plugin.o"
|
||||
|
||||
ts2abc_gen_abc("gen_stateMgmt_abc") {
|
||||
extra_visibility = [ ":*" ] # Only targets in this file can depend on this.
|
||||
@@ -40,6 +41,16 @@ ts2abc_gen_abc("gen_jsEnumStyle_abc") {
|
||||
out_puts = [ base_output_path + "/jsEnumStyle.abc" ]
|
||||
}
|
||||
|
||||
ts2abc_gen_abc("gen_js_mock_system_plugin_abc") {
|
||||
extra_visibility = [ ":*" ] # Only targets in this file can depend on this.
|
||||
src_js = rebase_path(
|
||||
"//foundation/ace/ace_engine/frameworks/bridge/declarative_frontend/engine/quickjs/jsMockSystemPlugin.js")
|
||||
dst_file = rebase_path(base_output_path + "/jsMockSystemPlugin.abc")
|
||||
|
||||
in_puts = [ "//foundation/ace/ace_engine/frameworks/bridge/declarative_frontend/engine/quickjs/jsMockSystemPlugin.js" ]
|
||||
out_puts = [ base_output_path + "/jsMockSystemPlugin.abc" ]
|
||||
}
|
||||
|
||||
gen_obj("abc_proxyclass") {
|
||||
input = base_output_path + "/stateMgmt.abc"
|
||||
if (use_mac || use_mingw_win) {
|
||||
@@ -51,10 +62,22 @@ gen_obj("abc_proxyclass") {
|
||||
|
||||
gen_obj("abc_enum_style") {
|
||||
input = base_output_path + "/jsEnumStyle.abc"
|
||||
if (use_mac || use_mingw_win) {
|
||||
abcenumstyle_obj_path = base_output_path + "/jsEnumStyle.c"
|
||||
}
|
||||
output = abcenumstyle_obj_path
|
||||
snapshot_dep = [ ":gen_jsEnumStyle_abc" ]
|
||||
}
|
||||
|
||||
gen_obj("abc_mock_system_plugin") {
|
||||
input = base_output_path + "/jsMockSystemPlugin.abc"
|
||||
if (use_mac || use_mingw_win) {
|
||||
jsmocksystemplugin_obj_path = base_output_path + "/js_mock_system_plugin.c"
|
||||
}
|
||||
output = jsmocksystemplugin_obj_path
|
||||
snapshot_dep = [ ":gen_js_mock_system_plugin_abc" ]
|
||||
}
|
||||
|
||||
template("declarative_js_engine_ark") {
|
||||
forward_variables_from(invoker, "*")
|
||||
|
||||
@@ -91,6 +114,8 @@ template("declarative_js_engine_ark") {
|
||||
"modules/jsi_timer_module.cpp",
|
||||
]
|
||||
|
||||
deps = [ "//ark/js_runtime:libark_jsruntime" ]
|
||||
|
||||
if (!defined(config.build_for_preview) || !config.build_for_preview) {
|
||||
sources += [
|
||||
"$ace_root/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp",
|
||||
@@ -98,21 +123,18 @@ template("declarative_js_engine_ark") {
|
||||
"$ace_root/frameworks/bridge/js_frontend/engine/jsi/jsi_base_utils.cpp",
|
||||
"jsi_declarative_utils.cpp",
|
||||
]
|
||||
} else {
|
||||
deps += [ ":gen_obj_src_abc_mock_system_plugin" ]
|
||||
}
|
||||
|
||||
deps = [ "//ark/js_runtime:libark_jsruntime" ]
|
||||
|
||||
# if napi support
|
||||
deps += [ "//foundation/ace/napi:ace_napi_ark" ]
|
||||
public_deps = [ "//foundation/ace/napi:ace_napi" ]
|
||||
|
||||
# do not support windows platform
|
||||
if (!is_mingw) {
|
||||
deps += [
|
||||
":gen_obj_src_abc_enum_style",
|
||||
":gen_obj_src_abc_proxyclass",
|
||||
]
|
||||
}
|
||||
deps += [
|
||||
":gen_obj_src_abc_enum_style",
|
||||
":gen_obj_src_abc_proxyclass",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,14 @@
|
||||
#include "frameworks/bridge/js_frontend/engine/common/runtime_constants.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/jsi/jsi_base_utils.h"
|
||||
|
||||
#ifndef WINDOWS_PLATFORM
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_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[];
|
||||
extern const char* _binary_jsMockSystemPlugin_abc_start[];
|
||||
extern const char* _binary_jsMockSystemPlugin_abc_end[];
|
||||
#else
|
||||
extern const char _binary_stateMgmt_abc_start[];
|
||||
extern const char _binary_stateMgmt_abc_end[];
|
||||
extern const char _binary_jsEnumStyle_abc_start[];
|
||||
@@ -206,6 +213,7 @@ bool JsiDeclarativeEngineInstance::InitJsEnv(bool debuggerMode,
|
||||
if (usingSharedRuntime_ && isModuleInitialized_) {
|
||||
LOGI("InitJsEnv SharedRuntime has initialized, skip...");
|
||||
} else {
|
||||
InitGroupJsBridge();
|
||||
if (!isModulePreloaded_ || IsPlugin()) {
|
||||
InitConsoleModule();
|
||||
InitAceModule();
|
||||
@@ -216,7 +224,6 @@ bool JsiDeclarativeEngineInstance::InitJsEnv(bool debuggerMode,
|
||||
if (!isModuleInitialized_) {
|
||||
InitJsContextModuleObject();
|
||||
}
|
||||
InitGroupJsBridge();
|
||||
}
|
||||
|
||||
if (usingSharedRuntime_) {
|
||||
@@ -237,7 +244,6 @@ 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) {
|
||||
@@ -248,6 +254,12 @@ void JsiDeclarativeEngineInstance::InitAceModule()
|
||||
if (!jsEnumStyleResult) {
|
||||
LOGE("EvaluateJsCode jsEnumStyle failed");
|
||||
}
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
bool jsMockSystemPlugin = runtime_->EvaluateJsCode((uint8_t*)_binary_jsMockSystemPlugin_abc_start,
|
||||
_binary_jsMockSystemPlugin_abc_end - _binary_jsMockSystemPlugin_abc_start);
|
||||
if (!jsMockSystemPlugin) {
|
||||
LOGE("EvaluateJsCode jsMockSystemPlugin failed");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -308,7 +320,6 @@ 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);
|
||||
@@ -328,7 +339,6 @@ void JsiDeclarativeEngineInstance::PreloadAceModule(void* runtime)
|
||||
isModulePreloaded_ = evalResult;
|
||||
globalRuntime_ = nullptr;
|
||||
LOGI("PreloadAceModule loaded:%{public}d", isModulePreloaded_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void JsiDeclarativeEngineInstance::InitConsoleModule()
|
||||
@@ -784,13 +794,11 @@ 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);
|
||||
}
|
||||
@@ -821,6 +829,34 @@ void JsiDeclarativeEngine::RegisterWorker()
|
||||
RegisterAssetFunc();
|
||||
}
|
||||
|
||||
bool JsiDeclarativeEngine::ExecuteAbc(const shared_ptr<JsRuntime> runtime, const std::string fileName)
|
||||
{
|
||||
auto delegate = engineInstance_->GetDelegate();
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
|
||||
std::string basePath = delegate->GetAssetPath(fileName);
|
||||
if (!basePath.empty()) {
|
||||
std::string abcPath = basePath.append(fileName);
|
||||
LOGD("abcPath is: %{private}s", abcPath.c_str());
|
||||
if (!runtime->ExecuteJsBin(abcPath)) {
|
||||
LOGE("ExecuteJsBin %{private}s failed.", fileName.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
std::vector<uint8_t> content;
|
||||
if (!delegate->GetAssetContent(fileName, content)) {
|
||||
LOGD("GetAssetContent \"%{public}s\" failed.", fileName.c_str());
|
||||
return true;
|
||||
}
|
||||
if (!runtime->EvaluateJsCode(content.data(), content.size())) {
|
||||
LOGE("EvaluateJsCode \"%{public}s\" failed.", fileName.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void JsiDeclarativeEngine::LoadJs(const std::string& url, const RefPtr<JsAcePage>& page, bool isMainPage)
|
||||
{
|
||||
ACE_SCOPED_TRACE("JsiDeclarativeEngine::LoadJs");
|
||||
@@ -850,26 +886,12 @@ void JsiDeclarativeEngine::LoadJs(const std::string& url, const RefPtr<JsAcePage
|
||||
auto pos = url.rfind(js_ext);
|
||||
if (pos != std::string::npos && pos == url.length() - (sizeof(js_ext) - 1)) {
|
||||
std::string urlName = url.substr(0, pos) + bin_ext;
|
||||
std::string assetBasePath = delegate->GetAssetPath(urlName);
|
||||
std::string assetPath = assetBasePath.append(urlName);
|
||||
LOGI("assetPath is: %{private}s", assetPath.c_str());
|
||||
|
||||
if (isMainPage) {
|
||||
std::string commonsBasePath = delegate->GetAssetPath("commons.abc");
|
||||
if (!commonsBasePath.empty()) {
|
||||
std::string commonsPath = commonsBasePath.append("commons.abc");
|
||||
if (!runtime->ExecuteJsBin(commonsPath)) {
|
||||
LOGE("ExecuteJsBin \"commons.js\" failed.");
|
||||
return;
|
||||
}
|
||||
if (!ExecuteAbc(runtime, "commons.abc")) {
|
||||
return;
|
||||
}
|
||||
std::string vendorsBasePath = delegate->GetAssetPath("vendors.abc");
|
||||
if (!vendorsBasePath.empty()) {
|
||||
std::string vendorsPath = vendorsBasePath.append("vendors.abc");
|
||||
if (!runtime->ExecuteJsBin(vendorsPath)) {
|
||||
LOGE("ExecuteJsBin \"vendors.js\" failed.");
|
||||
return;
|
||||
}
|
||||
if (!ExecuteAbc(runtime, "vendor.abc")) {
|
||||
return;
|
||||
}
|
||||
std::string appMap;
|
||||
if (delegate->GetAssetContent("app.js.map", appMap)) {
|
||||
@@ -877,17 +899,13 @@ void JsiDeclarativeEngine::LoadJs(const std::string& url, const RefPtr<JsAcePage
|
||||
} else {
|
||||
LOGW("app map load failed!");
|
||||
}
|
||||
std::string appBasePath = delegate->GetAssetPath("app.abc");
|
||||
std::string appPath = appBasePath.append("app.abc");
|
||||
LOGI("appPath is: %{private}s", appPath.c_str());
|
||||
if (runtime->ExecuteJsBin(appPath)) {
|
||||
CallAppFunc("onCreate");
|
||||
} else {
|
||||
if (!ExecuteAbc(runtime, "app.abc")) {
|
||||
LOGW("ExecuteJsBin \"app.js\" failed.");
|
||||
} else {
|
||||
CallAppFunc("onCreate");
|
||||
}
|
||||
}
|
||||
if (!runtime->ExecuteJsBin(assetPath)) {
|
||||
LOGE("ExecuteJsBin %{public}s failed.", urlName.c_str());
|
||||
if (!ExecuteAbc(runtime, urlName)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,6 +284,7 @@ private:
|
||||
void RegisterWorker();
|
||||
void RegisterInitWorkerFunc();
|
||||
void RegisterAssetFunc();
|
||||
bool ExecuteAbc(const shared_ptr<JsRuntime> runtime, const std::string fileName);
|
||||
|
||||
RefPtr<JsiDeclarativeEngineInstance> engineInstance_;
|
||||
|
||||
|
||||
@@ -94,9 +94,7 @@
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_slider.h"
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_textpicker.h"
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_toggle.h"
|
||||
#if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM)
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_qrcode.h"
|
||||
#endif
|
||||
#ifdef PLUGIN_COMPONENT_SUPPORTED
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_plugin.h"
|
||||
#endif
|
||||
@@ -863,12 +861,10 @@ static const std::unordered_map<std::string, std::function<void(BindingTarget)>>
|
||||
{ "TextInput", JSTextInput::JSBind },
|
||||
{ "TextClock", JSTextClock::JSBind },
|
||||
{ "SideBarContainer", JSSideBar::JSBind },
|
||||
#if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM)
|
||||
{ "QRCode", JSQRCode::JSBind },
|
||||
#ifdef FORM_SUPPORTED
|
||||
{ "FormComponent", JSForm::JSBind },
|
||||
#endif
|
||||
#endif
|
||||
#ifdef PLUGIN_COMPONENT_SUPPORTED
|
||||
{ "PluginComponent", JSPlugin::JSBind },
|
||||
#endif
|
||||
|
||||
@@ -580,8 +580,7 @@ void JsiGroupJsBridge::Destroy()
|
||||
}
|
||||
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
void JsiGroupJsBridge::TriggerModuleJsCallbackPreview(
|
||||
int32_t callbackId, int32_t code, OHOS::Ace::ResponseData responseData)
|
||||
void JsiGroupJsBridge::TriggerModuleJsCallbackPreview(int32_t callbackId, int32_t code, ResponseData responseData)
|
||||
{
|
||||
LOGE("WAIT FOR IMPLEMENTED");
|
||||
}
|
||||
|
||||
@@ -70,8 +70,7 @@ 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;
|
||||
void TriggerModuleJsCallbackPreview(int32_t callbackId, int32_t code, ResponseData responseData) override;
|
||||
#endif
|
||||
|
||||
void LoadPluginJsCode(std::string&& jsCode) override;
|
||||
|
||||
Reference in New Issue
Block a user