Skip to content

Commit

Permalink
Merge pull request #16526 from rwjblue/avoid-erroring-for-name-key
Browse files Browse the repository at this point in the history
[BUGFIX beta] Ensure setting a `NAME_KEY` does not error.
  • Loading branch information
rwjblue authored Apr 16, 2018
2 parents 9324e62 + 76689ea commit 77050a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/ember-metal/lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@module @ember/object
*/
import { EMBER_METAL_ES5_GETTERS } from 'ember/features';
import { assign, guidFor, ROOT, wrap, makeArray } from 'ember-utils';
import { assign, guidFor, ROOT, wrap, makeArray, NAME_KEY } from 'ember-utils';
import { assert } from 'ember-debug';
import { DEBUG } from 'ember-env-flags';
import { ENV } from 'ember-environment';
Expand Down Expand Up @@ -449,6 +449,7 @@ export default class Mixin {
this._without = undefined;

if (DEBUG) {
this[NAME_KEY] = undefined;
/*
In debug builds, we seal mixins to help avoid performance pitfalls.
Expand Down Expand Up @@ -609,6 +610,7 @@ if (ENV._ENABLE_BINDING_SUPPORT) {
Mixin.prototype.toString = classToString;

if (DEBUG) {
Mixin.prototype[NAME_KEY] = undefined;
Object.seal(Mixin.prototype);
}

Expand Down
15 changes: 14 additions & 1 deletion packages/ember-metal/tests/mixin/introspection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// as well as methods vs props. We are just keeping these for testing; the
// current impl doesn't care about the differences as much...

import { guidFor } from 'ember-utils';
import { guidFor, NAME_KEY } from 'ember-utils';
import { mixin, Mixin } from '../..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

Expand Down Expand Up @@ -58,5 +58,18 @@ moduleFor(
'should return included mixins'
);
}

['@test setting a NAME_KEY on a mixin does not error'](assert) {
assert.expect(0);

let instance = Mixin.create();
instance[NAME_KEY] = 'My special name!';
}

['@test setting a NAME_KEY on a mixin instance does not error'](assert) {
assert.expect(0);

Mixin.create({ [NAME_KEY]: 'My special name' });
}
}
);

0 comments on commit 77050a8

Please sign in to comment.