mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-07 21:17:07 +09:00
js: Make print variadic for consistency with other repls
This commit is contained in:
parent
81e84c8273
commit
8b08162942
Notes:
github-actions[bot]
2025-05-29 23:34:32 +00:00
Author: https://github.com/ananas-dev
Commit: 8b08162942
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4915
Reviewed-by: https://github.com/trflynn89 ✅
1 changed files with 19 additions and 4 deletions
|
@ -112,6 +112,21 @@ static ErrorOr<void> print(JS::Value value, PrintTarget target = PrintTarget::St
|
|||
return print(value, *stream);
|
||||
}
|
||||
|
||||
static ErrorOr<void> print_all_arguments(JS::VM const& vm, PrintTarget target = PrintTarget::StandardOutput)
|
||||
{
|
||||
auto stream = TRY(target == PrintTarget::StandardError ? Core::File::standard_error() : Core::File::standard_output());
|
||||
|
||||
for (size_t i = 0; i < vm.argument_count(); i++) {
|
||||
TRY(print(vm.argument(i), *stream));
|
||||
|
||||
if (i < vm.argument_count() - 1) {
|
||||
TRY(stream->write_until_depleted(" "sv));
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static size_t s_ctrl_c_hit_count = 0;
|
||||
[[maybe_unused]] static ErrorOr<String> prompt_for_level(int level)
|
||||
{
|
||||
|
@ -331,9 +346,9 @@ JS_DEFINE_NATIVE_FUNCTION(ReplObject::load_json)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(ReplObject::print)
|
||||
{
|
||||
auto result = ::print(vm.argument(0));
|
||||
auto result = print_all_arguments(vm);
|
||||
if (result.is_error())
|
||||
return g_vm->throw_completion<JS::InternalError>(TRY_OR_THROW_OOM(*g_vm, String::formatted("Failed to print value: {}", result.error())));
|
||||
return g_vm->throw_completion<JS::InternalError>(TRY_OR_THROW_OOM(*g_vm, String::formatted("Failed to print value(s): {}", result.error())));
|
||||
|
||||
outln();
|
||||
|
||||
|
@ -363,9 +378,9 @@ JS_DEFINE_NATIVE_FUNCTION(ScriptObject::load_json)
|
|||
|
||||
JS_DEFINE_NATIVE_FUNCTION(ScriptObject::print)
|
||||
{
|
||||
auto result = ::print(vm.argument(0));
|
||||
auto result = print_all_arguments(vm);
|
||||
if (result.is_error())
|
||||
return g_vm->throw_completion<JS::InternalError>(TRY_OR_THROW_OOM(*g_vm, String::formatted("Failed to print value: {}", result.error())));
|
||||
return g_vm->throw_completion<JS::InternalError>(TRY_OR_THROW_OOM(*g_vm, String::formatted("Failed to print value(s): {}", result.error())));
|
||||
|
||||
outln();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue