Skip to content

feat: ada 3.1.1 including URLPattern support #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,292 changes: 3,517 additions & 1,775 deletions NativeScript/ada/ada.cpp

Large diffs are not rendered by default.

6,862 changes: 5,015 additions & 1,847 deletions NativeScript/ada/ada.h

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion NativeScript/runtime/ModuleBinding.hpp
Original file line number Diff line number Diff line change
@@ -60,7 +60,8 @@ namespace tns {
V(worker) \
V(timers) \
V(url) \
V(urlsearchparams)
V(urlsearchparams) \
V(urlpattern)

enum {
NM_F_BUILTIN = 1 << 0, // Unused.
1 change: 1 addition & 0 deletions NativeScript/runtime/Runtime.mm
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
#include "ModuleBinding.hpp"
#include "URLImpl.h"
#include "URLSearchParamsImpl.h"
#include "URLPatternImpl.h"

#define STRINGIZE(x) #x
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
689 changes: 689 additions & 0 deletions NativeScript/runtime/URLPatternImpl.cpp

Large diffs are not rendered by default.

92 changes: 92 additions & 0 deletions NativeScript/runtime/URLPatternImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// Created by Osei Fortune on 30/01/2025.
//
#pragma once

#include "Common.h"
#include "Helpers.h"
#include "ada/ada.h"
using namespace ada;
namespace tns {

class v8_regex_provider {
public:
using regex_type = v8::Global<v8::RegExp>;

static std::optional<regex_type> create_instance(std::string_view pattern,
bool ignore_case);

static std::optional<std::vector<std::optional<std::string>>> regex_search(
std::string_view input, const regex_type& pattern);

static bool regex_match(std::string_view input, const regex_type& pattern);
};

class URLPatternImpl {
public:
URLPatternImpl(url_pattern<v8_regex_provider> pattern);

static void Init(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> globalTemplate);

url_pattern<v8_regex_provider>* GetPattern();

static URLPatternImpl* GetPointer(v8::Local<v8::Object> object);

static v8::Local<v8::FunctionTemplate> GetCtor(v8::Isolate* isolate);

static void Ctor(const v8::FunctionCallbackInfo<v8::Value>& args);

static void GetHash(v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info);

static void GetHostName(v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info);

static void GetPassword(v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info);

static void GetPathName(v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info);

static void GetPort(v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info);

static void GetProtocol(v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info);

static void GetSearch(v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info);

static void GetUserName(v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info);

static void GetHasRegExpGroups(
v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info);

static void Test(const v8::FunctionCallbackInfo<v8::Value>& args);

static void Exec(const v8::FunctionCallbackInfo<v8::Value>& args);

void BindFinalizer(v8::Isolate* isolate,
const v8::Local<v8::Object>& object) {
v8::HandleScope scopedHandle(isolate);
weakHandle_.Reset(isolate, object);
weakHandle_.SetWeak(this, Finalizer, v8::WeakCallbackType::kParameter);
}

static void Finalizer(const v8::WeakCallbackInfo<URLPatternImpl>& data) {
auto* pThis = data.GetParameter();
pThis->weakHandle_.Reset();
delete pThis;
}

private:
url_pattern<v8_regex_provider> pattern_;
v8::Global<v8::Object> weakHandle_;

static std::optional<ada::url_pattern_init> ParseInput(
v8::Isolate* isolate, const v8::Local<v8::Value>& input);
};
} // namespace tns
49 changes: 49 additions & 0 deletions TestRunner/app/tests/URLPattern.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

describe("URLPattern", function () {
it("throws on invalid URLPattern", function () {
var exceptionCaught = false;
try {
const pattern = new URLPattern(1);
} catch (e) {
exceptionCaught = true;
}
expect(exceptionCaught).toBe(true);
});

it("does not throw on valid URLPattern", function () {
var exceptionCaught = false;
try {
const pattern = new URLPattern("https://example.com/books/:id");
} catch (e) {
exceptionCaught = true;
}
expect(exceptionCaught).toBe(false);
});

it("parses simple pattern", function () {
const pattern = new URLPattern("https://example.com/books/:id");
expect(pattern.protocol).toBe("https");
expect(pattern.hostname).toBe("example.com");
expect(pattern.pathname).toBe("/books/:id");
expect(pattern.port).toBe("");
expect(pattern.search).toBe("*");
expect(pattern.hash).toBe("*");
expect(pattern.username).toBe("*");
expect(pattern.password).toBe("*");
expect(pattern.hasRegExpGroups).toBe(false);
});


it("parses with undefined base", function () {
const pattern = new URLPattern("https://google.com", undefined);
expect(pattern.protocol).toBe("https");
expect(pattern.hostname).toBe("google.com");
});

it("parses with null base", function () {
const pattern = new URLPattern("https://google.com", null);
expect(pattern.protocol).toBe("https");
expect(pattern.hostname).toBe("google.com");
});

});
1 change: 1 addition & 0 deletions TestRunner/app/tests/index.js
Original file line number Diff line number Diff line change
@@ -82,6 +82,7 @@ require("./Timers");

require("./URL");
require("./URLSearchParams");
require("./URLPattern");

// Tests common for all runtimes.
require("./shared/index").runAllTests();
20 changes: 14 additions & 6 deletions v8ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -319,6 +319,8 @@
C2F64E8322E870A300EDB057 /* NativeScript.mm in Sources */ = {isa = PBXBuildFile; fileRef = C2F64E8222E870A300EDB057 /* NativeScript.mm */; };
C2FEA16F22A3C75C00A5C0FC /* InlineFunctions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C2FEA16D22A3C75C00A5C0FC /* InlineFunctions.cpp */; };
C2FEA17022A3C75C00A5C0FC /* InlineFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = C2FEA16E22A3C75C00A5C0FC /* InlineFunctions.h */; };
F1CB51832D5C37100042555E /* URLPatternImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F1CB51822D5C37100042555E /* URLPatternImpl.cpp */; };
F1CB51842D5C37100042555E /* URLPatternImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = F1CB51812D5C37100042555E /* URLPatternImpl.h */; };
F1F30E742B58FC74006A62C0 /* URLImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F1F30E702B58FC74006A62C0 /* URLImpl.cpp */; };
F1F30E752B58FC74006A62C0 /* URLSearchParamsImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F1F30E712B58FC74006A62C0 /* URLSearchParamsImpl.cpp */; };
F1F30E762B58FC74006A62C0 /* URLSearchParamsImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = F1F30E722B58FC74006A62C0 /* URLSearchParamsImpl.h */; };
@@ -818,6 +820,8 @@
C2FF3017225203FD00933782 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
C2FF301C2252062A00933782 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
C2FF301F2252065E00933782 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
F1CB51812D5C37100042555E /* URLPatternImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = URLPatternImpl.h; sourceTree = "<group>"; };
F1CB51822D5C37100042555E /* URLPatternImpl.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = URLPatternImpl.cpp; sourceTree = "<group>"; };
F1F30E702B58FC74006A62C0 /* URLImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URLImpl.cpp; sourceTree = "<group>"; };
F1F30E712B58FC74006A62C0 /* URLSearchParamsImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URLSearchParamsImpl.cpp; sourceTree = "<group>"; };
F1F30E722B58FC74006A62C0 /* URLSearchParamsImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = URLSearchParamsImpl.h; sourceTree = "<group>"; };
@@ -1372,6 +1376,8 @@
C2DDEB3B229EAB8600345BFE /* runtime */ = {
isa = PBXGroup;
children = (
F1CB51812D5C37100042555E /* URLPatternImpl.h */,
F1CB51822D5C37100042555E /* URLPatternImpl.cpp */,
F1F30E702B58FC74006A62C0 /* URLImpl.cpp */,
F1F30E732B58FC74006A62C0 /* URLImpl.h */,
F1F30E712B58FC74006A62C0 /* URLSearchParamsImpl.cpp */,
@@ -1543,6 +1549,7 @@
F6191AB129C0FCE8003F588F /* InspectorServer.h in Headers */,
C247C16722F82842001D2CA2 /* libplatform.h in Headers */,
C2DDEBA4229EAC8300345BFE /* Runtime.h in Headers */,
F1CB51842D5C37100042555E /* URLPatternImpl.h in Headers */,
F1F30E8B2B58FE28006A62C0 /* ada.h in Headers */,
C2DDEB8D229EAC8300345BFE /* Common.h in Headers */,
C247C17122F82842001D2CA2 /* v8config.h in Headers */,
@@ -2177,6 +2184,7 @@
F6191AB029C0FCE8003F588F /* JsV8InspectorClient.mm in Sources */,
C2DDEB9C229EAC8300345BFE /* ClassBuilder.cpp in Sources */,
C266569322AFFF7E00EE15CC /* Pointer.cpp in Sources */,
F1CB51832D5C37100042555E /* URLPatternImpl.cpp in Sources */,
C2DDEB93229EAC8300345BFE /* ArgConverter.mm in Sources */,
C22C092222CA3F370080D176 /* Worker.mm in Sources */,
C2C8EE7A22CF64E4001F8CEC /* SimpleAllocator.cpp in Sources */,
@@ -2433,7 +2441,7 @@
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
@@ -2496,7 +2504,7 @@
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
@@ -2676,7 +2684,7 @@
C2DDEB2A229EA89200345BFE /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_CXX_LANGUAGE_STANDARD = "c++20";
CLANG_CXX_LIBRARY = "compiler-default";
CLANG_ENABLE_MODULES = NO;
CODE_SIGN_IDENTITY = "Apple Development";
@@ -2731,7 +2739,7 @@
C2DDEB2B229EA89200345BFE /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_CXX_LANGUAGE_STANDARD = "c++20";
CLANG_CXX_LIBRARY = "compiler-default";
CLANG_ENABLE_MODULES = NO;
CODE_SIGN_IDENTITY = "Apple Development";
@@ -2788,7 +2796,7 @@
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = NO;
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_CXX_LANGUAGE_STANDARD = "c++20";
CLANG_ENABLE_MODULES = NO;
CLANG_ENABLE_OBJC_ARC = NO;
CURRENT_PROJECT_VERSION = 1;
@@ -2883,7 +2891,7 @@
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = NO;
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_CXX_LANGUAGE_STANDARD = "c++20";
CLANG_ENABLE_MODULES = NO;
CLANG_ENABLE_OBJC_ARC = NO;
CURRENT_PROJECT_VERSION = 1;