1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +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:
Andreas Kling 2020-05-15 13:39:24 +02:00
parent d8aa2a6997
commit c6ddbd1f3e
25 changed files with 285 additions and 112 deletions

View file

@ -55,16 +55,24 @@ Value FunctionConstructor::construct(Interpreter& interpreter)
{
String parameters_source = "";
String body_source = "";
if (interpreter.argument_count() == 1)
body_source = interpreter.argument(0).to_string();
if (interpreter.argument_count() == 1) {
body_source = interpreter.argument(0).to_string(interpreter);
if (interpreter.exception())
return {};
}
if (interpreter.argument_count() > 1) {
Vector<String> parameters;
for (size_t i = 0; i < interpreter.argument_count() - 1; ++i)
parameters.append(interpreter.argument(i).to_string());
for (size_t i = 0; i < interpreter.argument_count() - 1; ++i) {
parameters.append(interpreter.argument(i).to_string(interpreter));
if (interpreter.exception())
return {};
}
StringBuilder parameters_builder;
parameters_builder.join(',', parameters);
parameters_source = parameters_builder.build();
body_source = interpreter.argument(interpreter.argument_count() - 1).to_string();
body_source = interpreter.argument(interpreter.argument_count() - 1).to_string(interpreter);
if (interpreter.exception())
return {};
}
auto source = String::format("function anonymous(%s) { %s }", parameters_source.characters(), body_source.characters());
auto parser = Parser(Lexer(source));