mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-10-26 06:49:12 +03:00
LibWeb: Populate filename in WindowOrWorkerGlobalScope.reportError()
Previously, when `WindowOrWorkerGlobalScope.reportError()` was called the `filename` property of the dispatched error event was blank. It is now populated with the full path of the active script.
This commit is contained in:
parent
572324d47b
commit
34b9873664
Notes:
sideshowbarker
2024-07-16 20:31:50 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/34b9873664 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/493
@ -1,5 +1,6 @@
|
||||
message = Reporting an Error!
|
||||
filename =
|
||||
lineno = 0
|
||||
colno = 0
|
||||
error = Error: Reporting an Error!
|
||||
filename URL scheme = file:
|
||||
filename URL final path segment = WindowOrWorkerGlobalScope-reportError.html
|
||||
|
@ -3,11 +3,13 @@
|
||||
test(() => {
|
||||
window.onerror = (message, filename, lineno, colno, error) => {
|
||||
println(`message = ${message}`);
|
||||
println(`filename = ${filename}`);
|
||||
println(`lineno = ${lineno}`);
|
||||
println(`colno = ${colno}`);
|
||||
println(`error = ${error}`);
|
||||
|
||||
// We can't simply print the filename because it is the full path to the active script, which varies between machines.
|
||||
const filenameURL = new URL(filename);
|
||||
println(`filename URL scheme = ${filenameURL.protocol}`);
|
||||
println(`filename URL final path segment = ${filenameURL.pathname.split('/').pop()}`);
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -783,22 +783,30 @@ void WindowOrWorkerGlobalScopeMixin::report_error(JS::Value e)
|
||||
auto error_value = e;
|
||||
|
||||
// 5. Let urlString be the result of applying the URL serializer to the URL record that corresponds to the resource from which script was obtained.
|
||||
// FIXME: Use the URL of the current running script.
|
||||
auto url_string = String {};
|
||||
// NOTE: urlString is set below once we have determined whether we are dealing with a script or a module.
|
||||
String url_string;
|
||||
auto script_or_module_filename = [](auto const& script_or_module) {
|
||||
return MUST(String::from_utf8(script_or_module->filename()));
|
||||
};
|
||||
|
||||
// 6. If script is a classic script and script's muted errors is true, then set message to "Script error.",
|
||||
// urlString to the empty string, line and col to 0, and errorValue to null.
|
||||
script_or_module.visit(
|
||||
[&](const JS::NonnullGCPtr<JS::Script>& js_script) {
|
||||
[&](JS::NonnullGCPtr<JS::Script> const& js_script) {
|
||||
if (verify_cast<ClassicScript>(js_script->host_defined())->muted_errors() == ClassicScript::MutedErrors::Yes) {
|
||||
message = "Script error."_string;
|
||||
url_string = String {};
|
||||
line = 0;
|
||||
col = 0;
|
||||
error_value = JS::js_null();
|
||||
} else {
|
||||
url_string = script_or_module_filename(js_script);
|
||||
}
|
||||
},
|
||||
[](auto const&) {});
|
||||
[&](JS::NonnullGCPtr<JS::Module> const& js_module) {
|
||||
url_string = script_or_module_filename(js_module);
|
||||
},
|
||||
[](Empty) {});
|
||||
|
||||
// 7. Let notHandled be true.
|
||||
auto not_handled = true;
|
||||
|
Loading…
Reference in New Issue
Block a user