Skip to content

Commit df7a67c

Browse files
committed
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.
1 parent 4174b73 commit df7a67c

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lib/internal/assert/assertion_error.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
MathMax,
99
ObjectDefineProperty,
1010
ObjectGetPrototypeOf,
11+
ObjectAssign,
1112
ObjectKeys,
1213
String,
1314
StringPrototypeEndsWith,
@@ -46,11 +47,8 @@ const kReadableOperator = {
4647
const kMaxShortLength = 12;
4748

4849
function copyError(source) {
49-
const keys = ObjectKeys(source);
5050
const target = { __proto__: ObjectGetPrototypeOf(source) };
51-
for (const key of keys) {
52-
target[key] = source[key];
53-
}
51+
ObjectAssign(target, source);
5452
ObjectDefineProperty(target, 'message', { __proto__: null, value: source.message });
5553
return target;
5654
}

0 commit comments

Comments
 (0)