diff --git a/native_engine/impl/ark/ark_native_engine.cpp b/native_engine/impl/ark/ark_native_engine.cpp index ab05f59291e88fcb6b2e49e2a9fbe1c4bb5167cd..d2f669036f947982276af752ccb67cab82a02f24 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) @@ -869,6 +872,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 @@ -893,7 +903,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 d1b892ac80d59a9e2eb2375405edd59dd2fc7b95..8b29ba688ba4cdba3db2dfb2f54e9822390b6747 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 };