mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-28 04:09:00 +00:00
LibJS+LibWeb: Add a custom host hook to log unparsed date strings
This lets us log when our Date.parse implementation was unable to handle a string found on the web.
This commit is contained in:
parent
921a9cef62
commit
8d6f36f8d6
Notes:
github-actions[bot]
2024-09-08 16:25:58 +00:00
Author: https://github.com/trflynn89
Commit: 8d6f36f8d6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1331
4 changed files with 13 additions and 3 deletions
|
@ -150,7 +150,7 @@ static double parse_simplified_iso8601(ByteString const& iso_8601)
|
||||||
return time_clip(time_ms);
|
return time_clip(time_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double parse_date_string(ByteString const& date_string)
|
static double parse_date_string(VM& vm, ByteString const& date_string)
|
||||||
{
|
{
|
||||||
auto value = parse_simplified_iso8601(date_string);
|
auto value = parse_simplified_iso8601(date_string);
|
||||||
if (isfinite(value))
|
if (isfinite(value))
|
||||||
|
@ -188,6 +188,7 @@ static double parse_date_string(ByteString const& date_string)
|
||||||
return 1000.0 * maybe_datetime->timestamp();
|
return 1000.0 * maybe_datetime->timestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vm.host_unrecognized_date_string(date_string);
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +258,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> DateConstructor::construct(FunctionObjec
|
||||||
if (primitive.is_string()) {
|
if (primitive.is_string()) {
|
||||||
// 1. Assert: The next step never returns an abrupt completion because Type(v) 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).
|
// 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(primitive.as_string().byte_string());
|
time_value = parse_date_string(vm, primitive.as_string().byte_string());
|
||||||
}
|
}
|
||||||
// iii. Else,
|
// iii. Else,
|
||||||
else {
|
else {
|
||||||
|
@ -334,7 +335,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateConstructor::parse)
|
||||||
|
|
||||||
auto date_string = TRY(vm.argument(0).to_byte_string(vm));
|
auto date_string = TRY(vm.argument(0).to_byte_string(vm));
|
||||||
|
|
||||||
return Value(parse_date_string(date_string));
|
return Value(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
|
// 21.4.3.4 Date.UTC ( year [ , month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ] ), https://tc39.es/ecma262/#sec-date.utc
|
||||||
|
|
|
@ -164,6 +164,10 @@ VM::VM(OwnPtr<CustomData> custom_data, ErrorMessages error_messages)
|
||||||
|
|
||||||
return HandledByHost::Handled;
|
return HandledByHost::Handled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// AD-HOC: Inform the host that we received a date string we were unable to parse.
|
||||||
|
host_unrecognized_date_string = [](StringView) {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
VM::~VM() = default;
|
VM::~VM() = default;
|
||||||
|
|
|
@ -274,6 +274,7 @@ public:
|
||||||
Function<ThrowCompletionOr<void>(Realm&)> host_ensure_can_compile_strings;
|
Function<ThrowCompletionOr<void>(Realm&)> host_ensure_can_compile_strings;
|
||||||
Function<ThrowCompletionOr<void>(Object&)> host_ensure_can_add_private_element;
|
Function<ThrowCompletionOr<void>(Object&)> host_ensure_can_add_private_element;
|
||||||
Function<ThrowCompletionOr<HandledByHost>(ArrayBuffer&, size_t)> host_resize_array_buffer;
|
Function<ThrowCompletionOr<HandledByHost>(ArrayBuffer&, size_t)> host_resize_array_buffer;
|
||||||
|
Function<void(StringView)> host_unrecognized_date_string;
|
||||||
|
|
||||||
Vector<StackTraceElement> stack_trace() const;
|
Vector<StackTraceElement> stack_trace() const;
|
||||||
|
|
||||||
|
|
|
@ -545,6 +545,10 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
|
||||||
HTML::fetch_single_imported_module_script(realm, url.release_value(), *fetch_client, destination, fetch_options, *settings_object, fetch_referrer, module_request, perform_fetch, on_single_fetch_complete);
|
HTML::fetch_single_imported_module_script(realm, url.release_value(), *fetch_client, destination, fetch_options, *settings_object, fetch_referrer, module_request, perform_fetch, on_single_fetch_complete);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
s_main_thread_vm->host_unrecognized_date_string = [](StringView date) {
|
||||||
|
dbgln("Unable to parse date string: \"{}\"", date);
|
||||||
|
};
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue