summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/ErrorConstructor.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-15 13:39:24 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-15 13:50:42 +0200
commitc6ddbd1f3ec30ccf7dc150f5a0eff982bd411293 (patch)
tree58897d645f1adcbbebd14569b9be555305f8382f /Libraries/LibJS/Runtime/ErrorConstructor.cpp
parentd8aa2a6997800779cd2dc4303cb2256a32ffc2f3 (diff)
downloadserenity-c6ddbd1f3ec30ccf7dc150f5a0eff982bd411293.zip
LibJS: Add side-effect-free version of Value::to_string()
There are now two API's on Value: - Value::to_string(Interpreter&) -- may throw. - Value::to_string_without_side_effects() -- will never throw. These are some pretty big sweeping changes, so it's possible that I did some part the wrong way. We'll work it out as we go. :^) Fixes #2123.
Diffstat (limited to 'Libraries/LibJS/Runtime/ErrorConstructor.cpp')
-rw-r--r--Libraries/LibJS/Runtime/ErrorConstructor.cpp46
1 files changed, 26 insertions, 20 deletions
diff --git a/Libraries/LibJS/Runtime/ErrorConstructor.cpp b/Libraries/LibJS/Runtime/ErrorConstructor.cpp
index 3904a90747..a28ee1a47c 100644
--- a/Libraries/LibJS/Runtime/ErrorConstructor.cpp
+++ b/Libraries/LibJS/Runtime/ErrorConstructor.cpp
@@ -50,29 +50,35 @@ Value ErrorConstructor::call(Interpreter& interpreter)
Value ErrorConstructor::construct(Interpreter& interpreter)
{
String message = "";
- if (!interpreter.call_frame().arguments.is_empty() && !interpreter.call_frame().arguments[0].is_undefined())
- message = interpreter.call_frame().arguments[0].to_string();
+ if (!interpreter.call_frame().arguments.is_empty() && !interpreter.call_frame().arguments[0].is_undefined()) {
+ message = interpreter.call_frame().arguments[0].to_string(interpreter);
+ if (interpreter.exception())
+ return {};
+ }
return Error::create(interpreter.global_object(), "Error", message);
}
-#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
- ConstructorName::ConstructorName() \
- : NativeFunction(*interpreter().global_object().function_prototype()) \
- { \
- put("prototype", interpreter().global_object().snake_name##_prototype(), 0); \
- put("length", Value(1), Attribute::Configurable); \
- } \
- ConstructorName::~ConstructorName() { } \
- Value ConstructorName::call(Interpreter& interpreter) \
- { \
- return construct(interpreter); \
- } \
- Value ConstructorName::construct(Interpreter& interpreter) \
- { \
- String message = ""; \
- if (!interpreter.call_frame().arguments.is_empty() && !interpreter.call_frame().arguments[0].is_undefined()) \
- message = interpreter.call_frame().arguments[0].to_string(); \
- return ClassName::create(interpreter.global_object(), message); \
+#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
+ ConstructorName::ConstructorName() \
+ : NativeFunction(*interpreter().global_object().function_prototype()) \
+ { \
+ put("prototype", interpreter().global_object().snake_name##_prototype(), 0); \
+ put("length", Value(1), Attribute::Configurable); \
+ } \
+ ConstructorName::~ConstructorName() { } \
+ Value ConstructorName::call(Interpreter& interpreter) \
+ { \
+ return construct(interpreter); \
+ } \
+ Value ConstructorName::construct(Interpreter& interpreter) \
+ { \
+ String message = ""; \
+ if (!interpreter.call_frame().arguments.is_empty() && !interpreter.call_frame().arguments[0].is_undefined()) { \
+ message = interpreter.call_frame().arguments[0].to_string(interpreter); \
+ if (interpreter.exception()) \
+ return {}; \
+ } \
+ return ClassName::create(interpreter.global_object(), message); \
}
JS_ENUMERATE_ERROR_SUBCLASSES