Skip to content

Commit

Permalink
Added URL.parse Static Method
Browse files Browse the repository at this point in the history
  • Loading branch information
Redfire75369 committed Aug 9, 2024
1 parent 3fdc557 commit e6b1e55
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions runtime/src/globals/url/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ impl URL {
Url::options().base_url(base.as_ref()).parse(&input).is_ok()
}

pub fn parse(cx: &Context, input: String, Opt(base): Opt<String>) -> Option<*mut JSObject> {
let base = base.as_ref().and_then(|base| Url::parse(base).ok());
let url = Url::options().base_url(base.as_ref()).parse(&input).ok()?;

let url_object = URL::new_raw_object(cx);
let search_params = Box::new(URLSearchParams::new(url.query_pairs().into_owned().collect()));
search_params.url.as_ref().unwrap().set(url_object);
let search_params = Heap::boxed(URLSearchParams::new_object(cx, search_params));

unsafe {
URL::set_private(
url_object,
Box::new(URL {
reflector: Reflector::default(),
url,
search_params,
}),
);
}

Some(url_object)
}

pub fn format(&self, Opt(options): Opt<FormatOptions>) -> Result<String> {
let mut url = self.url.clone();

Expand Down

0 comments on commit e6b1e55

Please sign in to comment.