mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 04:17:34 +00: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:
parent
b9b3d01bea
commit
f7c9bd0760
10 changed files with 357 additions and 354 deletions
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue