diff --git a/interfaces/kits/js/src/mod_fs/class_watcher/ani/watch_event_listener.cpp b/interfaces/kits/js/src/mod_fs/class_watcher/ani/watch_event_listener.cpp index 36ac7517d6d286f627a4ffd4e5c05002e49928d0..d51d6a44ab9aa35c6f506ee4258d6c16bc56b915 100644 --- a/interfaces/kits/js/src/mod_fs/class_watcher/ani/watch_event_listener.cpp +++ b/interfaces/kits/js/src/mod_fs/class_watcher/ani/watch_event_listener.cpp @@ -79,17 +79,20 @@ void WatchEventListener::SendWatchEvent(const WatchEvent &watchEvent) const HILOGE("Cannot send WatchEvent because the callback is null."); return; } - ani_size scopeSize = ANI_SCOPE_SIZE; + ani_env *env = AniHelper::GetThreadEnv(vm); if (env == nullptr) { HILOGE("Cannot send WatchEvent because the env is null."); return; } + + ani_size scopeSize = ANI_SCOPE_SIZE; ani_status status = env->CreateLocalScope(scopeSize); if (status != ANI_OK) { HILOGE("Failed to creat local scope, status: %{public}d", static_cast(status)); return; } + auto evtObj = WatchEventWrapper::Wrap(env, watchEvent); if (evtObj == nullptr) { HILOGE("Create WatchEvent obj failed!"); @@ -102,7 +105,6 @@ void WatchEventListener::SendWatchEvent(const WatchEvent &watchEvent) const status = env->FunctionalObject_Call(cbObj, argc, args.data(), &result); if (status != ANI_OK) { HILOGE("Failed to call FunctionalObject_Call, status: %{public}d", static_cast(status)); - // continue execution and not exit. } status = env->DestroyLocalScope(); if (status != ANI_OK) {