LibJS: Implement console.time/timeLog/timeEnd() methods

This commit is contained in:
Sam Atkins 2021-12-22 16:40:57 +00:00 committed by Andreas Kling
commit 1fba221b46
Notes: sideshowbarker 2024-07-17 22:06:34 +09:00
5 changed files with 152 additions and 1 deletions

View file

@ -11,6 +11,7 @@
#include <AK/HashMap.h>
#include <AK/Noncopyable.h>
#include <AK/Vector.h>
#include <LibCore/ElapsedTimer.h>
#include <LibJS/Forward.h>
#include <LibJS/Runtime/Value.h>
@ -78,17 +79,21 @@ public:
ThrowCompletionOr<Value> group();
ThrowCompletionOr<Value> group_collapsed();
ThrowCompletionOr<Value> group_end();
ThrowCompletionOr<Value> time();
ThrowCompletionOr<Value> time_log();
ThrowCompletionOr<Value> time_end();
void output_debug_message(LogLevel log_level, String output) const;
private:
ThrowCompletionOr<String> value_vector_to_string(Vector<Value>&);
ThrowCompletionOr<String> format_time_since(Core::ElapsedTimer timer);
GlobalObject& m_global_object;
ConsoleClient* m_client { nullptr };
HashMap<String, unsigned> m_counters;
HashMap<String, Core::ElapsedTimer> m_timer_table;
Vector<Group> m_group_stack;
};