LibJS+WebContent+js: Bring console.clear() to spec

This is identical to before, since we don't have "group stacks" yet, but
clear() now uses ThrowCompletionOr.
This commit is contained in:
Sam Atkins 2021-12-08 19:24:17 +00:00 committed by Andreas Kling
parent 834ced82d4
commit 9b78e287b0
Notes: sideshowbarker 2024-07-17 22:06:57 +09:00
5 changed files with 9 additions and 7 deletions

View file

@ -76,10 +76,14 @@ ThrowCompletionOr<Value> Console::warn()
return js_undefined();
}
// 1.1.2. clear(), https://console.spec.whatwg.org/#clear
Value Console::clear()
{
// 1. TODO: Empty the appropriate group stack.
// 2. If possible for the environment, clear the console. (Otherwise, do nothing.)
if (m_client)
return m_client->clear();
m_client->clear();
return js_undefined();
}

View file

@ -87,7 +87,7 @@ public:
ThrowCompletionOr<Vector<Value>> formatter(Vector<Value>& args);
virtual ThrowCompletionOr<Value> printer(Console::LogLevel log_level, Vector<Value>&) = 0;
virtual Value clear() = 0;
virtual void clear() = 0;
virtual Value trace() = 0;
virtual Value assert_() = 0;

View file

@ -115,10 +115,9 @@ void WebContentConsoleClient::send_messages(i32 start_index)
m_client.async_did_get_js_console_messages(start_index, message_types, messages);
}
JS::Value WebContentConsoleClient::clear()
void WebContentConsoleClient::clear()
{
clear_output();
return JS::js_undefined();
}
JS::Value WebContentConsoleClient::trace()

View file

@ -24,7 +24,7 @@ public:
void send_messages(i32 start_index);
private:
virtual JS::Value clear() override;
virtual void clear() override;
virtual JS::Value trace() override;
virtual JS::Value assert_() override;
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, Vector<JS::Value>&) override;

View file

@ -1122,11 +1122,10 @@ public:
{
}
virtual JS::Value clear() override
virtual void clear() override
{
js_out("\033[3J\033[H\033[2J");
fflush(stdout);
return JS::js_undefined();
}
virtual JS::Value trace() override