diff --git a/.gitignore b/.gitignore index 08fb1b04..a3003258 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,7 @@ v8_build /project-template-ios/.build_env_vars.sh /project-template-ios/__PROJECT_NAME__.xcodeproj/project.xcworkspace/xcshareddata/ /project-template-vision/.build_env_vars.sh -/project-template-vision/__PROJECT_NAME__.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist \ No newline at end of file +/project-template-vision/__PROJECT_NAME__.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist + +# test262 +dist-test/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index fa45c83c..9aaa9e62 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,6 @@ path = libffi url = https://github.com/NativeScript/libffi.git branch = darind/v8-ios +[submodule "TestRunner/app/tests/vendor/test262"] + path = TestRunner/app/tests/vendor/test262 + url = https://github.com/tc39/test262.git diff --git a/NativeScript/inspector/JsV8InspectorClient.mm b/NativeScript/inspector/JsV8InspectorClient.mm index fafe0c68..60210f56 100644 --- a/NativeScript/inspector/JsV8InspectorClient.mm +++ b/NativeScript/inspector/JsV8InspectorClient.mm @@ -22,6 +22,13 @@ namespace v8_inspector { +namespace { +StringView Make8BitStringView(const std::string& value) { + return StringView(reinterpret_cast(value.data()), + value.size()); +} +} // namespace + #define NOTIFICATION(name) \ [[NSString stringWithFormat:@"%@:NativeScript.Debug.%s", \ [[NSBundle mainBundle] bundleIdentifier], name] UTF8String] @@ -257,8 +264,7 @@ } void JsV8InspectorClient::dispatchMessage(const std::string& message) { - std::vector vector = tns::ToVector(message); - StringView messageView(vector.data(), vector.size()); + StringView messageView = Make8BitStringView(message); Isolate* isolate = isolate_; v8::Locker locker(isolate); Isolate::Scope isolate_scope(isolate); @@ -343,8 +349,7 @@ auto returnString = GetReturnMessageFromDomainHandlerResult(result, requestId); if (returnString.size() > 0) { - std::vector vector = tns::ToVector(returnString); - StringView messageView(vector.data(), vector.size()); + StringView messageView = Make8BitStringView(returnString); auto msg = StringBuffer::create(messageView); this->sendNotification(std::move(msg)); } @@ -486,8 +491,7 @@ Local arg = args[0].As(); std::string message = tns::ToString(isolate, arg); - std::vector vector = tns::ToVector(message); - StringView messageView(vector.data(), vector.size()); + StringView messageView = Make8BitStringView(message); auto msg = StringBuffer::create(messageView); client->sendNotification(std::move(msg)); } diff --git a/NativeScript/inspector/src/inspector/string-16.h b/NativeScript/inspector/src/inspector/string-16.h index 7dfc5e34..ac9892f5 100644 --- a/NativeScript/inspector/src/inspector/string-16.h +++ b/NativeScript/inspector/src/inspector/string-16.h @@ -17,7 +17,7 @@ namespace v8_inspector { -using UChar = uint16_t; +using UChar = char16_t; class String16 { public: diff --git a/NativeScript/inspector/src/inspector/string-util.h b/NativeScript/inspector/src/inspector/string-util.h index 7f427d9b..82055588 100644 --- a/NativeScript/inspector/src/inspector/string-util.h +++ b/NativeScript/inspector/src/inspector/string-util.h @@ -30,13 +30,13 @@ class StringUtil { } static String fromUTF16LE(const uint16_t* data, size_t length) { - return String16::fromUTF16LE(data, length); + return String16::fromUTF16LE(reinterpret_cast(data), length); } static const uint8_t* CharactersLatin1(const String& s) { return nullptr; } static const uint8_t* CharactersUTF8(const String& s) { return nullptr; } static const uint16_t* CharactersUTF16(const String& s) { - return s.characters16(); + return reinterpret_cast(s.characters16()); } static size_t CharacterCount(const String& s) { return s.length(); } }; diff --git a/NativeScript/inspector/utils.mm b/NativeScript/inspector/utils.mm index d078e525..63a1f898 100644 --- a/NativeScript/inspector/utils.mm +++ b/NativeScript/inspector/utils.mm @@ -35,17 +35,16 @@ } std::string v8_inspector::ToStdString(const StringView& value) { - std::vector buffer(value.length()); + std::u16string value16; + value16.resize(value.length()); for (size_t i = 0; i < value.length(); i++) { if (value.is8Bit()) { - buffer[i] = value.characters8()[i]; + value16[i] = static_cast(value.characters8()[i]); } else { - buffer[i] = value.characters16()[i]; + value16[i] = static_cast(value.characters16()[i]); } } - std::u16string value16(buffer.begin(), buffer.end()); - #pragma GCC diagnostic ignored "-Wdeprecated-declarations" // FIXME: std::codecvt_utf8_utf16 is deprecated std::wstring_convert, char16_t> convert; diff --git a/NativeScript/runtime/ModuleInternal.h b/NativeScript/runtime/ModuleInternal.h index 9fae6239..f62b9a0c 100644 --- a/NativeScript/runtime/ModuleInternal.h +++ b/NativeScript/runtime/ModuleInternal.h @@ -13,6 +13,8 @@ class ModuleInternal { void RunScript(v8::Isolate* isolate, std::string script); static v8::Local LoadScript(v8::Isolate* isolate, const std::string& path); + static v8::Local LoadSourceTextModule(v8::Isolate* isolate, + const std::string& path); private: static void RequireCallback(const v8::FunctionCallbackInfo& info); @@ -28,6 +30,9 @@ class ModuleInternal { // Compile/link/evaluate an ES module; returns its namespace object. static v8::Local LoadESModule(v8::Isolate* isolate, const std::string& path); + static v8::Local LoadESModule(v8::Isolate* isolate, + const std::string& path, + bool suppressInDebug); static v8::Local WrapModuleContent(v8::Isolate* isolate, const std::string& path); v8::Local LoadModule(v8::Isolate* isolate, diff --git a/NativeScript/runtime/ModuleInternal.mm b/NativeScript/runtime/ModuleInternal.mm index b55a5cb2..76ad41a6 100644 --- a/NativeScript/runtime/ModuleInternal.mm +++ b/NativeScript/runtime/ModuleInternal.mm @@ -56,6 +56,36 @@ bool IsESModule(const std::string& path) { return std::string([standardized UTF8String]); } +static bool ShouldTreatAsForcedSourceTextModule(v8::Isolate* isolate, + const std::string& path) { + v8::Local context = isolate->GetCurrentContext(); + v8::Local global = context->Global(); + + v8::Local enabledValue; + if (!global->Get(context, tns::ToV8String(isolate, "__test262ForceModule")) + .ToLocal(&enabledValue) || + !enabledValue->BooleanValue(isolate)) { + return false; + } + + v8::Local rootValue; + if (!global->Get(context, tns::ToV8String(isolate, "__test262ModuleRoot")) + .ToLocal(&rootValue) || + rootValue.IsEmpty() || !rootValue->IsString()) { + return false; + } + + std::string root = NormalizePath(tns::ToString(isolate, rootValue)); + std::string normalizedPath = NormalizePath(path); + if (root.empty() || normalizedPath.size() < root.size() || + normalizedPath.compare(0, root.size(), root) != 0) { + return false; + } + + return normalizedPath.size() >= 3 && + normalizedPath.compare(normalizedPath.size() - 3, 3, ".js") == 0; +} + // Helper function to resolve main entry from package.json with proper extension handling std::string ResolveMainEntryFromPackageJson(const std::string& baseDir) { // Get the main value from package.json @@ -708,7 +738,7 @@ throw NativeScriptException(isolate, if (IsESModule(canonicalPath)) { // Treat all .mjs files as standard ES modules. - return ModuleInternal::LoadESModule(isolate, canonicalPath); + return ModuleInternal::LoadESModule(isolate, canonicalPath, true); } Local