diff options
author | Emanuele Torre <torreemanuele6@gmail.com> | 2020-05-01 08:59:05 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-01 13:02:01 +0200 |
commit | 46b79eaad9389e438d99bc06e5beca4408abb089 (patch) | |
tree | 953d68b623b326a64ba78abd78fb32f81dd32092 /Libraries | |
parent | 8c60ba1e4227383c81a1b6bbb94696d15d638a83 (diff) | |
download | serenity-46b79eaad9389e438d99bc06e5beca4408abb089.zip |
LibJS: Implement console.countReset()
I chose to also make it print "<counter_name>: 0\n" when a counter gets
reset, similarly to how firefox behaves.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibJS/Runtime/ConsoleObject.cpp | 19 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/ConsoleObject.h | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/Libraries/LibJS/Runtime/ConsoleObject.cpp b/Libraries/LibJS/Runtime/ConsoleObject.cpp index 8e8c9e2dcc..4c6b9f326a 100644 --- a/Libraries/LibJS/Runtime/ConsoleObject.cpp +++ b/Libraries/LibJS/Runtime/ConsoleObject.cpp @@ -56,6 +56,7 @@ ConsoleObject::ConsoleObject() put_native_function("error", error); put_native_function("trace", trace); put_native_function("count", count); + put_native_function("countReset", count_reset); } ConsoleObject::~ConsoleObject() @@ -133,4 +134,22 @@ Value ConsoleObject::count(Interpreter& interpreter) return js_undefined(); } +Value ConsoleObject::count_reset(Interpreter& interpreter) +{ + String counter_name; + if (!interpreter.argument_count()) + counter_name = "default"; + else + counter_name = interpreter.argument(0).to_string(); + + auto& counters = interpreter.console_counters(); + + if (counters.contains(counter_name)) { + counters.remove(counter_name); + printf("%s: 0\n", counter_name.characters()); + } + + return js_undefined(); +} + } diff --git a/Libraries/LibJS/Runtime/ConsoleObject.h b/Libraries/LibJS/Runtime/ConsoleObject.h index 50874a357a..eff99da621 100644 --- a/Libraries/LibJS/Runtime/ConsoleObject.h +++ b/Libraries/LibJS/Runtime/ConsoleObject.h @@ -45,6 +45,7 @@ private: static Value error(Interpreter&); static Value trace(Interpreter&); static Value count(Interpreter&); + static Value count_reset(Interpreter&); }; } |