diff --git a/ecmascript/napi/include/jsnapi_expo.h b/ecmascript/napi/include/jsnapi_expo.h index 393f8cec4b..cb5c59a17e 100644 --- a/ecmascript/napi/include/jsnapi_expo.h +++ b/ecmascript/napi/include/jsnapi_expo.h @@ -1033,6 +1033,18 @@ private: bool isRevert_ = false; }; +class ECMA_PUBLIC_API JsiNativeScope { +public: + explicit JsiNativeScope(const EcmaVM *vm); + ~JsiNativeScope(); + ECMA_DISALLOW_COPY(JsiNativeScope); + ECMA_DISALLOW_MOVE(JsiNativeScope); + +private: + JSThread *thread_; + uint16_t oldThreadState_; +}; + /** * JsiRuntimeCallInfo is used for ace_engine and napi, is same to ark EcamRuntimeCallInfo except data. */ diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index 7768c3354d..ff28561516 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -2728,6 +2728,20 @@ JSExecutionScope::~JSExecutionScope() isRevert_ = false; } +// ------------------------------------ JsiNativeScope ----------------------------------------------- + +JsiNativeScope::JsiNativeScope(const EcmaVM *vm) +{ + thread_ = vm->GetAssociatedJSThread(); + oldThreadState_ = static_cast(thread_->GetState()); + thread_->UpdateState(ecmascript::ThreadState::NATIVE); +} + +JsiNativeScope::~JsiNativeScope() +{ + thread_->UpdateState(static_cast(oldThreadState_)); +} + // ------------------------------------ JsiRuntimeCallInfo ----------------------------------------------- void *JsiRuntimeCallInfo::GetData() { diff --git a/libark_jsruntime.map b/libark_jsruntime.map index 130b2eb5e1..956a88aa15 100644 --- a/libark_jsruntime.map +++ b/libark_jsruntime.map @@ -69,6 +69,7 @@ panda::Exception::*; panda::JSON::*; panda::JsiRuntimeCallInfo::*; + panda::JsiNativeScope::*; panda::JSExecutionScope::*; panda::ecmascript::Log::*;