mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 10:07:15 +02:00
LibJS: Convert remaining Date AOs using JS::Value as in/output to double
There was an awful lot of JS::Value <-> double conversion going on, even through these AOs only work with number values anyway. They don't need a global object either as they won't allocate or throw, that was simply to pass it to infallible calls of ToIntegerOrInfinity.
This commit is contained in:
Notes:
sideshowbarker
2024-07-17 11:14:03 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/f7c9bd0760 Pull-request: https://github.com/SerenityOS/serenity/pull/13936 Reviewed-by: https://github.com/trflynn89
@@ -44,19 +44,21 @@ ThrowCompletionOr<Value> DateTimeFormatFunction::call()
|
||||
// 1. Let dtf be F.[[DateTimeFormat]].
|
||||
// 2. Assert: Type(dtf) is Object and dtf has an [[InitializedDateTimeFormat]] internal slot.
|
||||
|
||||
double date_value;
|
||||
|
||||
// 3. If date is not provided or is undefined, then
|
||||
if (date.is_undefined()) {
|
||||
// a. Let x be ! Call(%Date.now%, undefined).
|
||||
date = MUST(JS::call(global_object, global_object.date_constructor_now_function(), js_undefined()));
|
||||
date_value = MUST(JS::call(global_object, global_object.date_constructor_now_function(), js_undefined())).as_double();
|
||||
}
|
||||
// 4. Else,
|
||||
else {
|
||||
// a. Let x be ? ToNumber(date).
|
||||
date = TRY(date.to_number(global_object));
|
||||
date_value = TRY(date.to_number(global_object)).as_double();
|
||||
}
|
||||
|
||||
// 5. Return ? FormatDateTime(dtf, x).
|
||||
auto formatted = TRY(format_date_time(global_object, m_date_time_format, date));
|
||||
auto formatted = TRY(format_date_time(global_object, m_date_time_format, date_value));
|
||||
return js_string(vm, move(formatted));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user