@@ -20,7 +20,6 @@ const {
2020 NumberIsNaN,
2121 NumberMAX_SAFE_INTEGER,
2222 NumberMIN_SAFE_INTEGER,
23- ObjectAssign,
2423 ObjectPrototypeIsPrototypeOf,
2524 SafeSet,
2625 String,
@@ -30,7 +29,7 @@ const {
3029 TypedArrayPrototypeGetSymbolToStringTag,
3130} = primordials ;
3231
33- const { kEmptyObject } = require ( 'internal/util' ) ;
32+ const { kEmptyObject, setOwnProperty } = require ( 'internal/util' ) ;
3433const {
3534 isSharedArrayBuffer,
3635 isTypedArray,
@@ -81,15 +80,15 @@ const converters = { __proto__: null };
8180 */
8281
8382/**
84- * Creates a TypeError and assigns Node.js error properties to it .
83+ * Creates a TypeError with a Node.js error code .
8584 * @param {string } message Error message.
86- * @param {object } [errorProperties] Properties assigned to the error .
85+ * @param {string } code Node.js error code to assign .
8786 * @returns {TypeError }
8887 */
89- function codedTypeError ( message , errorProperties = kEmptyObject ) {
88+ function codedTypeError ( message , code ) {
9089 // eslint-disable-next-line no-restricted-syntax
9190 const err = new TypeError ( message ) ;
92- ObjectAssign ( err , errorProperties ) ;
91+ setOwnProperty ( err , 'code' , code ) ;
9392 return err ;
9493}
9594
@@ -105,7 +104,7 @@ function makeException(message, options = kEmptyObject) {
105104 '' : ( options . context ?? 'Value' ) + ' ' ;
106105 return codedTypeError (
107106 `${ prefix } ${ context } ${ message } ` ,
108- { code : options . code || 'ERR_INVALID_ARG_TYPE' } ,
107+ options . code || 'ERR_INVALID_ARG_TYPE' ,
109108 ) ;
110109}
111110
0 commit comments