Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a memory leak in Error objects #6965

Merged
merged 3 commits into from
Sep 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Fixes

- `[jest-haste-map]` [**BREAKING**] Replaced internal data structures to improve performance ([#6960](https://github.com/facebook/jest/pull/6960))
- `[jest-jasmine2]` Fix memory leak in Error objects hold by the framework ([#6965](https://github.com/facebook/jest/pull/6965))

### Chore & Maintenance

Expand Down
6 changes: 6 additions & 0 deletions packages/jest-jasmine2/src/jasmine/Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export default function Spec(attrs: Object) {
this.initError = new Error();
this.initError.name = '';

// Without this line v8 stores references to all closures
// in the stack in the Error object. This line stringifies the stack
// property to allow garbage-collecting objects on the stack
// https://crbug.com/v8/7142
this.initError.stack = this.initError.stack;

this.queueableFn.initError = this.initError;

this.result = {
Expand Down
12 changes: 12 additions & 0 deletions packages/jest-jasmine2/src/jasmine_async.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ function promisifyLifeCycleFunction(originalFn, env) {

const extraError = new Error();

// Without this line v8 stores references to all closures
// in the stack in the Error object. This line stringifies the stack
// property to allow garbage-collecting objects on the stack
// https://crbug.com/v8/7142
extraError.stack = extraError.stack;

// We make *all* functions async and run `done` right away if they
// didn't return a promise.
const asyncJestLifecycle = function(done) {
Expand Down Expand Up @@ -79,6 +85,12 @@ function promisifyIt(originalFn, env) {

const extraError = new Error();

// Without this line v8 stores references to all closures
// in the stack in the Error object. This line stringifies the stack
// property to allow garbage-collecting objects on the stack
// https://crbug.com/v8/7142
extraError.stack = extraError.stack;

const asyncJestTest = function(done) {
const wrappedFn = isGeneratorFn(fn) ? co.wrap(fn) : fn;
const returnValue = wrappedFn.call({});
Expand Down
1 change: 1 addition & 0 deletions packages/jest-jasmine2/src/queue_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default function queueRunner(options: Options) {
'Timeout - Async callback was not invoked within the ' +
timeoutMs +
'ms timeout specified by jest.setTimeout.';
initError.stack = initError.message + initError.stack;
options.onException(initError);
},
);
Expand Down