Skip to content
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

feat: ada v3 #1830

Merged
merged 3 commits into from
Feb 20, 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
49 changes: 49 additions & 0 deletions test-app/app/src/main/assets/app/tests/testURLPattern.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");
});

});
10 changes: 5 additions & 5 deletions test-app/gradle.properties
Original file line number Diff line number Diff line change
@@ -21,15 +21,15 @@ android.useAndroidX=true
# Default versions used throughout the gradle configurations
NS_DEFAULT_BUILD_TOOLS_VERSION=35.0.0
NS_DEFAULT_COMPILE_SDK_VERSION=35
NS_DEFAULT_MIN_SDK_VERSION=17
NS_DEFAULT_ANDROID_BUILD_TOOLS_VERSION=8.5.0
NS_DEFAULT_MIN_SDK_VERSION=21
NS_DEFAULT_ANDROID_BUILD_TOOLS_VERSION=8.7.0

ns_default_androidx_appcompat_version = 1.5.1
ns_default_androidx_appcompat_version = 1.7.0
ns_default_androidx_exifinterface_version = 1.3.7
ns_default_androidx_fragment_version = 1.5.7
ns_default_androidx_fragment_version = 1.8.5
ns_default_androidx_material_version = 1.8.0
ns_default_androidx_multidex_version = 2.0.1
ns_default_androidx_transition_version = 1.4.1
ns_default_androidx_transition_version = 1.5.1
ns_default_androidx_viewpager_version = 1.0.0
ns_default_asm_util_version = 9.7
ns_default_asm_version = 9.7
3 changes: 2 additions & 1 deletion test-app/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Tue Feb 11 10:56:28 AST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 5 additions & 7 deletions test-app/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Command info: https://cmake.org/cmake/help/v3.4/command/cmake_minimum_required.html
cmake_minimum_required(VERSION 3.4.1)
cmake_minimum_required(VERSION 3.18.1)

project(NativeScriptAndroidRuntime)

@@ -18,13 +18,14 @@ endif (CCACHE_FOUND AND (USE_CCACHE))
# "-DANDROID_STL=c++_static" is just not enough for clang++ to find some libraries in the ndk
MESSAGE(STATUS "## ANDROID_NDK_ROOT: " ${ANDROID_NDK_ROOT})

set(COMMON_CMAKE_ARGUMENTS "-std=c++17 -Werror -Wno-unused-result -mstackrealign -fexceptions -fno-builtin-stpcpy -fno-rtti -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -DV8_EMBEDDED_BUILTINS")
set(COMMON_CMAKE_ARGUMENTS "-std=c++20 -Werror -Wno-vla-cxx-extension -Wno-unused-result -mstackrealign -fexceptions -fno-builtin-stpcpy -fno-rtti -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -DV8_EMBEDDED_BUILTINS")

if("${ANDROID_ABI}" MATCHES "arm64-v8a$" OR "${ANDROID_ABI}" MATCHES "x86_64$")
# Enable pointer compression on 64 bit platforms
set(COMMON_CMAKE_ARGUMENTS "${COMMON_CMAKE_ARGUMENTS} -DV8_COMPRESS_POINTERS")
endif()


# AOSP has switched to using LLD by default and the NDK will use it by default in the next release.
# BFD and Gold will be removed once LLD has been through a release cycle with no major unresolved issues (estimated r21)
# Note: lld does not currently work on Windows: https://github.com/android-ndk/ndk/issues/888
@@ -142,6 +143,7 @@ add_library(
src/main/cpp/ada/ada.cpp
src/main/cpp/URLImpl.cpp
src/main/cpp/URLSearchParamsImpl.cpp
src/main/cpp/URLPatternImpl.cpp

# V8 inspector source files will be included only in Release mode
${INSPECTOR_SOURCES}
@@ -163,6 +165,7 @@ else ()
)
endif ()


