Skip to content

Commit 171c0cd

Browse files
committed
Simplify error property extraction slightly.
1 parent 0a89ef2 commit 171c0cd

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

packages/custom-elements/ts_src/CustomElementInternals.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ export default class CustomElementInternals {
537537
*
538538
* @see https://html.spec.whatwg.org/multipage/webappapis.html#report-the-exception
539539
*/
540-
reportTheException(errorArg: unknown) {
540+
reportTheException(arg: unknown) {
541541
interface ExtendedError extends Error {
542542
// Non-standard Safari properties.
543543
sourceURL?: string;
@@ -550,26 +550,20 @@ export default class CustomElementInternals {
550550
columnNumber?: number;
551551
}
552552

553-
const getErrorInfo = (maybeError: unknown) => {
554-
if (maybeError instanceof Error) {
555-
const error = maybeError as ExtendedError;
556-
return {
557-
message: error.message,
558-
filename: error.sourceURL || error.fileName || '',
559-
lineno: error.line || error.lineNumber || 0,
560-
colno: error.column || error.columnNumber || 0,
561-
};
562-
} else {
563-
return {
564-
message: `Uncaught ${String(maybeError)}`,
565-
filename: '',
566-
lineno: 0,
567-
colno: 0,
568-
};
569-
}
570-
};
571-
572-
const {message, filename, lineno, colno} = getErrorInfo(errorArg);
553+
let message = '';
554+
let filename = '';
555+
let lineno = 0;
556+
let colno = 0;
557+
558+
if (arg instanceof Error) {
559+
const error = arg as ExtendedError;
560+
message = error.message;
561+
filename = error.sourceURL || error.fileName || '';
562+
lineno = error.line || error.lineNumber || 0;
563+
colno = error.column || error.columnNumber || 0;
564+
} else {
565+
message = `Uncaught ${String(arg)}`;
566+
}
573567

574568
let event: ErrorEvent | undefined = undefined;
575569
if (ErrorEvent.prototype.initErrorEvent === undefined) {
@@ -579,7 +573,7 @@ export default class CustomElementInternals {
579573
filename,
580574
lineno,
581575
colno,
582-
error: errorArg,
576+
error: arg,
583577
});
584578
} else {
585579
event = document.createEvent('ErrorEvent') as ErrorEvent;
@@ -602,7 +596,7 @@ export default class CustomElementInternals {
602596
configurable: true,
603597
enumerable: true,
604598
get: function () {
605-
return errorArg;
599+
return arg;
606600
},
607601
});
608602
}
@@ -613,7 +607,7 @@ export default class CustomElementInternals {
613607
// console if their associated ErrorEvent isn't handled during dispatch
614608
// (indicated by calling `preventDefault`). In practice, these errors are
615609
// always displayed.
616-
console.error(errorArg);
610+
console.error(arg);
617611
}
618612
}
619613
}

0 commit comments

Comments
 (0)