@@ -2564,47 +2564,184 @@ assert.strictEqual(
25642564 inspect ( thrower , { getters : true } ) ,
25652565 '{\n' +
25662566 ' foo: [Getter: <Inspection threw (Error: Oops\n' +
2567- ' at get foo (/foo/node_modules/foo.js:2:7)\n' +
2568- ' at get bar (/foo/node_modules/bar.js:827:30))>]\n' +
2567+ ' at get foo (/foo/node_modules/foo.js:2:7)\n' +
2568+ ' at get bar (/foo/node_modules/bar.js:827:30))>]\n' +
25692569 '}' ,
25702570 ) ;
25712571} ;
25722572
25732573// Property getter throwing an error with getters that throws.
25742574// https://github.com/nodejs/node/issues/60683
25752575{
2576- const error = new Error ( ) ;
2576+ const badError = new Error ( ) ;
2577+
2578+ const innerError = new Error ( 'Oops' ) ;
2579+ innerError . stack = [
2580+ 'Error: Oops' ,
2581+ ' at get foo (/foo/node_modules/foo.js:2:7)' ,
2582+ ' at get bar (/foo/node_modules/bar.js:827:30)' ,
2583+ ] . join ( '\n' ) ;
25772584
25782585 const throwingGetter = {
25792586 __proto__ : null ,
25802587 get ( ) {
2581- throw error ;
2588+ throw innerError ;
25822589 } ,
25832590 configurable : true ,
25842591 enumerable : true ,
25852592 } ;
25862593
2587- Object . defineProperties ( error , {
2594+ Object . defineProperties ( badError , {
25882595 name : throwingGetter ,
25892596 message : throwingGetter ,
25902597 stack : throwingGetter ,
25912598 cause : throwingGetter ,
25922599 } ) ;
25932600
25942601 const thrower = {
2595- get foo ( ) { throw error ; }
2602+ get foo ( ) { throw badError ; }
25962603 } ;
25972604
25982605 assert . strictEqual (
25992606 inspect ( thrower , { getters : true } ) ,
26002607 '{\n' +
26012608 ' foo: [Getter: <Inspection threw ([object Error] {\n' +
2602- ' stack: [Getter/Setter],\n' +
2603- ' name: [Getter],\n' +
2604- ' message: [Getter],\n' +
2605- ' cause: [Getter]\n' +
2606- '})>]\n' +
2607- '}' ,
2609+ ' stack: [Getter/Setter: <Inspection threw (Error: Oops\n' +
2610+ ' at get foo (/foo/node_modules/foo.js:2:7)\n' +
2611+ ' at get bar (/foo/node_modules/bar.js:827:30))>],\n' +
2612+ ' name: [Getter: <Inspection threw (Error: Oops\n' +
2613+ ' at get foo (/foo/node_modules/foo.js:2:7)\n' +
2614+ ' at get bar (/foo/node_modules/bar.js:827:30))>],\n' +
2615+ ' message: [Getter: <Inspection threw (Error: Oops\n' +
2616+ ' at get foo (/foo/node_modules/foo.js:2:7)\n' +
2617+ ' at get bar (/foo/node_modules/bar.js:827:30))>],\n' +
2618+ ' cause: [Getter: <Inspection threw (Error: Oops\n' +
2619+ ' at get foo (/foo/node_modules/foo.js:2:7)\n' +
2620+ ' at get bar (/foo/node_modules/bar.js:827:30))>]\n' +
2621+ ' })>]\n' +
2622+ '}'
2623+ ) ;
2624+ }
2625+
2626+ // Property getter throwing an error with getters that throws recursivly.
2627+ {
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 ; }
2661+ } ;
2662+
2663+ assert . strictEqual (
2664+ inspect ( thrower , { getters : true , depth : 2 } ) ,
2665+ '{\n' +
2666+ ' foo: [Getter: <Inspection threw ([object Error] {\n' +
2667+ ' stack: [Getter/Setter: <Inspection threw ([object Error] {\n' +
2668+ ' stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
2669+ ' message: [Getter: <Inspection threw ([Error])>]\n' +
2670+ ' })>],\n' +
2671+ ' message: [Getter: <Inspection threw ([object Error] {\n' +
2672+ ' stack: [Getter/Setter: <Inspection threw ([Error])>],\n' +
2673+ ' 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' +
2712+ ' })>],\n' +
2713+ ' 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' +
2742+ ' })>]\n' +
2743+ ' })>]\n' +
2744+ '}'
26082745 ) ;
26092746}
26102747
@@ -2650,7 +2787,7 @@ assert.strictEqual(
26502787 // eslint-disable-next-line no-throw-literal
26512788 get foo ( ) { throw { get message ( ) { return 'Oops' ; } } ; }
26522789 } , { getters : true } ) ,
2653- ' { foo: [Getter: <Inspection threw ({ message: [Getter] })>] }'
2790+ " { foo: [Getter: <Inspection threw ({ message: [Getter: 'Oops' ] })>] }"
26542791 ) ;
26552792 assert . strictEqual (
26562793 inspect ( {
0 commit comments