Skip to content

Commit 0d74220

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 0d74220

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

lib/internal/assert/assertion_error.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const {
66
Error,
77
ErrorCaptureStackTrace,
88
MathMax,
9+
ObjectAssign,
910
ObjectDefineProperty,
1011
ObjectGetPrototypeOf,
11-
ObjectKeys,
1212
String,
1313
StringPrototypeEndsWith,
1414
StringPrototypeRepeat,
@@ -46,11 +46,8 @@ const kReadableOperator = {
4646
const kMaxShortLength = 12;
4747

4848
function copyError(source) {
49-
const keys = ObjectKeys(source);
5049
const target = { __proto__: ObjectGetPrototypeOf(source) };
51-
for (const key of keys) {
52-
target[key] = source[key];
53-
}
50+
ObjectAssign(target, source);
5451
ObjectDefineProperty(target, 'message', { __proto__: null, value: source.message });
5552
return target;
5653
}

0 commit comments

Comments
 (0)