From 55c5c5198f04ff2b5cbe1be6f5add92acb3ed23f Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Fri, 6 Sep 2024 08:56:18 -0300 Subject: [PATCH 01/11] fix: revert visionOS changes to iOS project template --- .../__PROJECT_NAME__.xcodeproj/project.pbxproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/project-template-ios/__PROJECT_NAME__.xcodeproj/project.pbxproj b/project-template-ios/__PROJECT_NAME__.xcodeproj/project.pbxproj index 8e2eaa92..142e4274 100644 --- a/project-template-ios/__PROJECT_NAME__.xcodeproj/project.pbxproj +++ b/project-template-ios/__PROJECT_NAME__.xcodeproj/project.pbxproj @@ -314,7 +314,7 @@ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = NO; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; @@ -356,6 +356,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 13.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + STRIP_SWIFT_SYMBOLS = NO; SUPPORTS_UIKITFORMAC = YES; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/internal/Swift-ObjC-Bridging-Header.h"; SWIFT_VERSION = 4.2; @@ -370,7 +371,7 @@ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = NO; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; @@ -408,6 +409,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 13.0; SDKROOT = iphoneos; + STRIP_SWIFT_SYMBOLS = NO; SUPPORTS_UIKITFORMAC = YES; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/internal/Swift-ObjC-Bridging-Header.h"; SWIFT_VERSION = 4.2; From 9d9f4aef03907908961ca6784220fa8aba9e5c03 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Fri, 6 Sep 2024 09:40:21 -0300 Subject: [PATCH 02/11] 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