Skip to content

Commit

Permalink
[BUGFIX release] Fix mergedProperties at create time modifying proto
Browse files Browse the repository at this point in the history
When `mergedProperties` are passed into an object at `.create()` time,
the objects prototype is inadvertently modified, which is then
reflected on all instances of the object. Simply passing in a new
object during `assign()` resolves this problem (per krisselden). Also
added a test for this use case, where `objA` results in 3 when the
proto is modified. Fixes #11714
  • Loading branch information
Panman82 committed Mar 2, 2016
1 parent 036ff2f commit fa87517
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions packages/ember-metal/tests/mixin/merged_properties_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,29 @@ QUnit.test('mergedProperties should exist even if not explicitly set on create',
equal(get(obj, 'options').b.c, 'ccc');
});

QUnit.test('defining mergedProperties at create time should not modify the prototype', function() {
var AnObj = EmberObject.extend({
mergedProperties: ['options'],
options: {
a: 1
}
});

var objA = AnObj.create({
options: {
a: 2
}
});
var objB = AnObj.create({
options: {
a: 3
}
});

equal(get(objA, 'options').a, 2);
equal(get(objB, 'options').a, 3);
});

QUnit.test('mergedProperties\' overwriting methods can call _super', function() {
expect(4);

Expand Down
2 changes: 1 addition & 1 deletion packages/ember-runtime/lib/system/core_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function makeCtor() {
mergedProperties.indexOf(keyName) >= 0) {
var originalValue = this[keyName];

value = assign(originalValue, value);
value = assign({}, originalValue, value);
}

if (desc) {
Expand Down

0 comments on commit fa87517

Please sign in to comment.