@@ -36,10 +36,12 @@ export function describeBuiltInComponentFrame(
3636 if ( enableComponentStackLocations ) {
3737 if ( prefix === undefined ) {
3838 // Extract the VM specific prefix used by each line.
39- const match = Error ( )
40- . stack . trim ( )
41- . match ( / \n ( * ( a t ) ? ) / ) ;
42- prefix = ( match && match [ 1 ] ) || '' ;
39+ try {
40+ throw Error ( ) ;
41+ } catch ( x ) {
42+ const match = x . stack . trim ( ) . match ( / \n ( * ( a t ) ? ) / ) ;
43+ prefix = ( match && match [ 1 ] ) || '' ;
44+ }
4345 }
4446 // We use the prefix to ensure our stacks line up with native stack frames.
4547 return '\n' + prefix + name ;
@@ -91,7 +93,7 @@ export function describeNativeComponentFrame(
9193 if ( construct ) {
9294 // Something should be setting the props in the constructor.
9395 const Fake = function ( ) {
94- return Error ( ) ;
96+ throw Error ( ) ;
9597 } ;
9698 // $FlowFixMe
9799 Object . defineProperty ( Fake . prototype , 'props' , {
@@ -104,14 +106,26 @@ export function describeNativeComponentFrame(
104106 if ( typeof Reflect === 'object' && Reflect . construct ) {
105107 // We construct a different control for this case to include any extra
106108 // frames added by the construct call.
107- control = Reflect . construct ( Fake , [ ] ) ;
109+ try {
110+ Reflect . construct ( Fake , [ ] ) ;
111+ } catch ( x ) {
112+ control = x ;
113+ }
108114 Reflect . construct ( fn , [ ] , Fake ) ;
109115 } else {
110- control = Error ( ) ;
116+ try {
117+ Fake . call ( ) ;
118+ } catch ( x ) {
119+ control = x ;
120+ }
111121 fn . call ( new Fake ( ) ) ;
112122 }
113123 } else {
114- control = Error ( ) ;
124+ try {
125+ throw Error ( ) ;
126+ } catch ( x ) {
127+ control = x ;
128+ }
115129 fn ( ) ;
116130 }
117131 } catch ( sample ) {
0 commit comments