MESSAGE(STATUS "# General cmake Info")
MESSAGE(STATUS "# PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR})
MESSAGE(STATUS "# CMAKE_VERSION: " ${CMAKE_VERSION})
@@ -183,11 +186,6 @@ if("${ANDROID_ABI}" MATCHES "armeabi-v7a$" OR "${ANDROID_ABI}" MATCHES "x86$")
target_link_libraries(NativeScript ${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${ANDROID_ABI}/libandroid_support.a)
endif()


if("${ANDROID_ABI}" MATCHES "arm64-v8a$" OR "${ANDROID_ABI}" MATCHES "x86_64$")
target_link_options(NativeScript PRIVATE "-Wl,-z,max-page-size=16384")
endif()

# Command info: https://cmake.org/cmake/help/v3.4/command/find_library.html
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
7 changes: 4 additions & 3 deletions test-app/runtime/build.gradle
Original file line number Diff line number Diff line change
@@ -21,7 +21,8 @@ if (useCCache) {
}


def defaultNdkVersion = "23.2.8568313"
def defaultNdkVersion = "27.2.12479018"


def hasNdkVersion = project.hasProperty("ndkVersion")
if (hasNdkVersion) {
@@ -113,7 +114,7 @@ android {
//
// arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_static", "-DANDROID_NDK_ROOT=${NDK_PATH}"

cppFlags "-std=c++14"
cppFlags "-std=c++20"
arguments "-DANDROID_STL=c++_static", "-DANDROID_NDK_ROOT=${NDK_PATH}"
}
}
@@ -147,7 +148,7 @@ allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile).tap {
configureEach {
options.compilerArgs << "-Xlint:all" << "-Werror"
//options.compilerArgs << "-Xlint:all" << "-Werror"
}
}
}
2 changes: 2 additions & 0 deletions test-app/runtime/src/main/cpp/Runtime.cpp
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
#include "ModuleBinding.h"
#include "URLImpl.h"
#include "URLSearchParamsImpl.h"
#include "URLPatternImpl.h"

#ifdef APPLICATION_IN_DEBUG
// #include "NetworkDomainCallbackHandlers.h"
@@ -529,6 +530,7 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__removeFrameCallback"), FunctionTemplate::New(isolate, CallbackHandlers::RemoveFrameCallback));
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "URL"), URLImpl::GetCtor(isolate));
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "URLSearchParams"), URLSearchParamsImpl::GetCtor(isolate));
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "URLPattern"), URLPatternImpl::GetCtor(isolate));

/*
* Attach `Worker` object constructor only to the main thread (isolate)'s global object
2 changes: 1 addition & 1 deletion test-app/runtime/src/main/cpp/Timers.h
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ namespace tns {
// background thread lost cycles
std::set<int> deletedTimers_;
int fd_[2];
std::atomic_bool isBufferFull = ATOMIC_VAR_INIT(false);
std::atomic_bool isBufferFull = false;
std::condition_variable taskReady;
std::condition_variable bufferFull;
std::mutex mutex;
3 changes: 3 additions & 0 deletions test-app/runtime/src/main/cpp/URLImpl.cpp
Original file line number Diff line number Diff line change
@@ -33,6 +33,9 @@ v8::Local<v8::FunctionTemplate> URLImpl::GetCtor(v8::Isolate *isolate) {
tmpl->SetAccessor(
ArgConverter::ConvertToV8String(isolate, "host"),
GetHost, SetHost);
tmpl->SetAccessor(
ArgConverter::ConvertToV8String(isolate, "hash"),
GetHash, SetHash);
tmpl->SetAccessor(
ArgConverter::ConvertToV8String(isolate, "hostname"),
GetHostName, SetHostName);
732 changes: 732 additions & 0 deletions test-app/runtime/src/main/cpp/URLPatternImpl.cpp

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions test-app/runtime/src/main/cpp/URLPatternImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// Created by Osei Fortune on 30/01/2025.
//

#ifndef TEST_APP_URLPATTERNIMPL_H
#define TEST_APP_URLPATTERNIMPL_H

#include "ada/ada.h"
#include "v8.h"
#include "ArgConverter.h"
#include "NativeScriptAssert.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);

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);

};
}


#endif //TEST_APP_URLPATTERNIMPL_H
1 change: 1 addition & 0 deletions test-app/runtime/src/main/cpp/Util.cpp
Original file line number Diff line number Diff line change
@@ -108,6 +108,7 @@ namespace tns {
}

u16string Util::ConvertFromUtf8ToUtf16(const string &str) {
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
auto utf16String =
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>().from_bytes(str);

5,234 changes: 3,488 additions & 1,746 deletions test-app/runtime/src/main/cpp/ada/ada.cpp

Large diffs are not rendered by default.

7,876 changes: 5,513 additions & 2,363 deletions test-app/runtime/src/main/cpp/ada/ada.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test-app/runtime/src/main/cpp/robin_hood.h
Original file line number Diff line number Diff line change
@@ -206,7 +206,7 @@ static Counts& counts() {

// workaround missing "is_trivially_copyable" in g++ < 5.0
// See https://stackoverflow.com/a/31798726/48181
#if defined(__GNUC__) && __GNUC__ < 5
#if defined(__GNUC__) && __GNUC__ < 5 && __cplusplus < 202002L
# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) __has_trivial_copy(__VA_ARGS__)
#else
# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) std::is_trivially_copyable<__VA_ARGS__>::value