From fa8751770ff707f38770a36193c761f5226b41d2 Mon Sep 17 00:00:00 2001 From: Ryan Panning Date: Tue, 1 Mar 2016 10:38:32 -0600 Subject: [PATCH] [BUGFIX release] Fix mergedProperties at create time modifying proto 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 --- .../tests/mixin/merged_properties_test.js | 23 +++++++++++++++++++ .../ember-runtime/lib/system/core_object.js | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/ember-metal/tests/mixin/merged_properties_test.js b/packages/ember-metal/tests/mixin/merged_properties_test.js index c5c3d1648ad..efa0820103d 100644 --- a/packages/ember-metal/tests/mixin/merged_properties_test.js +++ b/packages/ember-metal/tests/mixin/merged_properties_test.js @@ -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); diff --git a/packages/ember-runtime/lib/system/core_object.js b/packages/ember-runtime/lib/system/core_object.js index 59e2ddab434..6607db0da2c 100644 --- a/packages/ember-runtime/lib/system/core_object.js +++ b/packages/ember-runtime/lib/system/core_object.js @@ -147,7 +147,7 @@ function makeCtor() { mergedProperties.indexOf(keyName) >= 0) { var originalValue = this[keyName]; - value = assign(originalValue, value); + value = assign({}, originalValue, value); } if (desc) {