diff --git a/lib/internal/url.js b/lib/internal/url.js index 6aa9260990fecb..73168f40e13c64 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -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); } } diff --git a/src/node_url.cc b/src/node_url.cc index 35a7855035a2f1..f055acd51c323c 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -170,8 +170,6 @@ bool BindingData::FastCanParse(Local receiver, return ada::can_parse(std::string_view(input.data, input.length)); } -CFunction BindingData::fast_can_parse_(CFunction::Make(FastCanParse)); - bool BindingData::FastCanParseWithBase(Local receiver, const FastOneByteString& input, const FastOneByteString& base) { @@ -179,8 +177,8 @@ bool BindingData::FastCanParseWithBase(Local receiver, 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& args) { CHECK_GT(args.Length(), 4); @@ -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 target, @@ -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) { diff --git a/src/node_url.h b/src/node_url.h index fc0a302778ae73..c485caa2eb0343 100644 --- a/src/node_url.h +++ b/src/node_url.h @@ -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); diff --git a/typings/internalBinding/url.d.ts b/typings/internalBinding/url.d.ts index 90c8d5e869b479..4c8ae2ab1508f0 100644 --- a/typings/internalBinding/url.d.ts +++ b/typings/internalBinding/url.d.ts @@ -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;