Truly independent web browser
LibJS: Add console.timeStamp(), profile() and profileEnd()
sideshowbarker855df715718e
diff --git a/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Libraries/LibJS/Runtime/CommonPropertyNames.hindex 4e96530d313..69d6d8903e4 100644--- a/Libraries/LibJS/Runtime/CommonPropertyNames.h+++ b/Libraries/LibJS/Runtime/CommonPropertyNames.h@@ -401,6 +401,8 @@ namespace JS {P(POSITIVE_INFINITY) \P(pow) \P(preventExtensions) \+ P(profile) \+ P(profileEnd) \P(promise) \P(propertyIsEnumerable) \P(prototype) \@@ -523,6 +525,7 @@ namespace JS {P(time) \P(timeEnd) \P(timeLog) \+ P(timeStamp) \P(timeStyle) \P(timeZone) \P(timeZoneId) \diff --git a/Libraries/LibJS/Rust/src/runtime/common_property_names.rs b/Libraries/LibJS/Rust/src/runtime/common_property_names.rsindex 8c7fe6d55f6..dcdf0ee1e7e 100644--- a/Libraries/LibJS/Rust/src/runtime/common_property_names.rs+++ b/Libraries/LibJS/Rust/src/runtime/common_property_names.rs@@ -453,6 +453,8 @@ define_common_property_names! {POSITIVE_INFINITY,pow,preventExtensions,+ profile,+ profileEnd,promise,propertyIsEnumerable,prototype,@@ -575,6 +577,7 @@ define_common_property_names! {time,timeEnd,timeLog,+ timeStamp,timeStyle,timeZone,timeZoneId,diff --git a/Libraries/LibJS/Rust/src/runtime/console_object.rs b/Libraries/LibJS/Rust/src/runtime/console_object.rsindex 183e213730f..62bb61617e5 100644--- a/Libraries/LibJS/Rust/src/runtime/console_object.rs+++ b/Libraries/LibJS/Rust/src/runtime/console_object.rs@@ -91,6 +91,11 @@ impl ConsoleObject {define(&names.time, raw_native!(ConsoleObject::time));define(&names.timeLog, raw_native!(ConsoleObject::time_log));define(&names.timeEnd, raw_native!(ConsoleObject::time_end));+ // AD-HOC: The spec has no profile(), profileEnd() or timeStamp(), but scripts call them, and they throw if+ // they're missing. They're for a profiler to act on, and do nothing without one.+ define(&names.profile, raw_native!(ConsoleObject::do_nothing));+ define(&names.profileEnd, raw_native!(ConsoleObject::do_nothing));+ define(&names.timeStamp, raw_native!(ConsoleObject::do_nothing));object.define_direct_property(vm,@@ -200,4 +205,9 @@ impl ConsoleObject {fn time_end(vm: &Vm) -> ThrowCompletionOr<Value> {console_of_current_realm(vm).time_end(vm)}++ #[allow(clippy::unnecessary_wraps, reason = "native functions return a completion")]+ fn do_nothing(_vm: &Vm) -> ThrowCompletionOr<Value> {+ Ok(Value::UNDEFINED)+ }}diff --git a/Tests/LibWeb/Text/expected/console/console-timestamp-and-profile.txt b/Tests/LibWeb/Text/expected/console/console-timestamp-and-profile.txtnew file mode 100644index 00000000000..8cd4227e327--- /dev/null+++ b/Tests/LibWeb/Text/expected/console/console-timestamp-and-profile.txt@@ -0,0 +1,3 @@+timeStamp: function, length 0, writable true, enumerable true, configurable true, returns undefined+profile: function, length 0, writable true, enumerable true, configurable true, returns undefined+profileEnd: function, length 0, writable true, enumerable true, configurable true, returns undefineddiff --git a/Tests/LibWeb/Text/input/console/console-timestamp-and-profile.html b/Tests/LibWeb/Text/input/console/console-timestamp-and-profile.htmlnew file mode 100644index 00000000000..827bc2600ef--- /dev/null+++ b/Tests/LibWeb/Text/input/console/console-timestamp-and-profile.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ // Scripts call console.timeStamp(), console.profile() and console.profileEnd() as all engines provide them, so they+ // have to exist rather than throw: Here, with no profiler, they do nothing.+ test(() => {+ for (const name of ["timeStamp", "profile", "profileEnd"]) {+ const descriptor = Object.getOwnPropertyDescriptor(console, name);+ const result = console[name]("label", 1);+ println(`${name}: ${typeof console[name]}, length ${console[name].length}, writable ${descriptor.writable}, enumerable ${descriptor.enumerable}, configurable ${descriptor.configurable}, returns ${result}`);+ }+ });+</script>