Skip to content

Commit

Permalink
Fix URL to_string
Browse files Browse the repository at this point in the history
  • Loading branch information
ryutamago committed Oct 26, 2023
1 parent 294586a commit 9ba44a9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions jstz_api/src/url/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ mod search_params;
use std::{cmp::Ordering, ops::Deref};

use boa_engine::{
js_string, object::Object, property::Attribute, Context, JsArgs, JsError,
JsNativeError, JsObject, JsResult, JsValue, NativeFunction,
builtins::object::Object as GlobalObject, js_string, object::Object,
property::Attribute, Context, JsArgs, JsError, JsNativeError, JsObject, JsResult,
JsValue, NativeFunction,
};
use boa_gc::{custom_trace, Finalize, GcRefMut, Trace};
use jstz_core::{
Expand Down Expand Up @@ -428,9 +429,15 @@ impl UrlClass {
_args: &[JsValue],
context: &mut Context<'_>,
) -> JsResult<JsValue> {
let url = Url::try_from_js(this)?;

Ok(url.href().into_js(context))
Url::try_from_js(this)
.map(|url| url.href().into_js(context))
.or_else(|_| GlobalObject::to_string(this, _args, context))
.or_else(|_| {
Err(JsError::from_native(
JsNativeError::typ()
.with_message("Failed to convert `URL` into js string"),
))
})
}

fn to_json(
Expand Down

0 comments on commit 9ba44a9

Please sign in to comment.