mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 16:16:43 +00:00
LibJS: Port Date.parse string arguments to String
This commit is contained in:
parent
fc6155cf2c
commit
0d635100c4
Notes:
github-actions[bot]
2024-11-26 21:57:26 +00:00
Author: https://github.com/trflynn89
Commit: 0d635100c4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2594
1 changed files with 9 additions and 5 deletions
|
@ -25,7 +25,7 @@ namespace JS {
|
|||
GC_DEFINE_ALLOCATOR(DateConstructor);
|
||||
|
||||
// 21.4.3.2 Date.parse ( string ), https://tc39.es/ecma262/#sec-date.parse
|
||||
static Optional<double> parse_simplified_iso8601(ByteString const& iso_8601)
|
||||
static Optional<double> parse_simplified_iso8601(StringView iso_8601)
|
||||
{
|
||||
// 21.4.1.15 Date Time String Format, https://tc39.es/ecma262/#sec-date-time-string-format
|
||||
GenericLexer lexer(iso_8601);
|
||||
|
@ -148,7 +148,7 @@ static Optional<double> parse_simplified_iso8601(ByteString const& iso_8601)
|
|||
return time_clip(time_ms);
|
||||
}
|
||||
|
||||
static double parse_date_string(VM& vm, ByteString const& date_string)
|
||||
static double parse_date_string(VM& vm, StringView date_string)
|
||||
{
|
||||
if (date_string.is_empty())
|
||||
return NAN;
|
||||
|
@ -267,7 +267,7 @@ ThrowCompletionOr<GC::Ref<Object>> DateConstructor::construct(FunctionObject& ne
|
|||
if (primitive.is_string()) {
|
||||
// 1. Assert: The next step never returns an abrupt completion because Type(v) is String.
|
||||
// 2. Let tv be the result of parsing v as a date, in exactly the same manner as for the parse method (21.4.3.2).
|
||||
time_value = parse_date_string(vm, primitive.as_string().byte_string());
|
||||
time_value = parse_date_string(vm, primitive.as_string().utf8_string_view());
|
||||
}
|
||||
// iii. Else,
|
||||
else {
|
||||
|
@ -342,9 +342,13 @@ JS_DEFINE_NATIVE_FUNCTION(DateConstructor::parse)
|
|||
if (!vm.argument_count())
|
||||
return js_nan();
|
||||
|
||||
auto date_string = TRY(vm.argument(0).to_byte_string(vm));
|
||||
// This function applies the ToString operator to its argument. If ToString results in an abrupt completion the
|
||||
// Completion Record is immediately returned.
|
||||
auto date_string = TRY(vm.argument(0).to_string(vm));
|
||||
|
||||
return Value(parse_date_string(vm, date_string));
|
||||
// Otherwise, this function interprets the resulting String as a date and time; it returns a Number, the UTC time
|
||||
// value corresponding to the date and time.
|
||||
return parse_date_string(vm, date_string);
|
||||
}
|
||||
|
||||
// 21.4.3.4 Date.UTC ( year [ , month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ] ), https://tc39.es/ecma262/#sec-date.utc
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue