From 78c8540eb0167abd62975f47d40aa55a7bbcf5d0 Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 6 Mar 2024 19:28:43 +0700 Subject: [PATCH] fix(boa_engine): fix conversion from undefined to JSON --- boa_engine/src/value/conversions/serde_json.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/boa_engine/src/value/conversions/serde_json.rs b/boa_engine/src/value/conversions/serde_json.rs index f4f73f63eeb..4413333aaaf 100644 --- a/boa_engine/src/value/conversions/serde_json.rs +++ b/boa_engine/src/value/conversions/serde_json.rs @@ -108,14 +108,12 @@ impl JsValue { /// # /// # assert_eq!(json, back_to_json); /// ``` - /// - /// # Panics - /// - /// Panics if the `JsValue` is `Undefined`. pub fn to_json(&self, context: &mut Context<'_>) -> JsResult { match self { Self::Null => Ok(Value::Null), - Self::Undefined => todo!("undefined to JSON"), + Self::Undefined => Err(JsNativeError::typ() + .with_message("cannot convert undefined to JSON") + .into()), &Self::Boolean(b) => Ok(b.into()), Self::String(string) => Ok(string.to_std_string_escaped().into()), &Self::Rational(rat) => Ok(rat.into()),