mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
LibJS: Convert to_string() to ThrowCompletionOr
Also update get_function_name() to use ThrowCompletionOr, but this is not a standard AO and should be refactored out of existence eventually.
This commit is contained in:
parent
5d38cf4973
commit
4d8912a92b
48 changed files with 171 additions and 415 deletions
|
@ -41,24 +41,16 @@ RefPtr<FunctionExpression> FunctionConstructor::create_dynamic_function_node(Glo
|
|||
auto& vm = global_object.vm();
|
||||
String parameters_source = "";
|
||||
String body_source = "";
|
||||
if (vm.argument_count() == 1) {
|
||||
body_source = vm.argument(0).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
}
|
||||
if (vm.argument_count() == 1)
|
||||
body_source = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
|
||||
if (vm.argument_count() > 1) {
|
||||
Vector<String> parameters;
|
||||
for (size_t i = 0; i < vm.argument_count() - 1; ++i) {
|
||||
parameters.append(vm.argument(i).to_string(global_object));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
}
|
||||
for (size_t i = 0; i < vm.argument_count() - 1; ++i)
|
||||
parameters.append(TRY_OR_DISCARD(vm.argument(i).to_string(global_object)));
|
||||
StringBuilder parameters_builder;
|
||||
parameters_builder.join(',', parameters);
|
||||
parameters_source = parameters_builder.build();
|
||||
body_source = vm.argument(vm.argument_count() - 1).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
body_source = TRY_OR_DISCARD(vm.argument(vm.argument_count() - 1).to_string(global_object));
|
||||
}
|
||||
auto is_generator = kind == FunctionKind::Generator;
|
||||
auto source = String::formatted("function{} anonymous({}\n) {{\n{}\n}}", is_generator ? "*" : "", parameters_source, body_source);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue