From 6ef56f79bd6d59880f89d7de134702b8dea06f26 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Thu, 1 Jul 2021 02:04:06 +0300 Subject: [PATCH] LibJS: Stop coercing Date.prototype[Symbol.toPrimitive] hint to string --- Userland/Libraries/LibJS/Runtime/DatePrototype.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index 8456b6f082..317dbb2f45 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -860,12 +860,15 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::symbol_to_primitive) { auto this_value = vm.this_value(global_object); if (!this_value.is_object()) { - vm.throw_exception(global_object, ErrorType::NotAnObject); + vm.throw_exception(global_object, ErrorType::NotAnObject, this_value.to_string_without_side_effects()); return {}; } - auto hint = vm.argument(0).to_string(global_object); - if (vm.exception()) + auto hint_value = vm.argument(0); + if (!hint_value.is_string()) { + vm.throw_exception(global_object, ErrorType::InvalidHint, hint_value.to_string_without_side_effects()); return {}; + } + auto& hint = hint_value.as_string().string(); Value::PreferredType try_first; if (hint == "string" || hint == "default") { try_first = Value::PreferredType::String;