From 9d9f4aef03907908961ca6784220fa8aba9e5c03 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Fri, 6 Sep 2024 09:40:21 -0300 Subject: [PATCH] chore: clang format ModuleInternal files --- NativeScript/runtime/ModuleInternal.h | 118 ++-- NativeScript/runtime/ModuleInternal.mm | 784 +++++++++++++------------ 2 files changed, 477 insertions(+), 425 deletions(-) diff --git a/NativeScript/runtime/ModuleInternal.h b/NativeScript/runtime/ModuleInternal.h index b81ada9a..25d223e9 100644 --- a/NativeScript/runtime/ModuleInternal.h +++ b/NativeScript/runtime/ModuleInternal.h @@ -7,57 +7,75 @@ namespace tns { class ModuleInternal { -public: - ModuleInternal(v8::Local context); - bool RunModule(v8::Isolate* isolate, std::string path); - void RunScript(v8::Isolate* isolate, std::string script); - -private: - static void RequireCallback(const v8::FunctionCallbackInfo& info); - v8::Local GetRequireFunction(v8::Isolate* isolate, const std::string& dirName); - v8::Local LoadImpl(v8::Isolate* isolate, const std::string& moduleName, const std::string& baseDir, bool& isData); - v8::Local LoadScript(v8::Isolate* isolate, const std::string& path); - v8::Local WrapModuleContent(v8::Isolate* isolate, const std::string& path); - v8::Local LoadModule(v8::Isolate* isolate, const std::string& modulePath, const std::string& cacheKey); - v8::Local LoadData(v8::Isolate* isolate, const std::string& modulePath); - std::string ResolvePath(v8::Isolate* isolate, const std::string& baseDir, const std::string& moduleName); - std::string ResolvePathFromPackageJson(const std::string& packageJson, bool& error); - v8::ScriptCompiler::CachedData* LoadScriptCache(const std::string& path); - void SaveScriptCache(const v8::Local script, const std::string& path); - std::string GetCacheFileName(const std::string& path); - v8::MaybeLocal RunScriptString(v8::Isolate* isolate, v8::Local context, const std::string script); - - - std::unique_ptr> requireFunction_; - std::unique_ptr> requireFactoryFunction_; - robin_hood::unordered_map>> loadedModules_; - - struct TempModule { - public: - TempModule(ModuleInternal* module, std::string modulePath, std::string cacheKey, std::shared_ptr> poModuleObj) - : module_(module), dispose_(true), modulePath_(modulePath), cacheKey_(cacheKey) { - module->loadedModules_.emplace(modulePath, poModuleObj); - module->loadedModules_.emplace(cacheKey, poModuleObj); - } - - ~TempModule() { - if (this->dispose_) { - this->module_->loadedModules_.erase(modulePath_); - this->module_->loadedModules_.erase(cacheKey_); - } - } - - void SaveToCache() { - this->dispose_ = false; - } - private: - ModuleInternal* module_; - bool dispose_; - std::string modulePath_; - std::string cacheKey_; - }; + public: + ModuleInternal(v8::Local context); + bool RunModule(v8::Isolate* isolate, std::string path); + void RunScript(v8::Isolate* isolate, std::string script); + + private: + static void RequireCallback(const v8::FunctionCallbackInfo& info); + v8::Local GetRequireFunction(v8::Isolate* isolate, + const std::string& dirName); + v8::Local LoadImpl(v8::Isolate* isolate, + const std::string& moduleName, + const std::string& baseDir, bool& isData); + v8::Local LoadScript(v8::Isolate* isolate, + const std::string& path); + v8::Local WrapModuleContent(v8::Isolate* isolate, + const std::string& path); + v8::Local LoadModule(v8::Isolate* isolate, + const std::string& modulePath, + const std::string& cacheKey); + v8::Local LoadData(v8::Isolate* isolate, + const std::string& modulePath); + std::string ResolvePath(v8::Isolate* isolate, const std::string& baseDir, + const std::string& moduleName); + std::string ResolvePathFromPackageJson(const std::string& packageJson, + bool& error); + v8::ScriptCompiler::CachedData* LoadScriptCache(const std::string& path); + void SaveScriptCache(const v8::Local script, + const std::string& path); + std::string GetCacheFileName(const std::string& path); + v8::MaybeLocal RunScriptString(v8::Isolate* isolate, + v8::Local context, + const std::string script); + + std::unique_ptr> requireFunction_; + std::unique_ptr> requireFactoryFunction_; + robin_hood::unordered_map>> + loadedModules_; + + struct TempModule { + public: + TempModule(ModuleInternal* module, std::string modulePath, + std::string cacheKey, + std::shared_ptr> poModuleObj) + : module_(module), + dispose_(true), + modulePath_(modulePath), + cacheKey_(cacheKey) { + module->loadedModules_.emplace(modulePath, poModuleObj); + module->loadedModules_.emplace(cacheKey, poModuleObj); + } + + ~TempModule() { + if (this->dispose_) { + this->module_->loadedModules_.erase(modulePath_); + this->module_->loadedModules_.erase(cacheKey_); + } + } + + void SaveToCache() { this->dispose_ = false; } + + private: + ModuleInternal* module_; + bool dispose_; + std::string modulePath_; + std::string cacheKey_; + }; }; -} +} // namespace tns #endif /* ModuleInternal_h */ diff --git a/NativeScript/runtime/ModuleInternal.mm b/NativeScript/runtime/ModuleInternal.mm index 59292202..cd7aff47 100644 --- a/NativeScript/runtime/ModuleInternal.mm +++ b/NativeScript/runtime/ModuleInternal.mm @@ -1,468 +1,502 @@ +#include "ModuleInternal.h" #include -#include #include -#include "ModuleInternal.h" -#include "NativeScriptException.h" -#include "RuntimeConfig.h" +#include #include "Caches.h" #include "Helpers.h" +#include "NativeScriptException.h" +#include "RuntimeConfig.h" using namespace v8; namespace tns { ModuleInternal::ModuleInternal(Local context) { - std::string requireFactoryScript = - "(function() { " - " function require_factory(requireInternal, dirName) { " - " return function require(modulePath) { " - " if(global.__pauseOnNextRequire) { debugger; global.__pauseOnNextRequire = false; }" - " return requireInternal(modulePath, dirName); " - " } " - " } " - " return require_factory; " - "})()"; - - Isolate* isolate = context->GetIsolate(); - Local global = context->Global(); - Local