@@ -281,7 +281,7 @@ export default class CustomElementInternals {
281
281
this . _upgradeAnElement ( element , definition ) ;
282
282
}
283
283
} catch ( e : unknown ) {
284
- this . reportTheException ( e as Error ) ;
284
+ this . reportTheException ( e ) ;
285
285
}
286
286
}
287
287
@@ -341,7 +341,7 @@ export default class CustomElementInternals {
341
341
try {
342
342
definition . connectedCallback . call ( element ) ;
343
343
} catch ( e : unknown ) {
344
- this . reportTheException ( e as Error ) ;
344
+ this . reportTheException ( e ) ;
345
345
}
346
346
}
347
347
}
@@ -352,7 +352,7 @@ export default class CustomElementInternals {
352
352
try {
353
353
definition . disconnectedCallback . call ( element ) ;
354
354
} catch ( e : unknown ) {
355
- this . reportTheException ( e as Error ) ;
355
+ this . reportTheException ( e ) ;
356
356
}
357
357
}
358
358
}
@@ -378,7 +378,7 @@ export default class CustomElementInternals {
378
378
namespace
379
379
) ;
380
380
} catch ( e : unknown ) {
381
- this . reportTheException ( e as Error ) ;
381
+ this . reportTheException ( e ) ;
382
382
}
383
383
}
384
384
}
@@ -506,7 +506,7 @@ export default class CustomElementInternals {
506
506
507
507
return result ;
508
508
} catch ( e : unknown ) {
509
- this . reportTheException ( e as Error ) ;
509
+ this . reportTheException ( e ) ;
510
510
511
511
// When construction fails, a new HTMLUnknownElement is produced.
512
512
// However, there's no direct way to create one, so we create a
@@ -537,7 +537,7 @@ export default class CustomElementInternals {
537
537
*
538
538
* @see https://html.spec.whatwg.org/multipage/webappapis.html#report-the-exception
539
539
*/
540
- reportTheException ( errorArg : Error ) {
540
+ reportTheException ( errorArg : unknown ) {
541
541
interface ExtendedError extends Error {
542
542
// Non-standard Safari properties.
543
543
sourceURL ?: string ;
@@ -550,11 +550,26 @@ export default class CustomElementInternals {
550
550
columnNumber ?: number ;
551
551
}
552
552
553
- const error = errorArg as ExtendedError ;
554
- const message = error . message ;
555
- const filename = error . sourceURL || error . fileName || '' ;
556
- const lineno = error . line || error . lineNumber || 0 ;
557
- const colno = error . column || error . columnNumber || 0 ;
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 ) ;
558
573
559
574
let event : ErrorEvent | undefined = undefined ;
560
575
if ( ErrorEvent . prototype . initErrorEvent === undefined ) {
@@ -564,7 +579,7 @@ export default class CustomElementInternals {
564
579
filename,
565
580
lineno,
566
581
colno,
567
- error,
582
+ error : errorArg ,
568
583
} ) ;
569
584
} else {
570
585
event = document . createEvent ( 'ErrorEvent' ) as ErrorEvent ;
@@ -587,7 +602,7 @@ export default class CustomElementInternals {
587
602
configurable : true ,
588
603
enumerable : true ,
589
604
get : function ( ) {
590
- return error ;
605
+ return errorArg ;
591
606
} ,
592
607
} ) ;
593
608
}
@@ -598,7 +613,7 @@ export default class CustomElementInternals {
598
613
// console if their associated ErrorEvent isn't handled during dispatch
599
614
// (indicated by calling `preventDefault`). In practice, these errors are
600
615
// always displayed.
601
- console . error ( error ) ;
616
+ console . error ( errorArg ) ;
602
617
}
603
618
}
604
619
}
0 commit comments