mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 19:55:06 +00:00
LibJS: Implement ConsoleObject::count() as a Console::count() wrapper
Also implement ConsoleObject::count_clear() as a wrapper for Console::count_clear()
This commit is contained in:
parent
2e92c2e5e1
commit
e9c7d4524a
3 changed files with 37 additions and 28 deletions
|
@ -24,7 +24,9 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibJS/Console.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
|
@ -33,4 +35,29 @@ Console::Console(Interpreter& interpreter)
|
|||
{
|
||||
}
|
||||
|
||||
unsigned Console::count(String label)
|
||||
{
|
||||
auto counter_value = m_counters.get(label);
|
||||
if (!counter_value.has_value()) {
|
||||
printf("%s: 1\n", label.characters());
|
||||
m_counters.set(label, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto new_counter_value = counter_value.value() + 1;
|
||||
printf("%s: %d\n", label.characters(), new_counter_value);
|
||||
m_counters.set(label, new_counter_value);
|
||||
return new_counter_value;
|
||||
}
|
||||
|
||||
bool Console::count_reset(String label)
|
||||
{
|
||||
if (!m_counters.contains(label))
|
||||
return false;
|
||||
|
||||
m_counters.remove(label);
|
||||
printf("%s: 0\n", label.characters());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue