| 664 | |
| 665 | |
| 666 | void URLPatternImpl::Exec(const v8::FunctionCallbackInfo<v8::Value> &args) { |
| 667 | URLPatternImpl *ptr = GetPointer(args.This()); |
| 668 | if (ptr == nullptr) { |
| 669 | args.GetReturnValue().Set(false); |
| 670 | return; |
| 671 | } |
| 672 | auto isolate = args.GetIsolate(); |
| 673 | |
| 674 | |
| 675 | auto ctx = isolate->GetCurrentContext(); |
| 676 | ada::url_pattern_input input; |
| 677 | std::optional<std::string> baseURL{}; |
| 678 | std::string input_base; |
| 679 | |
| 680 | if (args.Length() == 0) { |
| 681 | input = ada::url_pattern_init{}; |
| 682 | } else if (args[0]->IsObject()) { |
| 683 | auto parsed = ParseInput(isolate, args[0]); |
| 684 | if (parsed) { |
| 685 | input = std::move(*parsed); |
| 686 | } |
| 687 | } else if (args[0]->IsString()) { |
| 688 | input_base = ArgConverter::ConvertToString(args[0]->ToString(ctx).ToLocalChecked()); |
| 689 | input = std::string_view(input_base); |
| 690 | } else { |
| 691 | isolate->ThrowException( |
| 692 | v8::Exception::TypeError(ArgConverter::ConvertToV8String(isolate, |
| 693 | "URLPattern input needs to be a string or an object"))); |
| 694 | return; |
| 695 | }; |
| 696 | |
| 697 | if (args.Length() > 1) { |
| 698 | if (!args[1]->IsString()) { |
| 699 | isolate->ThrowException( |
| 700 | v8::Exception::TypeError(ArgConverter::ConvertToV8String(isolate, |
| 701 | "baseURL must be a string"))); |
| 702 | return; |
| 703 | } |
| 704 | baseURL = ArgConverter::ConvertToString(args[1].As<v8::String>()); |
| 705 | } |
| 706 | |
| 707 | |
| 708 | std::optional<std::string_view> baseURL_opt = |
| 709 | baseURL ? std::optional<std::string_view>(*baseURL) : std::nullopt; |
| 710 | |
| 711 | if (auto result = ptr->GetPattern()->exec(input, baseURL_opt ? &*baseURL_opt : nullptr)) { |
| 712 | if (result.has_value()) { |
| 713 | auto value = result.value(); |
| 714 | |
| 715 | if (value.has_value()) { |
| 716 | auto object = v8::Object::New(isolate); |
| 717 | |
| 718 | BuildJS(isolate, object, result->value()); |
| 719 | |
| 720 | args.GetReturnValue().Set(object); |
| 721 | } else { |
| 722 | args.GetReturnValue().SetNull(); |
| 723 | } |
no test coverage detected