add containerScopeId in async func

Signed-off-by: huzeqi <huzeqi@huawei.com>
Change-Id: Ic010de421318fb47c5b08bc9874b7acc8bfbcd4a
This commit is contained in:
huzeqi
2022-03-04 00:39:45 +08:00
parent d4fd6b1987
commit 3723095c97
9 changed files with 65 additions and 1 deletions
+5
View File
@@ -60,6 +60,11 @@ template("ace_napi_impl") {
"//foundation/ace/napi:ace_napi",
]
if (product_name != "ohos-sdk") {
deps += [ "$ace_root/frameworks/core:ace_container_scope" ]
defines += [ "ENABLE_CONTAINER_SCOPE" ]
}
cflags_cc = [ "-Wno-missing-braces" ]
external_deps = hilog_deps
}
@@ -15,6 +15,10 @@
#include "ark_native_engine.h"
#ifdef ENABLE_CONTAINER_SCOPE
#include "core/common/container_scope.h"
#endif
#include "ark_native_deferred.h"
using panda::Global;
@@ -23,6 +27,9 @@ using panda::JSValueRef;
ArkNativeDeferred::ArkNativeDeferred(ArkNativeEngine* engine, Local<PromiseCapabilityRef> deferred)
: engine_(engine), deferred_(engine->GetEcmaVm(), deferred)
{
#ifdef ENABLE_CONTAINER_SCOPE
scopeId_ = OHOS::Ace::ContainerScope::CurrentId();
#endif
}
ArkNativeDeferred::~ArkNativeDeferred()
@@ -33,6 +40,9 @@ ArkNativeDeferred::~ArkNativeDeferred()
void ArkNativeDeferred::Resolve(NativeValue* data)
{
#ifdef ENABLE_CONTAINER_SCOPE
OHOS::Ace::ContainerScope containerScope(scopeId_);
#endif
auto vm = engine_->GetEcmaVm();
LocalScope scope(vm);
Global<JSValueRef> value = *data;
@@ -41,6 +51,9 @@ void ArkNativeDeferred::Resolve(NativeValue* data)
void ArkNativeDeferred::Reject(NativeValue* reason)
{
#ifdef ENABLE_CONTAINER_SCOPE
OHOS::Ace::ContainerScope containerScope(scopeId_);
#endif
auto vm = engine_->GetEcmaVm();
LocalScope scope(vm);
Global<JSValueRef> value = *reason;
@@ -31,6 +31,9 @@ public:
private:
ArkNativeEngine* engine_;
panda::Global<PromiseCapabilityRef> deferred_;
#ifdef ENABLE_CONTAINER_SCOPE
int32_t scopeId_ = -1;
#endif
};
#endif /* FOUNDATION_ACE_NAPI_NATIVE_ENGINE_ARK_NATIVE_DEFERRED_H */
+9 -1
View File
@@ -18,6 +18,10 @@
#include "ark_native_deferred.h"
#include "ark_native_reference.h"
#ifdef ENABLE_CONTAINER_SCOPE
#include "core/common/container_scope.h"
#endif
#include "native_engine/native_property.h"
#include "native_value/ark_native_array.h"
@@ -395,7 +399,11 @@ NativeValue* ArkNativeEngine::CallFunction(NativeValue* thisVar,
LocalScope scope(vm_);
Global<JSValueRef> thisObj = (thisVar != nullptr) ? *thisVar : Global<JSValueRef>(vm_, JSValueRef::Undefined(vm_));
Global<FunctionRef> funcObj = *function;
#ifdef ENABLE_CONTAINER_SCOPE
auto nativeFunction = static_cast<NativeFunction*>(function->GetInterface(NativeFunction::INTERFACE_ID));
auto arkNativeFunc = static_cast<ArkNativeFunction*>(nativeFunction);
OHOS::Ace::ContainerScope containerScope(arkNativeFunc->GetScopeId());
#endif
std::vector<Local<JSValueRef>> args;
args.reserve(argc);
for (size_t i = 0; i < argc; i++) {
@@ -17,6 +17,10 @@
#include "ark_native_reference.h"
#ifdef ENABLE_CONTAINER_SCOPE
#include "core/common/container_scope.h"
#endif
#include "utils/log.h"
ArkNativeReference::ArkNativeReference(ArkNativeEngine* engine, NativeValue* value, uint32_t initialRefcount,
@@ -32,6 +36,10 @@ ArkNativeReference::ArkNativeReference(ArkNativeEngine* engine, NativeValue* val
if (initialRefcount == 0) {
value_.SetWeak();
}
#ifdef ENABLE_CONTAINER_SCOPE
scopeId_ = OHOS::Ace::ContainerScope::CurrentId();
#endif
}
ArkNativeReference::~ArkNativeReference()
@@ -70,6 +78,9 @@ NativeValue* ArkNativeReference::Get()
auto vm = engine_->GetEcmaVm();
LocalScope scope(vm);
Local<JSValueRef> value = value_.ToLocal(vm);
#ifdef ENABLE_CONTAINER_SCOPE
OHOS::Ace::ContainerScope containerScope(scopeId_);
#endif
return ArkNativeEngine::ArkValueToNativeValue(engine_, value);
}
@@ -42,6 +42,10 @@ private:
Global<JSValueRef> value_;
uint32_t refCount_;
#ifdef ENABLE_CONTAINER_SCOPE
int32_t scopeId_ = -1;
#endif
NativeFinalize callback_ = nullptr;
void* data_ = nullptr;
void* hint_ = nullptr;
@@ -15,6 +15,10 @@
#include "ark_native_function.h"
#ifdef ENABLE_CONTAINER_SCOPE
#include "core/common/container_scope.h"
#endif
#include "utils/log.h"
using panda::ArrayRef;
@@ -23,6 +27,9 @@ using panda::FunctionRef;
using panda::StringRef;
ArkNativeFunction::ArkNativeFunction(ArkNativeEngine* engine, Local<JSValueRef> value) : ArkNativeObject(engine, value)
{
#ifdef ENABLE_CONTAINER_SCOPE
scopeId_ = OHOS::Ace::ContainerScope::CurrentId();
#endif
}
// common function
@@ -29,6 +29,13 @@ public:
NativeValue* GetFunctionPrototype();
#ifdef ENABLE_CONTAINER_SCOPE
inline int32_t GetScopeId()
{
return scopeId_;
}
#endif
private:
static Local<JSValueRef> NativeFunctionCallBack(EcmaVM* vm,
Local<JSValueRef> thisObj,
@@ -41,6 +48,9 @@ private:
const Local<JSValueRef> argv[],
int32_t length,
void* data);
#ifdef ENABLE_CONTAINER_SCOPE
int32_t scopeId_ = -1;
#endif
};
#endif /* FOUNDATION_ACE_NAPI_NATIVE_ENGINE_IMPL_ARK_NATIVE_VALUE_ARK_NATIVE_FUNCTION_H */
+3
View File
@@ -86,6 +86,9 @@ void NativeAsyncWork::AsyncWorkRecvCallback(const uv_async_t* req)
if (that == nullptr) {
return;
}
#ifdef ENABLE_CONTAINER_SCOPE
ContainerScope containerScope(that->containerScopeId_);
#endif
NativeAsyncWorkDataPointer res;
while (that->PopData(&res)) {
if (that->execute_ != nullptr) {