forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28ef654
commit 8c60ba1
Showing
3 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Copyright (c) 2020, Andreas Kling <[email protected]> | ||
* Copyright (c) 2020, Linus Groh <[email protected]> | ||
* Copyright (c) 2020, Emanuele Torre <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -27,6 +28,7 @@ | |
|
||
#include <AK/FlyString.h> | ||
#include <AK/Function.h> | ||
#include <AK/HashMap.h> | ||
#include <LibJS/Interpreter.h> | ||
#include <LibJS/Runtime/ConsoleObject.h> | ||
#include <LibJS/Runtime/GlobalObject.h> | ||
|
@@ -53,6 +55,7 @@ ConsoleObject::ConsoleObject() | |
put_native_function("warn", warn); | ||
put_native_function("error", error); | ||
put_native_function("trace", trace); | ||
put_native_function("count", count); | ||
} | ||
|
||
ConsoleObject::~ConsoleObject() | ||
|
@@ -109,4 +112,25 @@ Value ConsoleObject::trace(Interpreter& interpreter) | |
return js_undefined(); | ||
} | ||
|
||
Value ConsoleObject::count(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(); | ||
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); | ||
} | ||
return js_undefined(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters