Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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,234 changes: 3,488 additions & 1,746 deletions NativeScript/ada/ada.cpp

Large diffs are not rendered by default.

7,876 changes: 5,513 additions & 2,363 deletions NativeScript/ada/ada.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions NativeScript/runtime/Runtime.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
720 changes: 720 additions & 0 deletions NativeScript/runtime/URLPatternImpl.cpp

Large diffs are not rendered by default.

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

#include "ada/ada.h"
#include "Common.h"
#include "Helpers.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);

};
}
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(null);
} 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
Expand Up @@ -82,6 +82,7 @@ require("./Timers");

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

// Tests common for all runtimes.
require("./shared/index").runAllTests();
Expand Down
20 changes: 14 additions & 6 deletions v8ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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>"; };
Expand Down Expand Up @@ -1372,6 +1376,8 @@
C2DDEB3B229EAB8600345BFE /* runtime */ = {
isa = PBXGroup;
children = (
F1CB51812D5C37100042555E /* URLPatternImpl.h */,
F1CB51822D5C37100042555E /* URLPatternImpl.cpp */,
F1F30E702B58FC74006A62C0 /* URLImpl.cpp */,
F1F30E732B58FC74006A62C0 /* URLImpl.h */,
F1F30E712B58FC74006A62C0 /* URLSearchParamsImpl.cpp */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading