FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

src: define urlpattern components via macro by JonasBa · Pull Request #57452 · nodejs/node · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .cc  (1) .h  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
47 changes: 8 additions & 39 deletions src/node_url_pattern.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -462,48 +462,17 @@ URLPattern::URLPatternOptions::FromJsObject(Environment* env,
// by returning std::nullopt.
return std::nullopt;
}
return options;
}

MaybeLocal<Value> URLPattern::Hash() const {
auto context = env()->context();
return ToV8Value(context, url_pattern_.get_hash());
}

MaybeLocal<Value> URLPattern::Hostname() const {
auto context = env()->context();
return ToV8Value(context, url_pattern_.get_hostname());
}

MaybeLocal<Value> URLPattern::Password() const {
auto context = env()->context();
return ToV8Value(context, url_pattern_.get_password());
}

MaybeLocal<Value> URLPattern::Pathname() const {
auto context = env()->context();
return ToV8Value(context, url_pattern_.get_pathname());
}

MaybeLocal<Value> URLPattern::Port() const {
auto context = env()->context();
return ToV8Value(context, url_pattern_.get_port());
}

MaybeLocal<Value> URLPattern::Protocol() const {
auto context = env()->context();
return ToV8Value(context, url_pattern_.get_protocol());
}

MaybeLocal<Value> URLPattern::Search() const {
auto context = env()->context();
return ToV8Value(context, url_pattern_.get_search());
return options;
}

MaybeLocal<Value> URLPattern::Username() const {
auto context = env()->context();
return ToV8Value(context, url_pattern_.get_username());
}
#define URL_PATTERN_COMPONENT_GETTERS(uppercase_name, lowercase_name) \
MaybeLocal<Value> URLPattern::uppercase_name() const { \
auto context = env()->context(); \
return ToV8Value(context, url_pattern_.get_##lowercase_name()); \
}
URL_PATTERN_COMPONENTS(URL_PATTERN_COMPONENT_GETTERS)
#undef URL_PATTERN_COMPONENT_GETTERS

bool URLPattern::HasRegExpGroups() const {
return url_pattern_.has_regexp_groups();
Expand Down
37 changes: 20 additions & 17 deletions src/node_url_pattern.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@

namespace node::url_pattern {

#define URL_PATTERN_COMPONENTS(V) \
V(Protocol, protocol) \
V(Username, username) \
V(Password, password) \
V(Hostname, hostname) \
V(Port, port) \
V(Pathname, pathname) \
V(Search, search) \
V(Hash, hash)

// By default, ada::url_pattern doesn't ship with any regex library.
// Ada has a std::regex implementation, but it is considered unsafe and does
// not have a fully compliant ecmascript syntax support. Therefore, Ada
Expand Down Expand Up @@ -42,15 +52,12 @@ class URLPattern : public BaseObject {
// - Functions
static void Exec(const v8::FunctionCallbackInfo<v8::Value>& info);
static void Test(const v8::FunctionCallbackInfo<v8::Value>& info);
// - Getters
static void Hash(const v8::FunctionCallbackInfo<v8::Value>& info);
static void Hostname(const v8::FunctionCallbackInfo<v8::Value>& info);
static void Password(const v8::FunctionCallbackInfo<v8::Value>& info);
static void Pathname(const v8::FunctionCallbackInfo<v8::Value>& info);
static void Port(const v8::FunctionCallbackInfo<v8::Value>& info);
static void Protocol(const v8::FunctionCallbackInfo<v8::Value>& info);
static void Search(const v8::FunctionCallbackInfo<v8::Value>& info);
static void Username(const v8::FunctionCallbackInfo<v8::Value>& info);
// - Component Getters
#define URL_PATTERN_COMPONENT_GETTERS(name, _) \
static void name(const v8::FunctionCallbackInfo<v8::Value>& info);
URL_PATTERN_COMPONENTS(URL_PATTERN_COMPONENT_GETTERS)
#undef URL_PATTERN_COMPONENT_GETTERS
// - Has Regexp Groups
static void HasRegexpGroups(const v8::FunctionCallbackInfo<v8::Value>& info);

void MemoryInfo(MemoryTracker* tracker) const override;
Expand Down Expand Up @@ -86,14 +93,10 @@ class URLPattern : public BaseObject {
private:
ada::url_pattern<URLPatternRegexProvider> url_pattern_;
// Getter methods
v8::MaybeLocal<v8::Value> Hash() const;
v8::MaybeLocal<v8::Value> Hostname() const;
v8::MaybeLocal<v8::Value> Password() const;
v8::MaybeLocal<v8::Value> Pathname() const;
v8::MaybeLocal<v8::Value> Port() const;
v8::MaybeLocal<v8::Value> Protocol() const;
v8::MaybeLocal<v8::Value> Search() const;
v8::MaybeLocal<v8::Value> Username() const;
#define URL_PATTERN_COMPONENT_GETTERS(name, _) \
v8::MaybeLocal<v8::Value> name() const;
URL_PATTERN_COMPONENTS(URL_PATTERN_COMPONENT_GETTERS)
#undef URL_PATTERN_COMPONENT_GETTERS
bool HasRegExpGroups() const;
// Public API
v8::MaybeLocal<v8::Value> Exec(
Expand Down

Back | FazBrowse Home | New Git URL