Skip to content

url: call ada::can_parse directly #47919

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

Merged
merged 1 commit into from
May 18, 2023
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
27 changes: 10 additions & 17 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,25 @@ void BindingData::CanParse(const FunctionCallbackInfo<Value>& args) {

Environment* env = Environment::GetCurrent(args);
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());

Utf8Value input(env->isolate(), args[0]);
ada::result<ada::url_aggregator> base;
ada::url_aggregator* base_pointer = nullptr;
std::string_view input_view = input.ToStringView();

bool can_parse{};
if (args[1]->IsString()) {
base = ada::parse<ada::url_aggregator>(
Utf8Value(env->isolate(), args[1]).ToString());
if (!base) {
return args.GetReturnValue().Set(false);
}
base_pointer = &base.value();
Utf8Value base(env->isolate(), args[1]);
std::string_view base_view = base.ToStringView();
can_parse = ada::can_parse(input_view, &base_view);
} else {
can_parse = ada::can_parse(input_view);
}
auto out =
ada::parse<ada::url_aggregator>(input.ToStringView(), base_pointer);

args.GetReturnValue().Set(out.has_value());
args.GetReturnValue().Set(can_parse);
}

bool BindingData::FastCanParse(Local<Value> receiver,
const FastOneByteString& input) {
std::string_view input_view(input.data, input.length);

auto output = ada::parse<ada::url_aggregator>(input_view);

return output.has_value();
return ada::can_parse(std::string_view(input.data, input.length));
}

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