mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 08:08:43 +00: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: 34b9873664
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/493
3 changed files with 18 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
message = Reporting an Error!
|
message = Reporting an Error!
|
||||||
filename =
|
|
||||||
lineno = 0
|
lineno = 0
|
||||||
colno = 0
|
colno = 0
|
||||||
error = Error: Reporting an Error!
|
error = Error: Reporting an Error!
|
||||||
|
filename URL scheme = file:
|
||||||
|
filename URL final path segment = WindowOrWorkerGlobalScope-reportError.html
|
||||||
|
|
|
@ -3,11 +3,13 @@
|
||||||
test(() => {
|
test(() => {
|
||||||
window.onerror = (message, filename, lineno, colno, error) => {
|
window.onerror = (message, filename, lineno, colno, error) => {
|
||||||
println(`message = ${message}`);
|
println(`message = ${message}`);
|
||||||
println(`filename = ${filename}`);
|
|
||||||
println(`lineno = ${lineno}`);
|
println(`lineno = ${lineno}`);
|
||||||
println(`colno = ${colno}`);
|
println(`colno = ${colno}`);
|
||||||
println(`error = ${error}`);
|
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;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -783,22 +783,30 @@ void WindowOrWorkerGlobalScopeMixin::report_error(JS::Value e)
|
||||||
auto error_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.
|
// 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.
|
// NOTE: urlString is set below once we have determined whether we are dealing with a script or a module.
|
||||||
auto url_string = String {};
|
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.",
|
// 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.
|
// urlString to the empty string, line and col to 0, and errorValue to null.
|
||||||
script_or_module.visit(
|
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) {
|
if (verify_cast<ClassicScript>(js_script->host_defined())->muted_errors() == ClassicScript::MutedErrors::Yes) {
|
||||||
message = "Script error."_string;
|
message = "Script error."_string;
|
||||||
url_string = String {};
|
url_string = String {};
|
||||||
line = 0;
|
line = 0;
|
||||||
col = 0;
|
col = 0;
|
||||||
error_value = JS::js_null();
|
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.
|
// 7. Let notHandled be true.
|
||||||
auto not_handled = true;
|
auto not_handled = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue