summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-04-29 16:36:38 +0100
committerAndreas Kling <kling@serenityos.org>2020-04-29 18:53:21 +0200
commit4bdb6daac58f76feae8dba2bcad15d598d9eeccf (patch)
tree15d8f02d5328be213308e6ae5b7c07b8b2e7132b /Libraries
parent2c6e7dbd07f59f687a08c9d7460a2573ae20cbcd (diff)
downloadserenity-4bdb6daac58f76feae8dba2bcad15d598d9eeccf.zip
LibJS: Handle non-string primitive values in Object::to_string()
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibJS/Runtime/Object.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp
index 29f591e4cf..82ffbc5829 100644
--- a/Libraries/LibJS/Runtime/Object.cpp
+++ b/Libraries/LibJS/Runtime/Object.cpp
@@ -361,12 +361,12 @@ Value Object::to_string() const
&& to_string_property.as_object().is_function()) {
auto& to_string_function = static_cast<Function&>(to_string_property.as_object());
auto& interpreter = const_cast<Object*>(this)->interpreter();
- auto string_value = interpreter.call(to_string_function, const_cast<Object*>(this));
- if (!string_value.is_string())
+ auto to_string_result = interpreter.call(to_string_function, const_cast<Object*>(this));
+ if (to_string_result.is_object())
interpreter.throw_exception<TypeError>("Cannot convert object to string");
if (interpreter.exception())
return {};
- return string_value;
+ return js_string(heap(), to_string_result.to_string());
}
return js_string(heap(), String::format("[object %s]", class_name()));
}