From 41a75884fa8f6bdb5017aa4795d119c04c782934 Mon Sep 17 00:00:00 2001 From: xiongjojo <857612965@qq.com> Date: Thu, 28 Aug 2025 15:30:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=87=E4=BB=B6=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongjojo <857612965@qq.com> --- native_engine/impl/ark/ark_native_engine.cpp | 16 +++++++++++++++- native_engine/impl/ark/ark_native_engine.h | 7 ++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/native_engine/impl/ark/ark_native_engine.cpp b/native_engine/impl/ark/ark_native_engine.cpp index a80f49f6c..6dc8b8d73 100644 --- a/native_engine/impl/ark/ark_native_engine.cpp +++ b/native_engine/impl/ark/ark_native_engine.cpp @@ -131,6 +131,9 @@ bool ArkNativeEngine::napiProfilerEnabled {false}; bool ArkNativeEngine::napiProfilerParamReaded {false}; PermissionCheckCallback ArkNativeEngine::permissionCheckCallback_ {nullptr}; std::atomic ArkNativeEngine::moduleValidateCallback_ {nullptr}; +#if defined(PREVIEW) +bool ArkNativeEngine::enableFileOperation_ {false}; +#endif // This interface is using by ace_engine napi_value LocalValueToLocalNapiValue(panda::Local local) @@ -871,6 +874,13 @@ Local ArkNativeEngine::LoadNativeModule( return scope.Escape(exports); } +#if defined(PREVIEW) +void ArkNativeEngine::SetCurrentPreviewenv(bool enableFileOperation) +{ + enableFileOperation_ = enableFileOperation; +} +#endif + /** require napi module for Ark Native Engine (standard napi_env). * * TypeScript declaration @@ -895,7 +905,11 @@ Local ArkNativeEngine::RequireNapi(JsiRuntimeCallInfo *info) return scope.Escape(exports); } Local moduleName(info->GetCallArgRef(0)); - +#if defined(PREVIEW) + if (!enableFileOperation_ && (moduleName->ToString(ecmaVm) == "file.fs")) { + return scope.Escape(JSValueRef::Undefined(ecmaVm)); + } +#endif bool isAppModule = false; if (info->GetArgsNumber() > 1) { // 1: index of arguments, isAppModule Local ret(info->GetCallArgRef(1)); diff --git a/native_engine/impl/ark/ark_native_engine.h b/native_engine/impl/ark/ark_native_engine.h index d1b892ac8..7eed92a34 100644 --- a/native_engine/impl/ark/ark_native_engine.h +++ b/native_engine/impl/ark/ark_native_engine.h @@ -455,7 +455,9 @@ public: napi_status DestroyContext() override; void NotifyVMIgnoreFinalizeCallback() const override; - +#if defined(PREVIEW) + static void SetCurrentPreviewenv(bool enableFileOperation); +#endif private: // ArkNativeEngine constructor for multi-context ArkNativeEngine(NativeEngine* parent, EcmaVM* vm, const Local& context); @@ -523,6 +525,9 @@ private: // for context env ArkNativeEngine* parentEngine_ { nullptr }; static std::atomic moduleValidateCallback_; +#if defined(PREVIEW) + static bool enableFileOperation_; + #endif NapiConcurrentCallback concurrentCallbackFunc_ { nullptr }; NativeReference* promiseRejectCallbackRef_ { nullptr }; -- Gitee