@@ -2625,120 +2625,49 @@ assert.strictEqual(
26252625
26262626// Property getter throwing an error with getters that throws recursivly.
26272627{
2628- const terminalError = new Error ( 'Oops' ) ;
2629- terminalError . stack = [
2630- 'Error: Oops' ,
2631- ' at get foo (/foo/node_modules/foo.js:2:7)' ,
2632- ] . join ( '\n' ) ;
2633-
2634- function getRecursiveThrowingError ( recursions ) {
2635- const badError = new Error ( ) ;
2636-
2637- const innerError = recursions > 0 ?
2638- getRecursiveThrowingError ( recursions - 1 ) :
2639- terminalError ;
2640-
2641- const throwingGetter = {
2642- __proto__ : null ,
2643- get ( ) {
2644- throw innerError ;
2645- } ,
2646- configurable : true ,
2647- enumerable : true ,
2648- } ;
2649-
2650- Object . defineProperties ( badError , {
2651- message : throwingGetter ,
2652- stack : throwingGetter ,
2653- } ) ;
2654-
2655- return badError ;
2656- }
2657-
2658- const badRecursiveError = getRecursiveThrowingError ( 3 ) ;
2659- const thrower = {
2660- get foo ( ) { throw badRecursiveError ; }
2628+ const recursivelyThrowingErrorDesc = {
2629+ __proto__ : null ,
2630+ // eslint-disable-next-line no-restricted-syntax
2631+ get ( ) { throw createRecursivelyThrowingError ( ) ; } ,
2632+ configurable : true ,
2633+ enumerable : true ,
26612634 } ;
2635+ const createRecursivelyThrowingError = ( ) =>
2636+ Object . defineProperties ( new Error ( ) , {
2637+ cause : recursivelyThrowingErrorDesc ,
2638+ name : recursivelyThrowingErrorDesc ,
2639+ message : recursivelyThrowingErrorDesc ,
2640+ stack : recursivelyThrowingErrorDesc ,
2641+ } ) ;
2642+ const thrower = Object . defineProperty ( { } , 'foo' , recursivelyThrowingErrorDesc ) ;
26622643
26632644 assert . strictEqual (
26642645 inspect ( thrower , { getters : true , depth : 2 } ) ,
26652646 '{\n' +
26662647 ' foo: [Getter: <Inspection threw ([object Error] {\n' +
26672648 ' stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
26682649 ' stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
2650+ ' cause: [Getter: <Inspection threw ([Error])>],\n' +
2651+ ' name: [Getter: <Inspection threw ([Error])>],\n' +
26692652 ' message: [Getter: <Inspection threw ([Error])>]\n' +
26702653 ' })>],\n' +
2671- ' message : [Getter: <Inspection threw ([object Error] {\n' +
2654+ ' cause : [Getter: <Inspection threw ([object Error] {\n' +
26722655 ' stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
2656+ ' cause: [Getter: <Inspection threw ([Error])>],\n' +
2657+ ' name: [Getter: <Inspection threw ([Error])>],\n' +
2658+ ' message: [Getter: <Inspection threw ([Error])>]\n' +
2659+ ' })>],\n' +
2660+ ' name: [Getter: <Inspection threw ([object Error] {\n' +
2661+ ' stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
2662+ ' cause: [Getter: <Inspection threw ([Error])>],\n' +
2663+ ' name: [Getter: <Inspection threw ([Error])>],\n' +
26732664 ' message: [Getter: <Inspection threw ([Error])>]\n' +
2674- ' })>]\n' +
2675- ' })>]\n' +
2676- '}'
2677- ) ;
2678-
2679- assert . strictEqual (
2680- inspect ( thrower , { getters : true , depth : 4 } ) ,
2681- '{\n' +
2682- ' foo: [Getter: <Inspection threw ([object Error] {\n' +
2683- ' stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
2684- ' stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
2685- ' stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
2686- ' stack: [Getter/Setter: <Inspection threw (Error: Oops\n' +
2687- ' at get foo (/foo/node_modules/foo.js:2:7))>],\n' +
2688- ' message: [Getter: <Inspection threw (Error: Oops\n' +
2689- ' at get foo (/foo/node_modules/foo.js:2:7))>]\n' +
2690- ' })>],\n' +
2691- ' message: [Getter: <Inspection threw ([object Error] {\n' +
2692- ' stack: [Getter/Setter: <Inspection threw (Error: Oops\n' +
2693- ' at get foo (/foo/node_modules/foo.js:2:7))>],\n' +
2694- ' message: [Getter: <Inspection threw (Error: Oops\n' +
2695- ' at get foo (/foo/node_modules/foo.js:2:7))>]\n' +
2696- ' })>]\n' +
2697- ' })>],\n' +
2698- ' message: [Getter: <Inspection threw ([object Error] {\n' +
2699- ' stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
2700- ' stack: [Getter/Setter: <Inspection threw (Error: Oops\n' +
2701- ' at get foo (/foo/node_modules/foo.js:2:7))>],\n' +
2702- ' message: [Getter: <Inspection threw (Error: Oops\n' +
2703- ' at get foo (/foo/node_modules/foo.js:2:7))>]\n' +
2704- ' })>],\n' +
2705- ' message: [Getter: <Inspection threw ([object Error] {\n' +
2706- ' stack: [Getter/Setter: <Inspection threw (Error: Oops\n' +
2707- ' at get foo (/foo/node_modules/foo.js:2:7))>],\n' +
2708- ' message: [Getter: <Inspection threw (Error: Oops\n' +
2709- ' at get foo (/foo/node_modules/foo.js:2:7))>]\n' +
2710- ' })>]\n' +
2711- ' })>]\n' +
27122665 ' })>],\n' +
27132666 ' message: [Getter: <Inspection threw ([object Error] {\n' +
2714- ' stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
2715- ' stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
2716- ' stack: [Getter/Setter: <Inspection threw (Error: Oops\n' +
2717- ' at get foo (/foo/node_modules/foo.js:2:7))>],\n' +
2718- ' message: [Getter: <Inspection threw (Error: Oops\n' +
2719- ' at get foo (/foo/node_modules/foo.js:2:7))>]\n' +
2720- ' })>],\n' +
2721- ' message: [Getter: <Inspection threw ([object Error] {\n' +
2722- ' stack: [Getter/Setter: <Inspection threw (Error: Oops\n' +
2723- ' at get foo (/foo/node_modules/foo.js:2:7))>],\n' +
2724- ' message: [Getter: <Inspection threw (Error: Oops\n' +
2725- ' at get foo (/foo/node_modules/foo.js:2:7))>]\n' +
2726- ' })>]\n' +
2727- ' })>],\n' +
2728- ' message: [Getter: <Inspection threw ([object Error] {\n' +
2729- ' stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
2730- ' stack: [Getter/Setter: <Inspection threw (Error: Oops\n' +
2731- ' at get foo (/foo/node_modules/foo.js:2:7))>],\n' +
2732- ' message: [Getter: <Inspection threw (Error: Oops\n' +
2733- ' at get foo (/foo/node_modules/foo.js:2:7))>]\n' +
2734- ' })>],\n' +
2735- ' message: [Getter: <Inspection threw ([object Error] {\n' +
2736- ' stack: [Getter/Setter: <Inspection threw (Error: Oops\n' +
2737- ' at get foo (/foo/node_modules/foo.js:2:7))>],\n' +
2738- ' message: [Getter: <Inspection threw (Error: Oops\n' +
2739- ' at get foo (/foo/node_modules/foo.js:2:7))>]\n' +
2740- ' })>]\n' +
2741- ' })>]\n' +
2667+ ' stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
2668+ ' cause: [Getter: <Inspection threw ([Error])>],\n' +
2669+ ' name: [Getter: <Inspection threw ([Error])>],\n' +
2670+ ' message: [Getter: <Inspection threw ([Error])>]\n' +
27422671 ' })>]\n' +
27432672 ' })>]\n' +
27442673 '}'
0 commit comments