Skip to content

Commit

Permalink
Fixes memory leaks (see brunschgi#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon committed Aug 18, 2016
1 parent 80f6efa commit caa4428
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
21 changes: 21 additions & 0 deletions spec/utilsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ describe('Utils', function () {
expect(Module.foo()).toEqual('foo');
expect(Module.bar).toEqual('bar');
});

it('should deconstruct the module when calling stop', function () {
var Module = T.createModule({
name: 'Foo'
});
var instance = new Module({}, {});
spyOn(T.Module.prototype, 'stop');
instance.stop();
expect(T.Module.prototype.stop).toHaveBeenCalled();
});

it('should always deconstruct the module also if a custom stop function exists', function () {
var Module = T.createModule({
name: 'Foo',
stop: function() {}
});
var instance = new Module({}, {});
spyOn(T.Module.prototype, 'stop');
instance.stop();
expect(T.Module.prototype.stop).toHaveBeenCalled();
});
});
});

13 changes: 12 additions & 1 deletion src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,19 @@ var Utils = {
Utils.extend(Constructor, spec.statics);
}

// Ensure that stop is called even if the spec contains a custom stop function
if (spec.hasOwnProperty('stop')) {
proto.stop = function() {
// Call the spec stop function
spec.stop.apply(this, arguments);
// Call the original stop function
Module.prototype.stop.apply(this, arguments);
};
}

var reservedKeys = [
'statics'
'statics',
'stop'
];

// mixin spec properties to module prototype
Expand Down

0 comments on commit caa4428

Please sign in to comment.