diff --git a/frameworks/kits/runtime/native/js_runtime.cpp b/frameworks/kits/runtime/native/js_runtime.cpp index add9ecc8c6..12f45d7e1b 100644 --- a/frameworks/kits/runtime/native/js_runtime.cpp +++ b/frameworks/kits/runtime/native/js_runtime.cpp @@ -21,6 +21,7 @@ #include #include "native_engine/impl/ark/ark_native_engine.h" +#include "core/common/container_scope.h" #include "declarative_module_preloader.h" #include "event_handler.h" @@ -175,7 +176,7 @@ NativeValue* CanIUse(NativeEngine* engine, NativeCallbackInfo* info) HILOG_ERROR("Get syscap failed with invalid parameter."); return engine->CreateUndefined(); } - + char syscap[SYSCAP_MAX_SIZE] = { 0 }; NativeString* str = ConvertNativeValueTo(info->argv[0]); @@ -186,7 +187,7 @@ NativeValue* CanIUse(NativeEngine* engine, NativeCallbackInfo* info) size_t bufferLen = str->GetLength(); size_t strLen = 0; str->GetCString(syscap, bufferLen + 1, &strLen); - + bool ret = HasSystemCapability(syscap); return engine->CreateBoolean(ret); } @@ -422,12 +423,15 @@ bool JsRuntime::LoadModuleFile( return true; } +using OHOS::Ace::ContainerScope; class TimerTask final { public: TimerTask( JsRuntime& jsRuntime, std::shared_ptr jsFunction, const std::string &name, int64_t interval) : jsRuntime_(jsRuntime), jsFunction_(jsFunction), name_(name), interval_(interval) - {} + { + containerScopeId_ = ContainerScope::CurrentId(); + } ~TimerTask() = default; @@ -438,6 +442,7 @@ public: } // call js function + ContainerScope containerScope(containerScopeId_); HandleScope handleScope(jsRuntime_); std::vector args_; @@ -461,6 +466,7 @@ private: std::vector> jsArgs_; std::string name_; int64_t interval_ = 0; + int32_t containerScopeId_ = 0; }; void JsRuntime::PostTask(const TimerTask& task, const std::string& name, int64_t delayTime) diff --git a/interfaces/innerkits/runtime/BUILD.gn b/interfaces/innerkits/runtime/BUILD.gn index 4b5f112be4..e7a49183c4 100644 --- a/interfaces/innerkits/runtime/BUILD.gn +++ b/interfaces/innerkits/runtime/BUILD.gn @@ -58,6 +58,7 @@ ohos_shared_library("runtime") { deps = [ "//ark/js_runtime:libark_jsruntime", + "//foundation/ace/ace_engine/frameworks/core:ace_container_scope", "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", "//foundation/ace/napi:ace_napi", "//foundation/ace/napi:ace_napi_ark",