1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:57:45 +00:00

LibJS: Begin implementing console.dir

The intent of the spec is that the output of console.dir is interactable
within the console. Our Printer implementation currently just prints the
provided object as a string, and doesn't check the provided `options`
argument. But having console.dir defined prevents exceptions from being
thrown on real websites.
This commit is contained in:
Timothy Flynn 2023-06-21 21:29:24 -04:00 committed by Andreas Kling
parent 9f8e5f0b1c
commit 396655d145
5 changed files with 31 additions and 0 deletions

View file

@ -168,6 +168,26 @@ ThrowCompletionOr<Value> Console::warn()
return js_undefined();
}
// 1.1.10. dir(item, options), https://console.spec.whatwg.org/#dir
ThrowCompletionOr<Value> Console::dir()
{
auto& vm = realm().vm();
// 1. Let object be item with generic JavaScript object formatting applied.
// NOTE: Generic formatting is performed by ConsoleClient::printer().
auto object = vm.argument(0);
// 2. Perform Printer("dir", « object », options).
if (m_client) {
MarkedVector<Value> printer_arguments { vm.heap() };
TRY_OR_THROW_OOM(vm, printer_arguments.try_append(object));
return m_client->printer(LogLevel::Dir, move(printer_arguments));
}
return js_undefined();
}
static ThrowCompletionOr<String> label_or_fallback(VM& vm, StringView fallback)
{
return vm.argument_count() > 0