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

[BUGFIX release] fix the leaks #11832

Merged
merged 2 commits into from
Jul 21, 2015
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
6 changes: 5 additions & 1 deletion packages/ember-application/lib/system/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import LegacyEachView from 'ember-views/views/legacy_each_view';
import LinkToComponent from 'ember-routing-views/views/link';
import RoutingService from 'ember-routing/services/routing';
import ContainerDebugAdapter from 'ember-extension-support/container_debug_adapter';

import { _loaded } from 'ember-runtime/system/lazy_load';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at first glance this does seem strange import { _blah } I looked at the definition and don't know whether this is private just am assuming that the underscore prefix means private.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all modules are currently private, as they are not exposed.

import environment from 'ember-metal/environment';

function props(obj) {
Expand Down Expand Up @@ -772,6 +772,10 @@ var Application = Namespace.extend({
this._bootPromise = null;
this._bootResolver = null;

if (_loaded.application === this) {
_loaded.application = undefined;
}

if (this.__deprecatedInstance__) {
this.__deprecatedInstance__.destroy();
}
Expand Down
9 changes: 9 additions & 0 deletions packages/ember-application/tests/system/application_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import EmberObject from 'ember-runtime/system/object';
import EmberRoute from 'ember-routing/system/route';
import jQuery from 'ember-views/system/jquery';
import compile from 'ember-template-compiler/system/compile';
import { _loaded } from 'ember-runtime/system/lazy_load';

var trim = jQuery.trim;

Expand Down Expand Up @@ -332,3 +333,11 @@ QUnit.test('registers controls onto to container', function() {

ok(app.__container__.lookup('view:select'), 'Select control is registered into views');
});

QUnit.test('does not leak itself in onLoad._loaded', function() {
equal(_loaded.application, undefined);
var app = run(Application, 'create');
equal(_loaded.application, app);
run(app, 'destroy');
equal(_loaded.application, undefined);
});
5 changes: 3 additions & 2 deletions packages/ember-runtime/lib/system/lazy_load.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'ember-runtime/system/native_array'; // make sure Ember.A is setup.

var loadHooks = Ember.ENV.EMBER_LOAD_HOOKS || {};
var loaded = {};
export var _loaded = loaded;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really private? It's exported. I know JS doesn't really have 'protected' but am wondering if you can add a doc block on the export for _loaded What is this? private / public etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undocumented is private and our modules are not exposed by any public means, once they are a different facade will be exposed that enables 100% public only public API.


/**
Detects when a specific package of Ember (e.g. 'Ember.Application')
Expand All @@ -31,12 +32,12 @@ var loaded = {};
@private
*/
export function onLoad(name, callback) {
var object;
var object = loaded[name];

loadHooks[name] = loadHooks[name] || Ember.A();
loadHooks[name].pushObject(callback);

if (object = loaded[name]) {
if (object) {
callback(object);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/ember-testing/lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ EmberApplication.reopen({

for (var name in helpers) {
this.helperContainer[name] = this.originalMethods[name];
delete Test.Promise.prototype[name];
delete this.testHelpers[name];
delete this.originalMethods[name];
}
Expand Down
11 changes: 11 additions & 0 deletions packages/ember-testing/tests/helpers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,28 @@ QUnit.module('ember-testing: Helper setup', {
teardown() { cleanup(); }
});

function registerHelper() {
Test.registerHelper('LeakyMcLeakLeak', function(app) {
});
}

QUnit.test('Ember.Application#injectTestHelpers/#removeTestHelpers', function() {
App = run(EmberApplication, EmberApplication.create);
assertNoHelpers(App);

registerHelper();

App.injectTestHelpers();
assertHelpers(App);
ok(Ember.Test.Promise.prototype.LeakyMcLeakLeak, 'helper in question SHOULD be present');

App.removeTestHelpers();
assertNoHelpers(App);

equal(Ember.Test.Promise.prototype.LeakyMcLeakLeak, undefined, 'should NOT leak test promise extensions');
});


QUnit.test('Ember.Application#setupForTesting', function() {
run(function() {
App = EmberApplication.create();
Expand Down