@@ -15,8 +15,7 @@ use boa_engine::{
15
15
object:: { builtins:: JsArray , Object } ,
16
16
property:: Attribute ,
17
17
value:: TryFromJs ,
18
- Context , JsArgs , JsError , JsNativeError , JsObject , JsResult , JsString , JsValue ,
19
- NativeFunction ,
18
+ Context , JsArgs , JsError , JsNativeError , JsObject , JsResult , JsValue , NativeFunction ,
20
19
} ;
21
20
use boa_gc:: { empty_trace, Finalize , GcRefMut , Trace } ;
22
21
@@ -74,13 +73,13 @@ impl JsNativeObjectToString for UrlPattern {
74
73
75
74
impl UrlPattern {
76
75
fn process_input (
77
- string_or_init : quirks :: StringOrInit ,
76
+ input : UrlPatternInput ,
78
77
base_url : Option < String > ,
79
78
) -> JsResult < (
80
79
InnerUrlPatternMatchInput ,
81
80
( quirks:: StringOrInit , Option < String > ) ,
82
81
) > {
83
- match quirks:: process_match_input ( string_or_init , base_url. as_deref ( ) ) {
82
+ match quirks:: process_match_input ( input . 0 , base_url. as_deref ( ) ) {
84
83
Err ( e) => Err ( JsError :: from_native (
85
84
JsNativeError :: typ ( ) . with_message ( e. to_string ( ) ) ,
86
85
) ) ,
@@ -98,16 +97,15 @@ impl UrlPattern {
98
97
base_url : Option < String > ,
99
98
_context : & mut Context < ' _ > ,
100
99
) -> JsResult < Self > {
101
- let UrlPatternInput ( string_or_init) = input;
102
- let urlpatterninit =
103
- quirks:: process_construct_pattern_input ( string_or_init, base_url. as_deref ( ) )
100
+ let url_pattern_init =
101
+ quirks:: process_construct_pattern_input ( input. 0 , base_url. as_deref ( ) )
104
102
. map_err ( |_| {
105
103
JsError :: from_native (
106
104
JsNativeError :: typ ( )
107
105
. with_message ( "Failed to build UrlPatternInit" ) ,
108
106
)
109
107
} ) ?;
110
- let url_pattern = InnerUrlPattern :: parse ( urlpatterninit ) . map_err ( |_| {
108
+ let url_pattern = InnerUrlPattern :: parse ( url_pattern_init ) . map_err ( |_| {
111
109
JsError :: from_native (
112
110
JsNativeError :: typ ( ) . with_message ( "Failed to parse UrlPatternInit" ) ,
113
111
)
@@ -153,8 +151,7 @@ impl UrlPattern {
153
151
input : UrlPatternInput ,
154
152
base_url : Option < String > ,
155
153
) -> JsResult < bool > {
156
- let UrlPatternInput ( string_or_init) = input;
157
- let ( url_pattern_match_input, _) = Self :: process_input ( string_or_init, base_url) ?;
154
+ let ( url_pattern_match_input, _) = Self :: process_input ( input, base_url) ?;
158
155
159
156
self . url_pattern
160
157
. test ( url_pattern_match_input)
@@ -166,9 +163,8 @@ impl UrlPattern {
166
163
input : UrlPatternInput ,
167
164
base_url : Option < String > ,
168
165
) -> JsResult < Option < UrlPatternResult > > {
169
- let UrlPatternInput ( string_or_init) = input;
170
166
let ( url_pattern_match_input, ( string_or_init, base_url) ) =
171
- Self :: process_input ( string_or_init , base_url) ?;
167
+ Self :: process_input ( input , base_url) ?;
172
168
173
169
let mut inputs: Vec < UrlPatternInput > = Vec :: new ( ) ;
174
170
inputs. push ( UrlPatternInput ( string_or_init) ) ;
@@ -329,7 +325,7 @@ impl TryFromJs for UrlPatternInit {
329
325
pathname : get_optional_property ! ( obj, "pathname" , context) ,
330
326
search : get_optional_property ! ( obj, "search" , context) ,
331
327
hash : get_optional_property ! ( obj, "hash" , context) ,
332
- base_url : get_optional_property ! ( obj, "base_url " , context) ,
328
+ base_url : get_optional_property ! ( obj, "baseURL " , context) ,
333
329
} ;
334
330
335
331
Ok ( Self ( url_pattern_init) )
@@ -372,46 +368,58 @@ impl From<quirks::UrlPatternInit> for UrlPatternInput {
372
368
373
369
impl IntoJs for UrlPatternComponentResult {
374
370
fn into_js ( self , context : & mut Context < ' _ > ) -> JsValue {
375
- let UrlPatternComponentResult ( url_pattern_component_result) = self ;
371
+ let url_pattern_component_result = self . 0 ;
376
372
let input = url_pattern_component_result. input ;
377
373
let groups: Vec < ( String , String ) > =
378
374
url_pattern_component_result. groups . into_iter ( ) . collect ( ) ;
379
- // Create an object with prototype set to `Object`
375
+ // Create an object with prototype set to `Object.prototype `
380
376
let obj = JsObject :: with_object_proto ( context. intrinsics ( ) ) ;
381
377
// Add data property `input` to the object
378
+ // TODO: Support error handling (using TryIntoJs)
382
379
let _ = obj. create_data_property (
383
- JsString :: from ( "input" ) ,
380
+ js_string ! ( "input" ) ,
384
381
input. into_js ( context) ,
385
382
context,
386
383
) ;
387
384
// Add data property `groups` to the object,
388
- // which is itself another object with prototype set to `Object`
385
+ // which is itself another object with prototype set to `Object.prototype `
389
386
let group_obj = JsObject :: with_object_proto ( context. intrinsics ( ) ) ;
390
387
for ( key, value) in groups. iter ( ) {
391
388
let value = value. clone ( ) . into_js ( context) ;
392
- let _ = group_obj. create_data_property (
393
- JsString :: from ( key. clone ( ) ) ,
394
- value,
395
- context,
396
- ) ;
389
+
390
+ // TODO: Support error handling (using TryIntoJs)
391
+ let _ =
392
+ group_obj. create_data_property ( js_string ! ( key. clone( ) ) , value, context) ;
397
393
}
398
- let _ = obj. create_data_property ( JsString :: from ( "groups" ) , group_obj, context) ;
394
+
395
+ // TODO: Support error handling (using TryIntoJs)
396
+ let _ = obj. create_data_property ( js_string ! ( "groups" ) , group_obj, context) ;
399
397
obj. into ( )
400
398
}
401
399
}
402
400
403
401
impl IntoJs for UrlPatternInit {
404
402
fn into_js ( self , context : & mut Context < ' _ > ) -> JsValue {
405
403
let obj = JsObject :: with_object_proto ( context. intrinsics ( ) ) ;
406
- let UrlPatternInit ( init) = self ;
404
+ let init = self . 0 ;
407
405
408
406
macro_rules! create_data_properties_if_some {
409
407
( $obj: ident, $init: ident, $field: ident, $context: ident) => {
410
- let property_name = stringify!( $field) ;
411
408
if let Some ( s) = $init. $field {
409
+ // TODO: Support error handling (using TryIntoJs)
410
+ let _ = $obj. create_data_property(
411
+ js_string!( stringify!( $field) ) ,
412
+ js_string!( s) ,
413
+ $context,
414
+ ) ;
415
+ }
416
+ } ;
417
+ ( $obj: ident, $init: ident, $field: ident, $property_name: literal, $context: ident) => {
418
+ if let Some ( s) = $init. $field {
419
+ // TODO: Support error handling (using TryIntoJs)
412
420
let _ = $obj. create_data_property(
413
- JsString :: from ( property_name) ,
414
- JsString :: from ( s) ,
421
+ js_string! ( $ property_name) ,
422
+ js_string! ( s) ,
415
423
$context,
416
424
) ;
417
425
}
@@ -426,6 +434,7 @@ impl IntoJs for UrlPatternInit {
426
434
create_data_properties_if_some ! ( obj, init, pathname, context) ;
427
435
create_data_properties_if_some ! ( obj, init, search, context) ;
428
436
create_data_properties_if_some ! ( obj, init, hash, context) ;
437
+ create_data_properties_if_some ! ( obj, init, base_url, "baseURL" , context) ;
429
438
430
439
obj. into ( )
431
440
}
@@ -438,10 +447,9 @@ impl IntoJs for UrlPatternResult {
438
447
439
448
macro_rules! create_data_property {
440
449
( $obj: ident, $inner: ident, $field: ident, $context: ident) => {
441
- let property_name = stringify!( $field) ;
442
450
let $field = UrlPatternComponentResult ( $inner. $field) . into_js( $context) ;
443
451
let _ = $obj. create_data_property(
444
- JsString :: from ( property_name ) ,
452
+ js_string! ( stringify! ( $field ) ) ,
445
453
$field,
446
454
$context,
447
455
) ;
@@ -464,7 +472,7 @@ impl IntoJs for UrlPatternResult {
464
472
}
465
473
array. into ( )
466
474
} ;
467
- let _ = obj. create_data_property ( JsString :: from ( "inputs" ) , inputs, context) ;
475
+ let _ = obj. create_data_property ( js_string ! ( "inputs" ) , inputs, context) ;
468
476
469
477
obj. into ( )
470
478
}
0 commit comments