Skip to content

Commit 1058218

Browse files
committed
CR
1 parent 0d4af69 commit 1058218

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/internal/assert/calltracker.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
const {
44
ArrayPrototypePush,
5+
ArrayPrototypeSlice,
56
Error,
67
FunctionPrototype,
8+
ObjectFreeze,
79
Proxy,
810
ReflectApply,
911
SafeSet,
@@ -36,7 +38,8 @@ class CallTrackerContext {
3638
}
3739

3840
track(thisArg, args) {
39-
ArrayPrototypePush(this.#calls, { thisArg, arguments: args });
41+
args = ObjectFreeze(ArrayPrototypeSlice(args));
42+
ArrayPrototypePush(this.#calls, ObjectFreeze({ thisArg, arguments: args }));
4043
}
4144

4245
get delta() {
@@ -47,7 +50,7 @@ class CallTrackerContext {
4750
this.#calls = [];
4851
}
4952
getCalls() {
50-
return this.#calls;
53+
return ObjectFreeze(ArrayPrototypeSlice(this.#calls));
5154
}
5255

5356
report() {

test/parallel/test-assert-calltracker-getCalls.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ describe('assert.CallTracker.getCalls()', { concurrency: true }, () => {
2828
assert.throws(() => tracker.getCalls(fn), { code: 'ERR_INVALID_ARG_VALUE' });
2929
});
3030
});
31+
32+
it('should return a frozen object', () => {
33+
const fn = tracker.calls();
34+
fn();
35+
const calls = tracker.getCalls(fn);
36+
assert.throws(() => calls.push(1), /object is not extensible/);
37+
assert.throws(() => Object.assign(calls[0], { foo: 'bar' }), /object is not extensible/);
38+
assert.throws(() => calls[0].arguments.push(1), /object is not extensible/);
39+
});
3140
});
3241

3342
describe('assert.CallTracker.reset()', () => {

0 commit comments

Comments
 (0)