From a5fc9715c186f8c6c5276e31efc4d06d7757db31 Mon Sep 17 00:00:00 2001 From: Leo Unoki Date: Wed, 25 Oct 2023 11:10:06 +0100 Subject: [PATCH] Fix URLSearchParams to_string --- .gitignore | 2 ++ jstz_api/src/url/search_params.rs | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 55b08de44..c28e909be 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ node_modules/ **/.vitepress/dist **/dist + +.vscode \ No newline at end of file diff --git a/jstz_api/src/url/search_params.rs b/jstz_api/src/url/search_params.rs index ac9a31067..c3047a17b 100644 --- a/jstz_api/src/url/search_params.rs +++ b/jstz_api/src/url/search_params.rs @@ -1,5 +1,7 @@ use boa_engine::{ - builtins, js_string, + builtins, + builtins::object::Object as GlobalObject, + js_string, object::{builtins::JsArray, Object}, property::Attribute, value::TryFromJs, @@ -446,9 +448,14 @@ impl UrlSearchParamsClass { _args: &[JsValue], context: &mut Context<'_>, ) -> JsResult { - let search_params = UrlSearchParams::try_from_js(this)?; - - Ok(search_params.to_string().into_js(context)) + UrlSearchParams::try_from_js(this) + .map(|search_params| search_params.to_string().into_js(context)) + .or_else(|_| GlobalObject::to_string(this, _args, context)) + .or_else(|_| { + Err(JsError::from_native(JsNativeError::typ().with_message( + "Failed to convert `URLSearchParams` into js string", + ))) + }) } }