mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:48:11 +00:00
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.
This commit is contained in:
parent
d8aa2a6997
commit
c6ddbd1f3e
25 changed files with 285 additions and 112 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue