Skip to content

Commit

Permalink
url: overload canParse V8 fast api method
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Aug 6, 2023
1 parent 239585d commit 0457a0a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1054,10 +1054,10 @@ class URL {
url = `${url}`;

if (base !== undefined) {
return bindingUrl.canParseWithBase(url, `${base}`);
base = `${base}`;
}

return bindingUrl.canParse(url);
return bindingUrl.canParse(url, base);
}
}

Expand Down
19 changes: 7 additions & 12 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,15 @@ bool BindingData::FastCanParse(Local<Value> receiver,
return ada::can_parse(std::string_view(input.data, input.length));
}

CFunction BindingData::fast_can_parse_(CFunction::Make(FastCanParse));

bool BindingData::FastCanParseWithBase(Local<Value> receiver,
const FastOneByteString& input,
const FastOneByteString& base) {
auto base_view = std::string_view(base.data, base.length);
return ada::can_parse(std::string_view(input.data, input.length), &base_view);
}

CFunction BindingData::fast_can_parse_with_base_(
CFunction::Make(FastCanParseWithBase));
CFunction BindingData::fast_can_parse_methods_[] = {
CFunction::Make(FastCanParse), CFunction::Make(FastCanParseWithBase)};

void BindingData::Format(const FunctionCallbackInfo<Value>& args) {
CHECK_GT(args.Length(), 4);
Expand Down Expand Up @@ -361,12 +359,7 @@ void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data,
SetMethod(isolate, target, "parse", Parse);
SetMethod(isolate, target, "update", Update);
SetFastMethodNoSideEffect(
isolate, target, "canParse", CanParse, &fast_can_parse_);
SetFastMethodNoSideEffect(isolate,
target,
"canParseWithBase",
CanParse,
&fast_can_parse_with_base_);
isolate, target, "canParse", CanParse, {fast_can_parse_methods_, 2});
}

void BindingData::CreatePerContextProperties(Local<Object> target,
Expand All @@ -387,9 +380,11 @@ void BindingData::RegisterExternalReferences(
registry->Register(Update);
registry->Register(CanParse);
registry->Register(FastCanParse);
registry->Register(fast_can_parse_.GetTypeInfo());
registry->Register(FastCanParseWithBase);
registry->Register(fast_can_parse_with_base_.GetTypeInfo());

for (const CFunction& method : fast_can_parse_methods_) {
registry->Register(method.GetTypeInfo());
}
}

std::string FromFilePath(const std::string_view file_path) {
Expand Down
3 changes: 1 addition & 2 deletions src/node_url.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class BindingData : public SnapshotableObject {
void UpdateComponents(const ada::url_components& components,
const ada::scheme::type type);

static v8::CFunction fast_can_parse_;
static v8::CFunction fast_can_parse_with_base_;
static v8::CFunction fast_can_parse_methods_[];
};

std::string FromFilePath(const std::string_view file_path);
Expand Down
1 change: 0 additions & 1 deletion typings/internalBinding/url.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ declare function InternalBinding(binding: 'url'): {
domainToASCII(input: string): string;
domainToUnicode(input: string): string;
canParse(input: string): boolean;
canParseWithBase(input: string, base: string): boolean;
format(input: string, fragment?: boolean, unicode?: boolean, search?: boolean, auth?: boolean): string;
parse(input: string, base?: string): string | false;
update(input: string, actionType: typeof urlUpdateActions, value: string): string | false;
Expand Down

0 comments on commit 0457a0a

Please sign in to comment.