-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathURLPatternImpl.h
More file actions
92 lines (66 loc) · 2.95 KB
/
URLPatternImpl.h
File metadata and controls
92 lines (66 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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