lib: optimize copyError with ObjectAssign in primordials
optimized the copyError function by using ObjectAssign from primordials. this change replaces the for-loop with ObjectAssign, which improves memory usage and performance. this change updates the copyError function in internal/assert.js to use ObjectAssign for copying properties. PR-URL: https://github.com/nodejs/node/pull/53999 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
This commit is contained in:
parent
852a1a6742
commit
87e18a7b37
@ -6,9 +6,9 @@ const {
|
||||
Error,
|
||||
ErrorCaptureStackTrace,
|
||||
MathMax,
|
||||
ObjectAssign,
|
||||
ObjectDefineProperty,
|
||||
ObjectGetPrototypeOf,
|
||||
ObjectKeys,
|
||||
String,
|
||||
StringPrototypeEndsWith,
|
||||
StringPrototypeRepeat,
|
||||
@ -46,11 +46,7 @@ const kReadableOperator = {
|
||||
const kMaxShortLength = 12;
|
||||
|
||||
function copyError(source) {
|
||||
const keys = ObjectKeys(source);
|
||||
const target = { __proto__: ObjectGetPrototypeOf(source) };
|
||||
for (const key of keys) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
const target = ObjectAssign({ __proto__: ObjectGetPrototypeOf(source) }, source);
|
||||
ObjectDefineProperty(target, 'message', { __proto__: null, value: source.message });
|
||||
return target;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user