@@ -307,38 +307,52 @@ assert.strictEqual(
307307{
308308 const myError = new errors . Error ( 'ERR_TLS_HANDSHAKE_TIMEOUT' ) ;
309309 assert . strictEqual ( myError . code , 'ERR_TLS_HANDSHAKE_TIMEOUT' ) ;
310+ assert . strictEqual ( myError . hasOwnProperty ( 'code' ) , false ) ;
311+ assert . strictEqual ( myError . hasOwnProperty ( 'name' ) , false ) ;
312+ assert . deepStrictEqual ( Object . keys ( myError ) , [ ] ) ;
310313 const initialName = myError . name ;
311314 myError . code = 'FHQWHGADS' ;
312315 assert . strictEqual ( myError . code , 'FHQWHGADS' ) ;
313316 assert . strictEqual ( myError . name , initialName ) ;
317+ assert . deepStrictEqual ( Object . keys ( myError ) , [ 'code' ] ) ;
314318 assert . ok ( myError . name . includes ( 'ERR_TLS_HANDSHAKE_TIMEOUT' ) ) ;
315319 assert . ok ( ! myError . name . includes ( 'FHQWHGADS' ) ) ;
316320}
317321
318- // Test that `name` and `message` are mutable and that changing them alters
319- // `toString()` but not ` console.log()` results, which is the behavior of
320- // `Error` objects in the browser .
322+ // Test that `name` is mutable and that changing it alters `toString()` but not
323+ // `console.log()` results, which is the behavior of `Error` objects in the
324+ // browser. Note that `name` becomes enumerable after being assigned .
321325{
322- function test ( prop ) {
323- let initialConsoleLog = '' ;
324- common . hijackStdout ( ( data ) => { initialConsoleLog += data ; } ) ;
325- const myError = new errors . Error ( 'ERR_TLS_HANDSHAKE_TIMEOUT' ) ;
326- const initialToString = myError . toString ( ) ;
327- console . log ( myError ) ;
328- assert . notStrictEqual ( initialConsoleLog , '' ) ;
329-
330- common . restoreStdout ( ) ;
331-
332- let subsequentConsoleLog = '' ;
333- common . hijackStdout ( ( data ) => { subsequentConsoleLog += data ; } ) ;
334- myError [ prop ] = 'Fhqwhgads' ;
335- assert . notStrictEqual ( myError . toString ( ) , initialToString ) ;
336- console . log ( myError ) ;
337- assert . strictEqual ( subsequentConsoleLog , initialConsoleLog ) ;
338-
339- common . restoreStdout ( ) ;
340- }
341-
342- test ( 'name' ) ;
343- test ( 'message' ) ;
326+ const myError = new errors . Error ( 'ERR_TLS_HANDSHAKE_TIMEOUT' ) ;
327+ assert . deepStrictEqual ( Object . keys ( myError ) , [ ] ) ;
328+ const initialToString = myError . toString ( ) ;
329+
330+ myError . name = 'Fhqwhgads' ;
331+ assert . deepStrictEqual ( Object . keys ( myError ) , [ 'name' ] ) ;
332+ assert . notStrictEqual ( myError . toString ( ) , initialToString ) ;
333+ }
334+
335+ // Test that `message` is mutable and that changing it alters `toString()` but
336+ // not `console.log()` results, which is the behavior of `Error` objects in the
337+ // browser. Note that `message` remains non-enumerable after being assigned.
338+ {
339+ let initialConsoleLog = '' ;
340+ common . hijackStdout ( ( data ) => { initialConsoleLog += data ; } ) ;
341+ const myError = new errors . Error ( 'ERR_TLS_HANDSHAKE_TIMEOUT' ) ;
342+ assert . deepStrictEqual ( Object . keys ( myError ) , [ ] ) ;
343+ const initialToString = myError . toString ( ) ;
344+ console . log ( myError ) ;
345+ assert . notStrictEqual ( initialConsoleLog , '' ) ;
346+
347+ common . restoreStdout ( ) ;
348+
349+ let subsequentConsoleLog = '' ;
350+ common . hijackStdout ( ( data ) => { subsequentConsoleLog += data ; } ) ;
351+ myError . message = 'Fhqwhgads' ;
352+ assert . deepStrictEqual ( Object . keys ( myError ) , [ ] ) ;
353+ assert . notStrictEqual ( myError . toString ( ) , initialToString ) ;
354+ console . log ( myError ) ;
355+ assert . strictEqual ( subsequentConsoleLog , initialConsoleLog ) ;
356+
357+ common . restoreStdout ( ) ;
344358}
0 commit comments