1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "bridge/declarative_frontend/engine/v8/v8_module_manager.h"
17
18 #include "base/log/log.h"
19 #include "bridge/common/utils/utils.h"
20 #include "bridge/declarative_frontend/engine/v8/v8_declarative_engine.h"
21 #include "bridge/declarative_frontend/engine/v8/v8_js_matrix4.h"
22 #include "bridge/js_frontend/engine/common/js_constants.h"
23 #include "core/animation/cubic_curve.h"
24 #include "core/animation/spring_curve.h"
25 #include "core/common/container.h"
26
27 namespace OHOS::Ace::Framework {
GetInstance()28 ModuleManager* ModuleManager::GetInstance()
29 {
30 static ModuleManager instance;
31 return &instance;
32 }
33
PagePush(const v8::FunctionCallbackInfo<v8::Value> & args)34 void PagePush(const v8::FunctionCallbackInfo<v8::Value>& args)
35 {
36 v8::Isolate* isolate = args.GetIsolate();
37 v8::HandleScope handleScope(isolate);
38 auto context = isolate->GetCurrentContext();
39 if (context.IsEmpty()) {
40 LOGE("context is empty!");
41 return;
42 }
43 v8::Local<v8::String> value = v8::JSON::Stringify(context, args[0]).ToLocalChecked();
44 v8::String::Utf8Value argsJsStr(isolate, value);
45 if (!(*argsJsStr)) {
46 LOGE("PushPage method args is invalid");
47 return;
48 }
49
50 std::string argsStr(*argsJsStr);
51 std::unique_ptr<JsonValue> argsPtr = JsonUtil::ParseJsonString(*argsJsStr);
52
53 std::string uri;
54 if (argsPtr != nullptr && argsPtr->GetValue(ROUTE_KEY_URI)->IsString()) {
55 uri = argsPtr->GetValue(ROUTE_KEY_URI)->GetString();
56 }
57
58 std::string params;
59 if (argsPtr != nullptr && argsPtr->GetValue(ROUTE_KEY_PARAMS)->IsObject()) {
60 params = argsPtr->GetValue(ROUTE_KEY_PARAMS)->ToString();
61 }
62
63 auto delegate =
64 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
65 (*delegate)->Push(uri, params);
66 }
67
PageReplace(const v8::FunctionCallbackInfo<v8::Value> & args)68 void PageReplace(const v8::FunctionCallbackInfo<v8::Value>& args)
69 {
70 v8::Isolate* isolate = args.GetIsolate();
71 v8::HandleScope handleScope(isolate);
72 auto context = isolate->GetCurrentContext();
73 if (context.IsEmpty()) {
74 LOGE("context is empty!");
75 return;
76 }
77 v8::Local<v8::String> value = v8::JSON::Stringify(context, args[0]).ToLocalChecked();
78 v8::String::Utf8Value argsJsStr(isolate, value);
79 if (!(*argsJsStr)) {
80 LOGE("PageReplace method args is invalid");
81 return;
82 }
83
84 std::string argsStr(*argsJsStr);
85 std::unique_ptr<JsonValue> argsPtr = JsonUtil::ParseJsonString(*argsJsStr);
86
87 std::string uri;
88 if (argsPtr != nullptr && argsPtr->GetValue(ROUTE_KEY_URI)->IsString()) {
89 uri = argsPtr->GetValue(ROUTE_KEY_URI)->GetString();
90 }
91
92 std::string params;
93 if (argsPtr != nullptr && argsPtr->GetValue(ROUTE_KEY_PARAMS)->IsObject()) {
94 params = argsPtr->GetValue(ROUTE_KEY_PARAMS)->ToString();
95 }
96
97 auto delegate =
98 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
99 (*delegate)->Replace(uri, params);
100 }
101
PageBack(const v8::FunctionCallbackInfo<v8::Value> & args)102 void PageBack(const v8::FunctionCallbackInfo<v8::Value>& args)
103 {
104 v8::Isolate* isolate = args.GetIsolate();
105 v8::HandleScope handleScope(isolate);
106 auto context = isolate->GetCurrentContext();
107 if (context.IsEmpty()) {
108 LOGE("context is empty!");
109 return;
110 }
111 v8::Local<v8::String> value = v8::JSON::Stringify(context, args[0]).ToLocalChecked();
112 v8::String::Utf8Value argsJsStr(isolate, value);
113 if (!(*argsJsStr)) {
114 LOGE("PageBack method args is invalid");
115 return;
116 }
117
118 std::string argsStr(*argsJsStr);
119 std::unique_ptr<JsonValue> argsPtr = JsonUtil::ParseJsonString(*argsJsStr);
120
121 std::string uri;
122 if (argsPtr != nullptr && argsPtr->GetValue(ROUTE_KEY_URI)->IsString()) {
123 uri = argsPtr->GetValue(ROUTE_KEY_URI)->GetString();
124 }
125 std::string params;
126 if (argsPtr != nullptr && argsPtr->GetValue(ROUTE_KEY_PARAMS)->IsObject()) {
127 params = argsPtr->GetValue(ROUTE_KEY_PARAMS)->ToString();
128 }
129
130 auto delegate =
131 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
132 (*delegate)->Back(uri, params);
133 }
134
PageClear(const v8::FunctionCallbackInfo<v8::Value> & args)135 void PageClear(const v8::FunctionCallbackInfo<v8::Value>& args)
136 {
137 v8::Isolate* isolate = args.GetIsolate();
138 v8::HandleScope handleScope(isolate);
139
140 auto delegate =
141 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
142 (*delegate)->Clear();
143 }
144
PageGetLength(const v8::FunctionCallbackInfo<v8::Value> & args)145 void PageGetLength(const v8::FunctionCallbackInfo<v8::Value>& args)
146 {
147 v8::Isolate* isolate = args.GetIsolate();
148 v8::HandleScope handleScope(isolate);
149
150 auto delegate =
151 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
152 int32_t routeLength = (*delegate)->GetStackSize();
153 std::string indexLength = std::to_string(routeLength);
154 v8::Local<v8::String> lenStr =
155 v8::String::NewFromUtf8(isolate, indexLength.c_str()).ToLocalChecked();
156 args.GetReturnValue().Set(lenStr);
157 }
158
PageGetState(const v8::FunctionCallbackInfo<v8::Value> & args)159 void PageGetState(const v8::FunctionCallbackInfo<v8::Value>& args)
160 {
161 v8::Isolate* isolate = args.GetIsolate();
162 v8::HandleScope handleScope(isolate);
163
164 int32_t routeIndex = 0;
165 std::string routeName;
166 std::string routePath;
167 ACE_DCHECK(isolate);
168 auto delegate =
169 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
170 (*delegate)->GetState(routeIndex, routeName, routePath);
171 auto context = isolate->GetCurrentContext();
172 if (context.IsEmpty()) {
173 LOGE("get router state, context is empty!");
174 return;
175 }
176 v8::Local<v8::Object> res = v8::Object::New(isolate);
177 v8::Local<v8::Integer> index = v8::Integer::New(isolate, routeIndex);
178 v8::Local<v8::String> name = v8::String::NewFromUtf8(isolate, routeName.c_str()).ToLocalChecked();
179 v8::Local<v8::String> path = v8::String::NewFromUtf8(isolate, routePath.c_str()).ToLocalChecked();
180 res->Set(context, v8::String::NewFromUtf8(isolate, "index").ToLocalChecked(), index).ToChecked();
181 res->Set(context, v8::String::NewFromUtf8(isolate, "name").ToLocalChecked(), name).ToChecked();
182 res->Set(context, v8::String::NewFromUtf8(isolate, "path").ToLocalChecked(), path).ToChecked();
183 args.GetReturnValue().Set(res);
184 }
185
PageGetParams(const v8::FunctionCallbackInfo<v8::Value> & args)186 void PageGetParams(const v8::FunctionCallbackInfo<v8::Value>& args)
187 {
188 v8::Isolate* isolate = args.GetIsolate();
189 v8::HandleScope handleScope(isolate);
190
191 auto delegate =
192 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
193 std::string paramsStr = (*delegate)->GetParams();
194 if (paramsStr.empty()) {
195 LOGI("PageGetParams params is null");
196 args.GetReturnValue().Set(v8::Null(isolate));
197 return;
198 }
199
200 auto context = isolate->GetCurrentContext();
201 if (context.IsEmpty()) {
202 LOGE("get router state, context is empty!");
203 return;
204 }
205 v8::Local<v8::String> paramsRes = v8::String::NewFromUtf8(isolate, paramsStr.c_str()).ToLocalChecked();
206 v8::Local<v8::Value> res = v8::JSON::Parse(context, paramsRes).ToLocalChecked();
207 args.GetReturnValue().Set(res);
208 }
209
PostponePageTransition(const v8::FunctionCallbackInfo<v8::Value> & args)210 void PostponePageTransition(const v8::FunctionCallbackInfo<v8::Value>& args)
211 {
212 v8::Isolate* isolate = args.GetIsolate();
213 v8::HandleScope handleScope(isolate);
214 auto context = isolate->GetCurrentContext();
215 if (context.IsEmpty()) {
216 LOGE("context is empty!");
217 return;
218 }
219 auto delegate =
220 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
221 (*delegate)->PostponePageTransition();
222 }
223
LaunchPageTransition(const v8::FunctionCallbackInfo<v8::Value> & args)224 void LaunchPageTransition(const v8::FunctionCallbackInfo<v8::Value>& args)
225 {
226 v8::Isolate* isolate = args.GetIsolate();
227 v8::HandleScope handleScope(isolate);
228 auto context = isolate->GetCurrentContext();
229 if (context.IsEmpty()) {
230 LOGE("context is empty!");
231 return;
232 }
233 auto delegate =
234 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
235 (*delegate)->LaunchPageTransition();
236 }
237
InitRouterModule(v8::Local<v8::Object> moduleObj,v8::Isolate * isolate)238 void InitRouterModule(v8::Local<v8::Object> moduleObj, v8::Isolate* isolate)
239 {
240 auto context = isolate->GetCurrentContext();
241 if (context.IsEmpty()) {
242 LOGE("context is empty!");
243 return;
244 }
245 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, ROUTE_PAGE_PUSH).ToLocalChecked(),
246 v8::Function::New(context, PagePush).ToLocalChecked()).ToChecked();
247 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, ROUTE_PAGE_REPLACE).ToLocalChecked(),
248 v8::Function::New(context, PageReplace).ToLocalChecked()).ToChecked();
249 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, ROUTE_PAGE_BACK).ToLocalChecked(),
250 v8::Function::New(context, PageBack).ToLocalChecked()).ToChecked();
251 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, ROUTE_PAGE_CLEAR).ToLocalChecked(),
252 v8::Function::New(context, PageClear).ToLocalChecked()).ToChecked();
253 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, ROUTE_PAGE_GET_LENGTH).ToLocalChecked(),
254 v8::Function::New(context, PageGetLength).ToLocalChecked()).ToChecked();
255 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, ROUTE_PAGE_GET_STATE).ToLocalChecked(),
256 v8::Function::New(context, PageGetState).ToLocalChecked()).ToChecked();
257 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, ROUTE_PAGE_GET_PARAMS).ToLocalChecked(),
258 v8::Function::New(context, PageGetParams).ToLocalChecked()).ToChecked();
259 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, ROUTE_POSTPONE).ToLocalChecked(),
260 v8::Function::New(context, PostponePageTransition).ToLocalChecked()).ToChecked();
261 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, ROUTE_LAUNCH).ToLocalChecked(),
262 v8::Function::New(context, LaunchPageTransition).ToLocalChecked()).ToChecked();
263 }
264
AppGetInfo(const v8::FunctionCallbackInfo<v8::Value> & args)265 void AppGetInfo(const v8::FunctionCallbackInfo<v8::Value>& args)
266 {
267 LOGD("Enter GetAppInfo");
268 v8::Isolate* isolate = args.GetIsolate();
269 ACE_DCHECK(isolate);
270 v8::HandleScope handleScope(isolate);
271 auto context = isolate->GetCurrentContext();
272 if (context.IsEmpty()) {
273 LOGE("get app info, context is empty!");
274 return;
275 }
276
277 auto delegate =
278 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
279 v8::Local<v8::String> appID =
280 v8::String::NewFromUtf8(isolate, (*delegate)->GetAppID().c_str()).ToLocalChecked();
281 v8::Local<v8::String> appName =
282 v8::String::NewFromUtf8(isolate, (*delegate)->GetAppName().c_str()).ToLocalChecked();
283 v8::Local<v8::String> versionName =
284 v8::String::NewFromUtf8(isolate, (*delegate)->GetVersionName().c_str()).ToLocalChecked();
285 v8::Local<v8::Integer> versionCode = v8::Integer::New(isolate, (*delegate)->GetVersionCode());
286
287 // return the result as an object
288 v8::Local<v8::Object> res = v8::Object::New(isolate);
289 res->Set(context, v8::String::NewFromUtf8(isolate, "appID").ToLocalChecked(), appID).ToChecked();
290 res->Set(context, v8::String::NewFromUtf8(isolate, "appName").ToLocalChecked(), appName).ToChecked();
291 res->Set(context, v8::String::NewFromUtf8(isolate, "versionName").ToLocalChecked(), versionName).ToChecked();
292 res->Set(context, v8::String::NewFromUtf8(isolate, "versionCode").ToLocalChecked(), versionCode).ToChecked();
293 args.GetReturnValue().Set(res);
294 }
295
AppTerminate(const v8::FunctionCallbackInfo<v8::Value> & args)296 void AppTerminate(const v8::FunctionCallbackInfo<v8::Value>& args)
297 {
298 v8::Isolate* isolate = args.GetIsolate();
299 v8::HandleScope handleScope(isolate);
300
301 auto delegate =
302 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
303 WeakPtr<PipelineContext> pipelineContextWeak = (*delegate)->GetPipelineContext();
304 auto uiTaskExecutor = (*delegate)->GetUiTask();
305 uiTaskExecutor.PostTask([pipelineContextWeak]() mutable {
306 auto pipelineContext = pipelineContextWeak.Upgrade();
307 if (pipelineContext) {
308 pipelineContext->Finish();
309 }
310 });
311 }
312
AppSetImageCacheCount(const v8::FunctionCallbackInfo<v8::Value> & args)313 void AppSetImageCacheCount(const v8::FunctionCallbackInfo<v8::Value>& args)
314 {
315 auto container = Container::Current();
316 if (!container) {
317 LOGE("current container is null");
318 return;
319 }
320 auto pipelineContext = container->GetPipelineContext();
321 if (!pipelineContext) {
322 LOGE("get pipelineContext failed");
323 return;
324 }
325 auto taskExecutor = pipelineContext->GetTaskExecutor();
326 if (!taskExecutor) {
327 LOGE("taskExecutor is null.");
328 return;
329 }
330 v8::Isolate* isolate = args.GetIsolate();
331 v8::HandleScope handleScope(isolate);
332 auto context = isolate->GetCurrentContext();
333 if (args.Length() != 1 || !args[0]->IsNumber()) {
334 LOGE("The arguments must be one int number.");
335 return;
336 }
337
338 WeakPtr<PipelineContext> pipelineContextWeak(pipelineContext);
339 int32_t size = args[0]->Int32Value(context).ToChecked();
340 size = size > 0 ? size : 0;
341 taskExecutor->PostTask([pipelineContextWeak, size]() mutable {
342 auto pipelineContext = pipelineContextWeak.Upgrade();
343 if (pipelineContext) {
344 auto imageCache = pipelineContext->GetImageCache();
345 if (imageCache) {
346 imageCache->SetCapacity(size);
347 } else {
348 LOGW("image cache is null");
349 }
350 }
351 }, TaskExecutor::TaskType::UI);
352 }
353
AppSetImageRawDataCacheSize(const v8::FunctionCallbackInfo<v8::Value> & args)354 void AppSetImageRawDataCacheSize(const v8::FunctionCallbackInfo<v8::Value>& args)
355 {
356 auto container = Container::Current();
357 if (!container) {
358 LOGE("current container is null");
359 return;
360 }
361 auto pipelineContext = container->GetPipelineContext();
362 if (!pipelineContext) {
363 LOGE("get pipelineContext failed");
364 return;
365 }
366 auto taskExecutor = pipelineContext->GetTaskExecutor();
367 if (!taskExecutor) {
368 LOGE("taskExecutor is null.");
369 return;
370 }
371 v8::Isolate* isolate = args.GetIsolate();
372 v8::HandleScope handleScope(isolate);
373 auto context = isolate->GetCurrentContext();
374 if (args.Length() != 1 || !args[0]->IsNumber()) {
375 LOGE("The arguments must be one int number.");
376 return;
377 }
378
379 WeakPtr<PipelineContext> pipelineContextWeak(pipelineContext);
380 int32_t size = args[0]->Int32Value(context).ToChecked();
381 size = size > 0 ? size : 0;
382 taskExecutor->PostTask([pipelineContextWeak, size]() mutable {
383 auto pipelineContext = pipelineContextWeak.Upgrade();
384 if (pipelineContext) {
385 auto imageCache = pipelineContext->GetImageCache();
386 if (imageCache) {
387 imageCache->SetDataCacheLimit(size);
388 } else {
389 LOGW("image cache is null");
390 }
391 }
392 }, TaskExecutor::TaskType::UI);
393 }
394
AppSetImageFileCacheSize(const v8::FunctionCallbackInfo<v8::Value> & args)395 void AppSetImageFileCacheSize(const v8::FunctionCallbackInfo<v8::Value>& args)
396 {
397 auto container = Container::Current();
398 if (!container) {
399 LOGE("current container is null");
400 return;
401 }
402 auto pipelineContext = container->GetPipelineContext();
403 if (!pipelineContext) {
404 LOGE("get pipelineContext failed");
405 return;
406 }
407 auto taskExecutor = pipelineContext->GetTaskExecutor();
408 if (!taskExecutor) {
409 LOGE("taskExecutor is null.");
410 return;
411 }
412 v8::Isolate* isolate = args.GetIsolate();
413 v8::HandleScope handleScope(isolate);
414 auto context = isolate->GetCurrentContext();
415 if (args.Length() != 1 || !args[0]->IsNumber()) {
416 LOGE("The arguments must be one int number.");
417 return;
418 }
419 WeakPtr<PipelineContext> pipelineContextWeak(pipelineContext);
420 auto uiTaskExecutor = (*delegate)->GetUiTask();
421 int32_t size = args[0]->Int32Value(context).ToChecked();
422 size = size > 0 ? size : 0;
423 taskExecutor->PostTask([pipelineContextWeak, size]() mutable {
424 auto pipelineContext = pipelineContextWeak.Upgrade();
425 if (pipelineContext) {
426 auto imageCache = pipelineContext->GetImageCache();
427 if (imageCache) {
428 imageCache->SetCacheFileLimit(size);
429 } else {
430 LOGW("image cache is null");
431 }
432 }
433 }, TaskExecutor::TaskType::UI);
434 }
435
InitAppModule(v8::Local<v8::Object> moduleObj,v8::Isolate * isolate)436 void InitAppModule(v8::Local<v8::Object> moduleObj, v8::Isolate* isolate)
437 {
438 auto context = isolate->GetCurrentContext();
439 if (context.IsEmpty()) {
440 LOGE("context is empty!");
441 return;
442 }
443 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, APP_GET_INFO).ToLocalChecked(),
444 v8::Function::New(context, AppGetInfo).ToLocalChecked()).ToChecked();
445 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, APP_TERMINATE).ToLocalChecked(),
446 v8::Function::New(context, AppTerminate).ToLocalChecked()).ToChecked();
447 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, APP_SET_IMAGE_CACHE_COUNT).ToLocalChecked(),
448 v8::Function::New(context, AppSetImageCacheCount).ToLocalChecked()).ToChecked();
449 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, APP_SET_IMAGE_RAWDATA_CACHE_SIZE).ToLocalChecked(),
450 v8::Function::New(context, AppSetImageRawDataCacheSize).ToLocalChecked()).ToChecked();
451 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, APP_SET_IMAGE_FILE_CACHE_SIZE).ToLocalChecked(),
452 v8::Function::New(context, AppSetImageFileCacheSize).ToLocalChecked()).ToChecked();
453 }
454
CurvesInterpolate(const v8::FunctionCallbackInfo<v8::Value> & args)455 void CurvesInterpolate(const v8::FunctionCallbackInfo<v8::Value>& args)
456 {
457 v8::Isolate* isolate = args.GetIsolate();
458 v8::HandleScope handleScope(isolate);
459 auto context = isolate->GetCurrentContext();
460 if (args.Length() != 1) {
461 return;
462 }
463 double time = args[0]->NumberValue(context).ToChecked();
464 int32_t pageId = args.Holder()->Get(context, v8::String::NewFromUtf8(isolate, "__pageId").ToLocalChecked())
465 .ToLocalChecked()->Int32Value(context).ToChecked();
466 v8::Local<v8::Value> value = args.Holder()->Get(context, v8::String::NewFromUtf8(isolate, "__curveString").
467 ToLocalChecked()).ToLocalChecked();
468 v8::String::Utf8Value curve(isolate, value->ToString(context).ToLocalChecked());
469 if (!(*curve)) {
470 return;
471 }
472 std::string curveString(*curve);
473 auto animationCurve = CreateCurve(curveString, false);
474 if (!animationCurve) {
475 return;
476 }
477 double curveValue = animationCurve->Move(time);
478 args.GetReturnValue().Set(v8::Number::New(isolate, curveValue));
479 }
480
CurvesInitInternal(const v8::FunctionCallbackInfo<v8::Value> & args)481 void CurvesInitInternal(const v8::FunctionCallbackInfo<v8::Value>& args)
482 {
483 v8::Isolate* isolate = args.GetIsolate();
484 v8::HandleScope handleScope(isolate);
485 auto context = isolate->GetCurrentContext();
486 auto curveContext = v8::Object::New(isolate);
487 curveContext->Set(context, v8::String::NewFromUtf8(isolate, "interpolate").ToLocalChecked(),
488 v8::Function::New(context, CurvesInterpolate).ToLocalChecked()).ToChecked();
489 if (args.Length() != 0 && args.Length() != 1) {
490 return;
491 }
492 RefPtr<Curve> curve;
493 std::string curveString;
494 if (args.Length() == 1 && args[0]->IsString()) {
495 v8::String::Utf8Value arg(isolate, args[0]->ToString(context).ToLocalChecked());
496 if (!*arg) {
497 return;
498 }
499 curveString = *arg;
500 } else {
501 curveString = "linear";
502 }
503 curve = CreateCurve(curveString);
504 curveContext->Set(context, v8::String::NewFromUtf8(isolate, "__curveString").ToLocalChecked(),
505 v8::String::NewFromUtf8(isolate, curveString.c_str()).ToLocalChecked()).ToChecked();
506 if (Container::IsCurrentUseNewPipeline()) {
507 args.GetReturnValue().Set(curveContext);
508 return;
509 }
510
511 auto page =
512 static_cast<RefPtr<JsAcePage>*>(isolate->GetData(V8DeclarativeEngineInstance::STAGING_PAGE));
513 if ((*page) == nullptr) {
514 LOGE("page is nullptr");
515 return;
516 }
517 int32_t pageId = (*page)->GetPageId();
518 curveContext->Set(context, v8::String::NewFromUtf8(isolate, "__pageId").ToLocalChecked(),
519 v8::Int32::New(isolate, pageId)).ToChecked();
520 args.GetReturnValue().Set(curveContext);
521 }
522
CurvesInit(const v8::FunctionCallbackInfo<v8::Value> & args)523 void CurvesInit(const v8::FunctionCallbackInfo<v8::Value>& args)
524 {
525 CurvesInitInternal(args);
526 }
527
InitCurve(const v8::FunctionCallbackInfo<v8::Value> & args)528 void InitCurve(const v8::FunctionCallbackInfo<v8::Value>& args)
529 {
530 CurvesInitInternal(args);
531 }
532
ParseCurves(const v8::FunctionCallbackInfo<v8::Value> & args,std::string & curveString)533 void ParseCurves(const v8::FunctionCallbackInfo<v8::Value>& args, std::string& curveString)
534 {
535 v8::Isolate* isolate = args.GetIsolate();
536 v8::HandleScope handleScope(isolate);
537 auto context = isolate->GetCurrentContext();
538 auto curveContext = v8::Object::New(isolate);
539 curveContext->Set(context, v8::String::NewFromUtf8(isolate, "interpolate").ToLocalChecked(),
540 v8::Function::New(context, CurvesInterpolate).ToLocalChecked()).ToChecked();
541 if (args.Length() != 4) {
542 LOGE("the number of parameters is illegal");
543 return;
544 }
545 double x0 = args[0]->NumberValue(context).ToChecked();
546 double y0 = args[1]->NumberValue(context).ToChecked();
547 double x1 = args[2]->NumberValue(context).ToChecked();
548 double y1 = args[3]->NumberValue(context).ToChecked();
549 RefPtr<Curve> curve;
550 if (curveString == CURVES_SPRING || curveString == SPRING_CURVE) {
551 if (y0 > 0 && x1 > 0 && y1 > 0) {
552 curve = AceType::MakeRefPtr<SpringCurve>(x0, y0, x1, y1);
553 } else {
554 LOGE("Spring curve: the value of the parameters are illegal");
555 return false;
556 }
557 } else if (curveString == CURVES_CUBIC_BEZIER || curveString == CUBIC_BEZIER_CURVE) {
558 curve = AceType::MakeRefPtr<CubicCurve>(x0, y0, x1, y1);
559 } else {
560 LOGE("curve params: %{public}s is illegal", curveString.c_str());
561 return;
562 }
563 auto customCurve = curve->ToString();
564 curveContext->Set(context, v8::String::NewFromUtf8(isolate, "__curveString").ToLocalChecked(),
565 v8::String::NewFromUtf8(isolate, customCurve.c_str()).ToLocalChecked()).ToChecked();
566 if (Container::IsCurrentUseNewPipeline()) {
567 args.GetReturnValue().Set(curveContext);
568 return;
569 }
570 auto page =
571 static_cast<RefPtr<JsAcePage>*>(isolate->GetData(V8DeclarativeEngineInstance::STAGING_PAGE));
572 if ((*page) == nullptr) {
573 LOGE("page is nullptr");
574 return;
575 }
576 int32_t pageId = (*page)->GetPageId();
577
578 curveContext->Set(context, v8::String::NewFromUtf8(isolate, "__pageId").ToLocalChecked(),
579 v8::Int32::New(isolate, pageId)).ToChecked();
580 args.GetReturnValue().Set(curveContext);
581 }
582
CurvesBezier(const v8::FunctionCallbackInfo<v8::Value> & args)583 void CurvesBezier(const v8::FunctionCallbackInfo<v8::Value>& args)
584 {
585 std::string curveString(CURVES_CUBIC_BEZIER);
586 ParseCurves(args, curveString);
587 }
588
BezierCurve(const v8::FunctionCallbackInfo<v8::Value> & args)589 void BezierCurve(const v8::FunctionCallbackInfo<v8::Value>& args)
590 {
591 std::string curveString(CUBIC_BEZIER_CURVE);
592 ParseCurves(args, curveString);
593 }
594
CurvesSpring(const v8::FunctionCallbackInfo<v8::Value> & args)595 void CurvesSpring(const v8::FunctionCallbackInfo<v8::Value>& args)
596 {
597 std::string curveString(CURVES_SPRING);
598 ParseCurves(args, curveString);
599 }
600
SpringCurve(const v8::FunctionCallbackInfo<v8::Value> & args)601 void SpringCurve(const v8::FunctionCallbackInfo<v8::Value>& args)
602 {
603 std::string curveString(SPRING_CURVE);
604 ParseCurves(args, curveString);
605 }
606
CurvesStepsInternal(const v8::FunctionCallbackInfo<v8::Value> & args)607 void CurvesStepsInternal(const v8::FunctionCallbackInfo<v8::Value>& args)
608 {
609 int32_t STEPS_ARGS_NUMBER = 2;
610 auto argc = args.Length();
611 if (argc != 1 && argc != STEPS_ARGS_NUMBER) {
612 LOGE("Steps curve: the number of parameters is illegal");
613 return;
614 }
615 v8::Isolate* isolate = args.GetIsolate();
616 v8::HandleScope handleScope(isolate);
617 auto context = isolate->GetCurrentContext();
618 auto curveContext = v8::Object::New(isolate);
619 curveContext->Set(context, v8::String::NewFromUtf8(isolate, "interpolate").ToLocalChecked(),
620 v8::Function::New(context, CurvesInterpolate).ToLocalChecked()).ToChecked();
621 RefPtr<Curve> curve;
622 int32_t stepSize = 0;
623 if (argc == STEPS_ARGS_NUMBER) {
624 stepSize = args[0]->ToInt32(context).ToLocalChecked()->Value();
625 if (stepSize < 0) {
626 LOGE("Steps curve: When two parameters, the value of the stepSize is illegal");
627 return false;
628 }
629 bool isEnd = args[1]->ToBoolean(isolate)->Value();
630 if (isEnd) {
631 curve = AceType::MakeRefPtr<StepsCurve>(stepSize, StepsCurvePosition::END);
632 } else {
633 curve = AceType::MakeRefPtr<StepsCurve>(stepSize, StepsCurvePosition::START);
634 }
635 } else {
636 stepSize = args[0]->ToInt32(context).ToLocalChecked()->Value();
637 if (stepSize < 0) {
638 LOGE("Steps curve: When one parameter, the value of the stepSize is illegal");
639 return false;
640 }
641 curve = AceType::MakeRefPtr<StepsCurve>(stepSize);
642 }
643 curveContext->Set(context, v8::String::NewFromUtf8(isolate, "__curveString").ToLocalChecked(),
644 v8::String::NewFromUtf8(isolate, curve->ToString().c_str()).ToLocalChecked()).ToChecked();
645 if (Container::IsCurrentUseNewPipeline()) {
646 args.GetReturnValue().Set(curveContext);
647 return;
648 }
649 auto page = static_cast<RefPtr<JsAcePage>*>(isolate->GetData(V8DeclarativeEngineInstance::STAGING_PAGE));
650 if ((*page) == nullptr) {
651 LOGE("page is nullptr");
652 return;
653 }
654 int32_t pageId = (*page)->GetPageId();
655 curveContext->Set(context, v8::String::NewFromUtf8(isolate, "__pageId").ToLocalChecked(),
656 v8::Int32::New(isolate, pageId)).ToChecked();
657 args.GetReturnValue().Set(curveContext);
658 }
659
CurvesSteps(const v8::FunctionCallbackInfo<v8::Value> & args)660 void CurvesSteps(const v8::FunctionCallbackInfo<v8::Value>& args)
661 {
662 CurvesStepsInternal(args);
663 }
664
StepsCurve(const v8::FunctionCallbackInfo<v8::Value> & args)665 void StepsCurve(const v8::FunctionCallbackInfo<v8::Value>& args)
666 {
667 CurvesStepsInternal(args);
668 }
669
InitCurvesModule(v8::Local<v8::Object> moduleObj,v8::Isolate * isolate)670 void InitCurvesModule(v8::Local<v8::Object> moduleObj, v8::Isolate* isolate)
671 {
672 auto context = isolate->GetCurrentContext();
673 if (context.IsEmpty()) {
674 LOGE("context is empty!");
675 return;
676 }
677 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, CURVES_INIT).ToLocalChecked(),
678 v8::Function::New(context, CurvesInit).ToLocalChecked()).ToChecked();
679 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, INIT_CURVE).ToLocalChecked(),
680 v8::Function::New(context, InitCurve).ToLocalChecked()).ToChecked();
681 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, CURVES_CUBIC_BEZIER).ToLocalChecked(),
682 v8::Function::New(context, CurvesBezier).ToLocalChecked()).ToChecked();
683 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, CUBIC_BEZIER_CURVE).ToLocalChecked(),
684 v8::Function::New(context, BezierCurve).ToLocalChecked()).ToChecked();
685 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, CURVES_SPRING).ToLocalChecked(),
686 v8::Function::New(context, CurvesSpring).ToLocalChecked()).ToChecked();
687 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, SPRING_CURVE).ToLocalChecked(),
688 v8::Function::New(context, SpringCurve).ToLocalChecked()).ToChecked();
689 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, CURVES_STEPS).ToLocalChecked(),
690 v8::Function::New(context, CurvesSteps).ToLocalChecked()).ToChecked();
691 moduleObj->Set(context, v8::String::NewFromUtf8(isolate, STEPS_CURVE).ToLocalChecked(),
692 v8::Function::New(context, StepsCurve).ToLocalChecked()).ToChecked();
693 }
694
InitMatrix(v8::Local<v8::Object> moduleObj,v8::Isolate * isolate)695 void InitMatrix(v8::Local<v8::Object> moduleObj, v8::Isolate* isolate)
696 {
697 auto context = isolate->GetCurrentContext();
698 if (context.IsEmpty()) {
699 LOGE("context is empty!");
700 return;
701 }
702
703 JSMatrix4::CreateMatrix4Object(moduleObj, isolate);
704 }
705
SetTimeout(const v8::FunctionCallbackInfo<v8::Value> & args)706 void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args)
707 {
708 ModuleManager::GetInstance()->SetWaitTimer(args, false);
709 }
710
SetInterval(const v8::FunctionCallbackInfo<v8::Value> & args)711 void SetInterval(const v8::FunctionCallbackInfo<v8::Value>& args)
712 {
713 ModuleManager::GetInstance()->SetWaitTimer(args, true);
714 }
715
SetWaitTimer(const v8::FunctionCallbackInfo<v8::Value> & args,bool isInterval)716 void ModuleManager::SetWaitTimer(const v8::FunctionCallbackInfo<v8::Value>& args, bool isInterval)
717 {
718 v8::Isolate* isolate = args.GetIsolate();
719 ACE_DCHECK(isolate);
720 v8::HandleScope handleScope(isolate);
721 auto context = isolate->GetCurrentContext();
722 if (context.IsEmpty()) {
723 LOGE("set time out or interval, context is empty!");
724 return;
725 }
726 auto delegate =
727 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
728
729 int argc = args.Length();
730 if (argc < 1) {
731 LOGW("JsSetTimer: invalid callback value");
732 }
733
734 LOGI("Enter SetWaitTimer %{private}d %{private}d", isInterval, argc);
735
736 if (!args[0]->IsFunction()) {
737 LOGW("args[0] is not function");
738 return;
739 }
740 v8::Local<v8::Function> jsFunc = v8::Local<v8::Function>::Cast(args[0]);
741 CopyablePersistent<v8::Function> pFunction;
742 pFunction.Reset(isolate, jsFunc);
743
744 uint32_t delay = 0;
745 std::vector<v8::Persistent<v8::Value, v8::CopyablePersistentTraits<v8::Value>>> callbackArray;
746 if (argc < 2 || !args[1]->IsNumber()) {
747 uint32_t callbackId = ModuleManager::GetInstance()->AddCallback(pFunction, callbackArray, isolate, isInterval);
748 args.GetReturnValue().Set(v8::Integer::New(isolate, callbackId));
749 (*delegate)->WaitTimer(std::to_string(callbackId), std::to_string(delay), isInterval, true);
750 return;
751 }
752
753 delay = args[1]->ToInt32(context).ToLocalChecked()->Value();
754
755 for (int index = 2; index < argc; ++index) {
756 CopyablePersistent<v8::Value> pValue;
757 pValue.Reset(isolate, args[index]);
758 callbackArray.emplace_back(pValue);
759 }
760
761 uint32_t callbackId = ModuleManager::GetInstance()->AddCallback(pFunction, callbackArray, isolate, isInterval);
762 args.GetReturnValue().Set(v8::Integer::New(isolate, callbackId));
763 (*delegate)->WaitTimer(std::to_string(callbackId), std::to_string(delay), isInterval, true);
764 }
765
ClearTimeout(const v8::FunctionCallbackInfo<v8::Value> & args)766 void ClearTimeout(const v8::FunctionCallbackInfo<v8::Value>& args)
767 {
768 ModuleManager::GetInstance()->ClearWaitTimer(args, false);
769 }
770
ClearInterval(const v8::FunctionCallbackInfo<v8::Value> & args)771 void ClearInterval(const v8::FunctionCallbackInfo<v8::Value>& args)
772 {
773 ModuleManager::GetInstance()->ClearWaitTimer(args, true);
774 }
775
ClearWaitTimer(const v8::FunctionCallbackInfo<v8::Value> & args,bool isInterval)776 void ModuleManager::ClearWaitTimer(const v8::FunctionCallbackInfo<v8::Value>& args, bool isInterval)
777 {
778 LOGD("Enter ClearWaitTimer %{private}d", isInterval);
779
780 v8::Isolate* isolate = args.GetIsolate();
781 ACE_DCHECK(isolate);
782 v8::HandleScope handleScope(isolate);
783 auto context = isolate->GetCurrentContext();
784 if (context.IsEmpty()) {
785 LOGE("set timeout or interval, context is empty!");
786 return;
787 }
788
789 if (!args[0]->IsNumber()) {
790 LOGE("args[0] is not number");
791 return;
792 }
793
794 uint32_t callbackId = args[0]->ToInt32(context).ToLocalChecked()->Value();
795 ModuleManager::GetInstance()->RemoveCallbackFunc(callbackId, isInterval);
796 auto delegate =
797 static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
798 (*delegate)->ClearTimer(std::to_string(callbackId));
799 }
800
AddCallback(CopyablePersistent<v8::Function> callbackFunc,std::vector<CopyablePersistent<v8::Value>> callbackArray,v8::Isolate * isolate,bool isInterval)801 uint32_t ModuleManager::AddCallback(CopyablePersistent<v8::Function> callbackFunc,
802 std::vector<CopyablePersistent<v8::Value>> callbackArray, v8::Isolate* isolate, bool isInterval)
803 {
804 if (isInterval) {
805 return AddCallback(intervalCallbackFuncMap_, intervalCallbackArrayMap_, intervalCallbackIsolateMap_,
806 callbackFunc, callbackArray, isolate);
807 } else {
808 return AddCallback(
809 callbackFuncMap_, callbackArrayMap_, callbackIsolateMap_, callbackFunc, callbackArray, isolate);
810 }
811 }
812
AddCallback(std::unordered_map<uint32_t,CopyablePersistent<v8::Function>> & callbackFuncMap,std::unordered_map<uint32_t,std::vector<CopyablePersistent<v8::Value>>> & callbackArrayMap,std::unordered_map<uint32_t,v8::Isolate * > & callbackIsolateMap,CopyablePersistent<v8::Function> callbackFunc,std::vector<CopyablePersistent<v8::Value>> callbackArray,v8::Isolate * isolate)813 uint32_t ModuleManager::AddCallback(std::unordered_map<uint32_t, CopyablePersistent<v8::Function>>& callbackFuncMap,
814 std::unordered_map<uint32_t, std::vector<CopyablePersistent<v8::Value>>>& callbackArrayMap,
815 std::unordered_map<uint32_t, v8::Isolate*>& callbackIsolateMap, CopyablePersistent<v8::Function> callbackFunc,
816 std::vector<CopyablePersistent<v8::Value>> callbackArray, v8::Isolate* isolate)
817 {
818 ++callbackId_;
819 callbackFuncMap[callbackId_] = callbackFunc;
820 if (!callbackArray.empty()) {
821 callbackArrayMap[callbackId_] = callbackArray;
822 }
823 callbackIsolateMap[callbackId_] = isolate;
824 return callbackId_;
825 }
826
RemoveCallbackFunc(uint32_t callbackId,bool isInterval)827 void ModuleManager::RemoveCallbackFunc(uint32_t callbackId, bool isInterval)
828 {
829 if (isInterval) {
830 RemoveCallbackFunc(
831 intervalCallbackFuncMap_, intervalCallbackArrayMap_, intervalCallbackIsolateMap_, callbackId);
832 } else {
833 RemoveCallbackFunc(callbackFuncMap_, callbackArrayMap_, callbackIsolateMap_, callbackId);
834 }
835 }
836
RemoveCallbackFunc(std::unordered_map<uint32_t,CopyablePersistent<v8::Function>> & callbackFuncMap,std::unordered_map<uint32_t,std::vector<CopyablePersistent<v8::Value>>> & callbackArrayMap,std::unordered_map<uint32_t,v8::Isolate * > & callbackIsolateMap,uint32_t callbackId)837 void ModuleManager::RemoveCallbackFunc(std::unordered_map<uint32_t, CopyablePersistent<v8::Function>>& callbackFuncMap,
838 std::unordered_map<uint32_t, std::vector<CopyablePersistent<v8::Value>>>& callbackArrayMap,
839 std::unordered_map<uint32_t, v8::Isolate*>& callbackIsolateMap, uint32_t callbackId)
840 {
841 callbackFuncMap[callbackId].Reset();
842 callbackFuncMap.erase(callbackId);
843
844 if (callbackArrayMap.find(callbackId) != callbackArrayMap.end()) {
845 uint32_t index = 0;
846 while (index < callbackArrayMap[callbackId].size()) {
847 callbackArrayMap[callbackId][index].Reset();
848 ++index;
849 }
850 callbackArrayMap.erase(callbackId);
851 }
852 callbackIsolateMap.erase(callbackId);
853 }
854
GetCallbackFunc(uint32_t callbackId,bool isInterval)855 CopyablePersistent<v8::Function> ModuleManager::GetCallbackFunc(uint32_t callbackId, bool isInterval)
856 {
857 if (isInterval) {
858 return intervalCallbackFuncMap_[callbackId];
859 } else {
860 return callbackFuncMap_[callbackId];
861 }
862 }
863
GetCallbackArray(uint32_t callbackId,bool isInterval)864 std::vector<CopyablePersistent<v8::Value>> ModuleManager::GetCallbackArray(uint32_t callbackId, bool isInterval)
865 {
866 if (isInterval) {
867 return GetCallbackArray(intervalCallbackArrayMap_, callbackId);
868 } else {
869 return GetCallbackArray(callbackArrayMap_, callbackId);
870 }
871 }
872
GetCallbackArray(std::unordered_map<uint32_t,std::vector<CopyablePersistent<v8::Value>>> & callbackArrayMap,uint32_t callbackId)873 std::vector<CopyablePersistent<v8::Value>> ModuleManager::GetCallbackArray(
874 std::unordered_map<uint32_t, std::vector<CopyablePersistent<v8::Value>>>& callbackArrayMap, uint32_t callbackId)
875 {
876 if (callbackArrayMap.find(callbackId) != callbackArrayMap.end()) {
877 return callbackArrayMap[callbackId];
878 }
879 std::vector<CopyablePersistent<v8::Value>> emptyRet;
880 return emptyRet;
881 }
882
GetCallbackIsolate(uint32_t callbackId,bool isInterval)883 v8::Isolate* ModuleManager::GetCallbackIsolate(uint32_t callbackId, bool isInterval)
884 {
885 if (isInterval) {
886 return intervalCallbackIsolateMap_[callbackId];
887 } else {
888 return callbackIsolateMap_[callbackId];
889 }
890 }
891
ClearTimerIsolate(v8::Isolate * isolate)892 void ModuleManager::ClearTimerIsolate(v8::Isolate* isolate)
893 {
894 for (auto it = callbackIsolateMap_.begin(); it != callbackIsolateMap_.end();) {
895 if (it->second == isolate) {
896 uint32_t index = it->first;
897 callbackFuncMap_.erase(index);
898 callbackArrayMap_.erase(index);
899 callbackIsolateMap_.erase(it++);
900 } else {
901 it++;
902 }
903 }
904 for (auto it = intervalCallbackIsolateMap_.begin(); it != intervalCallbackIsolateMap_.end();) {
905 if (it->second == isolate) {
906 uint32_t index = it->first;
907 intervalCallbackFuncMap_.erase(index);
908 intervalCallbackArrayMap_.erase(index);
909 intervalCallbackIsolateMap_.erase(it++);
910 } else {
911 it++;
912 }
913 }
914 }
915
InitTimerModule(v8::Local<v8::Context> & localContext)916 void ModuleManager::InitTimerModule(v8::Local<v8::Context>& localContext)
917 {
918 v8::Isolate* isolate = localContext->GetIsolate();
919 v8::Local<v8::Object> global = localContext->Global();
920 global
921 ->Set(localContext, v8::String::NewFromUtf8(isolate, SET_TIMEOUT).ToLocalChecked(),
922 v8::Function::New(localContext, SetTimeout).ToLocalChecked()).ToChecked();
923 global
924 ->Set(localContext, v8::String::NewFromUtf8(isolate, SET_INTERVAL).ToLocalChecked(),
925 v8::Function::New(localContext, SetInterval).ToLocalChecked()).ToChecked();
926 global
927 ->Set(localContext, v8::String::NewFromUtf8(isolate, CLEAR_TIMEOUT).ToLocalChecked(),
928 v8::Function::New(localContext, ClearTimeout).ToLocalChecked()).ToChecked();
929 global
930 ->Set(localContext, v8::String::NewFromUtf8(isolate, CLEAR_INTERVAL).ToLocalChecked(),
931 v8::Function::New(localContext, ClearInterval).ToLocalChecked()).ToChecked();
932 }
933
InitModule(v8::Local<v8::Object> moduleObj,const std::string & moduleName,v8::Isolate * isolate)934 bool ModuleManager::InitModule(v8::Local<v8::Object> moduleObj, const std::string& moduleName, v8::Isolate* isolate)
935 {
936 static const std::unordered_map<std::string, void (*)(v8::Local<v8::Object>, v8::Isolate*)> MODULE_LIST = {
937 { "system.router",
938 [](v8::Local<v8::Object> moduleObj, v8::Isolate* isolate) { InitRouterModule(moduleObj, isolate); } },
939 { "ohos.router",
940 [](v8::Local<v8::Object> moduleObj, v8::Isolate* isolate) { InitRouterModule(moduleObj, isolate); } },
941 { "system.app",
942 [](v8::Local<v8::Object> moduleObj, v8::Isolate* isolate) { InitAppModule(moduleObj, isolate); } },
943 { "ohos.app",
944 [](v8::Local<v8::Object> moduleObj, v8::Isolate* isolate) { InitAppModule(moduleObj, isolate); } },
945 { "system.curves",
946 [](v8::Local<v8::Object> moduleObj, v8::Isolate* isolate) { InitCurvesModule(moduleObj, isolate); } },
947 { "ohos.curves",
948 [](v8::Local<v8::Object> moduleObj, v8::Isolate* isolate) { InitCurvesModule(moduleObj, isolate); } },
949 { "system.matrix4",
950 [](v8::Local<v8::Object> moduleObj, v8::Isolate* isolate) { InitMatrix(moduleObj, isolate); } },
951 { "ohos.matrix4",
952 [](v8::Local<v8::Object> moduleObj, v8::Isolate* isolate) { InitMatrix(moduleObj, isolate); } },
953 };
954 auto iter = MODULE_LIST.find(moduleName);
955 if (iter != MODULE_LIST.end()) {
956 iter->second(moduleObj, isolate);
957 return true;
958 } else {
959 LOGE("register module is not found");
960 return false;
961 }
962 }
963 } // namespace OHOS::Ace::Framework
964