@@ -102,6 +102,7 @@ describe('runtime log', () => {
102102 const parsed = JSON . parse ( arg ) ;
103103 expect ( parsed . msg ) . toBe ( 'visible' ) ;
104104 expect ( 'level' in parsed ) . toBe ( false ) ;
105+ expect ( Object . hasOwn ( parsed , '__proto__' ) ) . toBe ( true ) ;
105106 } ) ;
106107
107108 it ( 'throwing enumerable getters do not crash — fallback to safe shape' , ( ) => {
@@ -123,15 +124,15 @@ describe('runtime log', () => {
123124 expect ( parsed . error ) . toBe ( 'log: fields not serializable' ) ;
124125 } ) ;
125126
126- it ( 'a ` constructor` key in fields is skipped ', ( ) => {
127- logger . info ( 'ctor ' , { constructor : 'evil ' , keep : 'yes' } ) ;
127+ it . each ( [ '__proto__' , ' constructor' , 'prototype' ] ) ( 'preserves %s as an own log field ', ( key ) => {
128+ logger . info ( 'visible ' , { [ key ] : 'value ' , keep : 'yes' } ) ;
128129
129130 const arg = ( console . info as ReturnType < typeof vi . fn > ) . mock . calls [ 0 ] [ 0 ] as string ;
130131 const parsed = JSON . parse ( arg ) ;
131- expect ( parsed . msg ) . toBe ( 'ctor ' ) ;
132+ expect ( parsed . msg ) . toBe ( 'visible ' ) ;
132133 expect ( parsed . keep ) . toBe ( 'yes' ) ;
133- // Object.prototype already has `constructor`, so check own properties only.
134- expect ( Object . hasOwn ( parsed , 'constructor' ) ) . toBe ( false ) ;
134+ expect ( Object . hasOwn ( parsed , key ) ) . toBe ( true ) ;
135+ expect ( parsed [ key ] ) . toBe ( 'value' ) ;
135136 } ) ;
136137
137138 it ( 'non-stringifiable values (circular refs) do not crash — fallback to safe shape' , ( ) => {
@@ -241,7 +242,7 @@ describe('runtime log', () => {
241242 component : 'worker' ,
242243 msg : 'ignored' ,
243244 toJSON : ( ) => ( { hacked : true } ) ,
244- constructor : 'ignored ' ,
245+ constructor : 'custom ' ,
245246 fn : ( ) => { } ,
246247 } )
247248 . info ( 'safe' ) ;
@@ -251,6 +252,7 @@ describe('runtime log', () => {
251252 expect ( JSON . parse ( arg ) ) . toEqual ( {
252253 msg : 'safe' ,
253254 component : 'worker' ,
255+ constructor : 'custom' ,
254256 } ) ;
255257 } ) ;
256258
0 commit comments