|
24 | 24 | #include <LibWeb/Fetch/FetchMethod.h> |
25 | 25 | #include <LibWeb/HTML/CanvasRenderingContext2D.h> |
26 | 26 | #include <LibWeb/HTML/ErrorEvent.h> |
| 27 | +#include <LibWeb/HTML/ErrorInformation.h> |
27 | 28 | #include <LibWeb/HTML/EventLoop/EventLoop.h> |
28 | 29 | #include <LibWeb/HTML/EventSource.h> |
29 | 30 | #include <LibWeb/HTML/HTMLImageElement.h> |
@@ -1151,72 +1152,6 @@ void WindowOrWorkerGlobalScopeMixin::report_error(JS::Value e) |
1151 | 1152 | report_an_exception(e); |
1152 | 1153 | } |
1153 | 1154 |
|
1154 | | -// https://html.spec.whatwg.org/multipage/webappapis.html#extract-error |
1155 | | -struct ErrorInformation { |
1156 | | - String message; |
1157 | | - String filename; |
1158 | | - JS::Value error; |
1159 | | - size_t lineno { 0 }; |
1160 | | - size_t colno { 0 }; |
1161 | | -}; |
1162 | | - |
1163 | | -// https://html.spec.whatwg.org/multipage/webappapis.html#extract-error |
1164 | | -static ErrorInformation extract_error_information(JS::VM& vm, JS::Value exception) |
1165 | | -{ |
1166 | | - // 1. Let attributes be an empty map keyed by IDL attributes. |
1167 | | - ErrorInformation attributes; |
1168 | | - |
1169 | | - // 2. Set attributes[error] to exception. |
1170 | | - attributes.error = exception; |
1171 | | - |
1172 | | - // 3. Set attributes[message], attributes[filename], attributes[lineno], and attributes[colno] to |
1173 | | - // implementation-defined values derived from exception. |
1174 | | - attributes.message = [&] { |
1175 | | - if (exception.is_object()) { |
1176 | | - auto& object = exception.as_object(); |
1177 | | - if (MUST(object.has_own_property(vm.names.message))) { |
1178 | | - auto message = object.get_without_side_effects(vm.names.message); |
1179 | | - return message.to_string_without_side_effects(); |
1180 | | - } |
1181 | | - } |
1182 | | - |
1183 | | - return MUST(String::formatted("Uncaught exception: {}", exception.to_string_without_side_effects())); |
1184 | | - }(); |
1185 | | - |
1186 | | - // FIXME: This offset is relative to the javascript source. Other browsers appear to do it relative |
1187 | | - // to the entire source document! Calculate that somehow. |
1188 | | - |
1189 | | - // If we got an Error object, then try and extract the information from the location the object was made. |
1190 | | - if (exception.is_object() && is<JS::Error>(exception.as_object())) { |
1191 | | - auto const& error = static_cast<JS::Error&>(exception.as_object()); |
1192 | | - for (auto const& frame : error.traceback()) { |
1193 | | - auto source_range = frame.source_range(); |
1194 | | - if (source_range.start.line != 0 || source_range.start.column != 0) { |
1195 | | - attributes.filename = MUST(String::from_byte_string(source_range.filename())); |
1196 | | - attributes.lineno = source_range.start.line; |
1197 | | - attributes.colno = source_range.start.column; |
1198 | | - break; |
1199 | | - } |
1200 | | - } |
1201 | | - } |
1202 | | - // Otherwise, we fall back to try and find the location of the invocation of the function itself. |
1203 | | - else { |
1204 | | - for (ssize_t i = vm.execution_context_stack().size() - 1; i >= 0; --i) { |
1205 | | - auto& frame = vm.execution_context_stack()[i]; |
1206 | | - if (frame->executable) { |
1207 | | - auto source_range = frame->executable->source_range_at(frame->program_counter).realize(); |
1208 | | - attributes.filename = MUST(String::from_byte_string(source_range.filename())); |
1209 | | - attributes.lineno = source_range.start.line; |
1210 | | - attributes.colno = source_range.start.column; |
1211 | | - break; |
1212 | | - } |
1213 | | - } |
1214 | | - } |
1215 | | - |
1216 | | - // 4. Return attributes. |
1217 | | - return attributes; |
1218 | | -} |
1219 | | - |
1220 | 1155 | // https://html.spec.whatwg.org/multipage/webappapis.html#report-an-exception |
1221 | 1156 | void WindowOrWorkerGlobalScopeMixin::report_an_exception(JS::Value exception, OmitError omit_error) |
1222 | 1157 | { |
|
0 commit comments