@@ -202,7 +202,10 @@ void URLPattern::New(const FunctionCallbackInfo<Value>& args) {
202202 // - new URLPattern(input, baseURL)
203203 // - new URLPattern(input, options)
204204 // - new URLPattern(input, baseURL, options)
205- if (args[0 ]->IsString ()) {
205+ // Per WebIDL, undefined for an optional argument uses the default value.
206+ if (args[0 ]->IsUndefined ()) {
207+ init = ada::url_pattern_init{};
208+ } else if (args[0 ]->IsString ()) {
206209 BufferValue input_buffer (env->isolate (), args[0 ]);
207210 CHECK_NOT_NULL (*input_buffer);
208211 input = input_buffer.ToString ();
@@ -218,7 +221,7 @@ void URLPattern::New(const FunctionCallbackInfo<Value>& args) {
218221 }
219222
220223 // The next argument can be baseURL or options.
221- if (args.Length () > 1 ) {
224+ if (args.Length () > 1 && !args[ 1 ]-> IsUndefined () ) {
222225 if (args[1 ]->IsString ()) {
223226 BufferValue base_url_buffer (env->isolate (), args[1 ]);
224227 CHECK_NOT_NULL (*base_url_buffer);
@@ -239,7 +242,7 @@ void URLPattern::New(const FunctionCallbackInfo<Value>& args) {
239242 }
240243
241244 // Only remaining argument can be options.
242- if (args.Length () > 2 ) {
245+ if (args.Length () > 2 && !args[ 2 ]-> IsUndefined () ) {
243246 if (!args[2 ]->IsObject ()) {
244247 THROW_ERR_INVALID_ARG_TYPE (env, " options must be an object" );
245248 return ;
@@ -564,7 +567,7 @@ void URLPattern::Exec(const FunctionCallbackInfo<Value>& args) {
564567 ada::url_pattern_input input;
565568 std::optional<std::string> baseURL{};
566569 std::string input_base;
567- if (args.Length () == 0 ) {
570+ if (args.Length () == 0 || args[ 0 ]-> IsUndefined () ) {
568571 input = ada::url_pattern_init{};
569572 } else if (args[0 ]->IsString ()) {
570573 Utf8Value input_value (env->isolate (), args[0 ].As <String>());
@@ -580,7 +583,7 @@ void URLPattern::Exec(const FunctionCallbackInfo<Value>& args) {
580583 return ;
581584 }
582585
583- if (args.Length () > 1 ) {
586+ if (args.Length () > 1 && !args[ 1 ]-> IsUndefined () ) {
584587 if (!args[1 ]->IsString ()) {
585588 THROW_ERR_INVALID_ARG_TYPE (env, " baseURL must be a string" );
586589 return ;
@@ -607,7 +610,7 @@ void URLPattern::Test(const FunctionCallbackInfo<Value>& args) {
607610 ada::url_pattern_input input;
608611 std::optional<std::string> baseURL{};
609612 std::string input_base;
610- if (args.Length () == 0 ) {
613+ if (args.Length () == 0 || args[ 0 ]-> IsUndefined () ) {
611614 input = ada::url_pattern_init{};
612615 } else if (args[0 ]->IsString ()) {
613616 Utf8Value input_value (env->isolate (), args[0 ].As <String>());
@@ -623,7 +626,7 @@ void URLPattern::Test(const FunctionCallbackInfo<Value>& args) {
623626 return ;
624627 }
625628
626- if (args.Length () > 1 ) {
629+ if (args.Length () > 1 && !args[ 1 ]-> IsUndefined () ) {
627630 if (!args[1 ]->IsString ()) {
628631 THROW_ERR_INVALID_ARG_TYPE (env, " baseURL must be a string" );
629632 return ;
0 commit comments