LibJS+LibWeb: Add a custom host hook to log unparsed date strings
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-22.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-22.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run

This lets us log when our Date.parse implementation was unable to handle
a string found on the web.
This commit is contained in:
Timothy Flynn 2024-09-08 11:15:07 -04:00 committed by Andreas Kling
parent 921a9cef62
commit 8d6f36f8d6
Notes: github-actions[bot] 2024-09-08 16:25:58 +00:00
4 changed files with 13 additions and 3 deletions

View file

@ -150,7 +150,7 @@ static double parse_simplified_iso8601(ByteString const& iso_8601)
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);
if (isfinite(value))
@ -188,6 +188,7 @@ static double parse_date_string(ByteString const& date_string)
return 1000.0 * maybe_datetime->timestamp();
}
vm.host_unrecognized_date_string(date_string);
return NAN;
}
@ -257,7 +258,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> DateConstructor::construct(FunctionObjec
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(primitive.as_string().byte_string());
time_value = parse_date_string(vm, primitive.as_string().byte_string());
}
// iii. Else,
else {
@ -334,7 +335,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateConstructor::parse)
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

View file

@ -164,6 +164,10 @@ VM::VM(OwnPtr<CustomData> custom_data, ErrorMessages error_messages)
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;

View file

@ -274,6 +274,7 @@ public:
Function<ThrowCompletionOr<void>(Realm&)> host_ensure_can_compile_strings;
Function<ThrowCompletionOr<void>(Object&)> host_ensure_can_add_private_element;
Function<ThrowCompletionOr<HandledByHost>(ArrayBuffer&, size_t)> host_resize_array_buffer;
Function<void(StringView)> host_unrecognized_date_string;
Vector<StackTraceElement> stack_trace() const;

View file

@ -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);
};
s_main_thread_vm->host_unrecognized_date_string = [](StringView date) {
dbgln("Unable to parse date string: \"{}\"", date);
};
return {};
}