Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Aug 9, 2022
1 parent 0d4af69 commit 1058218
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/internal/assert/calltracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

const {
ArrayPrototypePush,
ArrayPrototypeSlice,
Error,
FunctionPrototype,
ObjectFreeze,
Proxy,
ReflectApply,
SafeSet,
Expand Down Expand Up @@ -36,7 +38,8 @@ class CallTrackerContext {
}

track(thisArg, args) {
ArrayPrototypePush(this.#calls, { thisArg, arguments: args });
args = ObjectFreeze(ArrayPrototypeSlice(args));
ArrayPrototypePush(this.#calls, ObjectFreeze({ thisArg, arguments: args }));
}

get delta() {
Expand All @@ -47,7 +50,7 @@ class CallTrackerContext {
this.#calls = [];
}
getCalls() {
return this.#calls;
return ObjectFreeze(ArrayPrototypeSlice(this.#calls));
}

report() {
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-assert-calltracker-getCalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ describe('assert.CallTracker.getCalls()', { concurrency: true }, () => {
assert.throws(() => tracker.getCalls(fn), { code: 'ERR_INVALID_ARG_VALUE' });
});
});

it('should return a frozen object', () => {
const fn = tracker.calls();
fn();
const calls = tracker.getCalls(fn);
assert.throws(() => calls.push(1), /object is not extensible/);
assert.throws(() => Object.assign(calls[0], { foo: 'bar' }), /object is not extensible/);
assert.throws(() => calls[0].arguments.push(1), /object is not extensible/);
});
});

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

0 comments on commit 1058218

Please sign in to comment.