diff options
author | Emanuele Torre <torreemanuele6@gmail.com> | 2020-05-01 15:19:43 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-02 11:41:35 +0200 |
commit | e9c7d4524af15dc1df1f871b78b92063b5b43f1d (patch) | |
tree | 847339f1207273cb246e0289e44497d5656eb845 /Libraries/LibJS/Runtime | |
parent | 2e92c2e5e16e75970c3cc0a0e520a905f18c3e49 (diff) | |
download | serenity-e9c7d4524af15dc1df1f871b78b92063b5b43f1d.zip |
LibJS: Implement ConsoleObject::count() as a Console::count() wrapper
Also implement ConsoleObject::count_clear() as a wrapper for
Console::count_clear()
Diffstat (limited to 'Libraries/LibJS/Runtime')
-rw-r--r-- | Libraries/LibJS/Runtime/ConsoleObject.cpp | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/Libraries/LibJS/Runtime/ConsoleObject.cpp b/Libraries/LibJS/Runtime/ConsoleObject.cpp index 3f01bf3449..c4d2be4fa3 100644 --- a/Libraries/LibJS/Runtime/ConsoleObject.cpp +++ b/Libraries/LibJS/Runtime/ConsoleObject.cpp @@ -28,7 +28,7 @@ #include <AK/FlyString.h> #include <AK/Function.h> -#include <AK/HashMap.h> +#include <LibJS/Console.h> #include <LibJS/Interpreter.h> #include <LibJS/Runtime/ConsoleObject.h> #include <LibJS/Runtime/GlobalObject.h> @@ -115,40 +115,19 @@ Value ConsoleObject::trace(Interpreter& interpreter) Value ConsoleObject::count(Interpreter& interpreter) { - String counter_name; - if (!interpreter.argument_count()) - counter_name = "default"; + if (interpreter.argument_count()) + interpreter.console().count(interpreter.argument(0).to_string()); else - counter_name = interpreter.argument(0).to_string(); - - auto& counters = interpreter.console().counters(); - auto counter_value = counters.get(counter_name); - - if (counter_value.has_value()) { - printf("%s: %d\n", counter_name.characters(), counter_value.value() + 1); - counters.set(counter_name, counter_value.value() + 1); - } else { - printf("%s: 1\n", counter_name.characters()); - counters.set(counter_name, 1); - } + interpreter.console().count(); return js_undefined(); } Value ConsoleObject::count_reset(Interpreter& interpreter) { - String counter_name; - if (!interpreter.argument_count()) - counter_name = "default"; + if (interpreter.argument_count()) + interpreter.console().count_reset(interpreter.argument(0).to_string()); 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()); - } - + interpreter.console().count_reset(); return js_undefined(); } |