mirror of
https://github.com/RGBCube/serenity
synced 2025-05-23 17:55:08 +00:00
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.
This commit is contained in:
parent
8c60ba1e42
commit
46b79eaad9
2 changed files with 20 additions and 0 deletions
|
@ -56,6 +56,7 @@ ConsoleObject::ConsoleObject()
|
||||||
put_native_function("error", error);
|
put_native_function("error", error);
|
||||||
put_native_function("trace", trace);
|
put_native_function("trace", trace);
|
||||||
put_native_function("count", count);
|
put_native_function("count", count);
|
||||||
|
put_native_function("countReset", count_reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsoleObject::~ConsoleObject()
|
ConsoleObject::~ConsoleObject()
|
||||||
|
@ -133,4 +134,22 @@ Value ConsoleObject::count(Interpreter& interpreter)
|
||||||
return js_undefined();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ private:
|
||||||
static Value error(Interpreter&);
|
static Value error(Interpreter&);
|
||||||
static Value trace(Interpreter&);
|
static Value trace(Interpreter&);
|
||||||
static Value count(Interpreter&);
|
static Value count(Interpreter&);
|
||||||
|
static Value count_reset(Interpreter&);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue