| 608 | |
| 609 | |
| 610 | void URLPatternImpl::Test(const v8::FunctionCallbackInfo<v8::Value> &args) { |
| 611 | URLPatternImpl *ptr = GetPointer(args.This()); |
| 612 | if (ptr == nullptr) { |
| 613 | args.GetReturnValue().Set(false); |
| 614 | return; |
| 615 | } |
| 616 | auto isolate = args.GetIsolate(); |
| 617 | auto ctx = isolate->GetCurrentContext(); |
| 618 | |
| 619 | ada::url_pattern_input input; |
| 620 | std::optional<std::string> baseURL{}; |
| 621 | std::string input_base; |
| 622 | |
| 623 | if (args.Length() == 0) { |
| 624 | input = ada::url_pattern_init{}; |
| 625 | } else if (args[0]->IsObject()) { |
| 626 | auto parsed = ParseInput(isolate, args[0]); |
| 627 | if (parsed) { |
| 628 | input = std::move(*parsed); |
| 629 | } |
| 630 | } else if (args[0]->IsString()) { |
| 631 | input_base = ArgConverter::ConvertToString(args[0]->ToString(ctx).ToLocalChecked()); |
| 632 | input = std::string_view(input_base); |
| 633 | } else { |
| 634 | isolate->ThrowException( |
| 635 | v8::Exception::TypeError(ArgConverter::ConvertToV8String(isolate, |
| 636 | "URLPattern input needs to be a string or an object"))); |
| 637 | return; |
| 638 | }; |
| 639 | |
| 640 | |
| 641 | std::optional<std::string> baseUrl{}; |
| 642 | |
| 643 | |
| 644 | if (args.Length() > 1) { |
| 645 | if (!args[1]->IsString()) { |
| 646 | isolate->ThrowException( |
| 647 | v8::Exception::TypeError(ArgConverter::ConvertToV8String(isolate, |
| 648 | "baseURL must be a string"))); |
| 649 | return; |
| 650 | } |
| 651 | baseURL = ArgConverter::ConvertToString(args[1].As<v8::String>()); |
| 652 | } |
| 653 | |
| 654 | |
| 655 | std::optional<std::string_view> baseURL_opt = |
| 656 | baseURL ? std::optional<std::string_view>(*baseURL) : std::nullopt; |
| 657 | |
| 658 | if (auto result = ptr->GetPattern()->test(input, baseURL_opt ? &*baseURL_opt : nullptr)) { |
| 659 | args.GetReturnValue().Set(result.value()); |
| 660 | } else { |
| 661 | args.GetReturnValue().SetNull(); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | |
| 666 | void URLPatternImpl::Exec(const v8::FunctionCallbackInfo<v8::Value> &args) { |
nothing calls this directly
no test coverage detected