diff --git a/packages/ember-runtime/lib/mixins/array.js b/packages/ember-runtime/lib/mixins/array.js index a2a01b37015..172afd719e4 100644 --- a/packages/ember-runtime/lib/mixins/array.js +++ b/packages/ember-runtime/lib/mixins/array.js @@ -205,7 +205,7 @@ export default Mixin.create(Enumerable, { firstObject: computed(function() { return objectAt(this, 0); - }), + }).readOnly(), lastObject: computed(function() { return objectAt(this, get(this, 'length') - 1); diff --git a/packages/ember-runtime/lib/mixins/enumerable.js b/packages/ember-runtime/lib/mixins/enumerable.js index e8b9a8b9ee5..6be73a26f82 100644 --- a/packages/ember-runtime/lib/mixins/enumerable.js +++ b/packages/ember-runtime/lib/mixins/enumerable.js @@ -153,6 +153,7 @@ export default Mixin.create({ @property firstObject @return {Object} the object or undefined + @readOnly @public */ firstObject: computed('[]', function() { @@ -167,7 +168,7 @@ export default Mixin.create({ pushCtx(context); return ret; - }), + }).readOnly(), /** Helper method returns the last object from a collection. If your enumerable diff --git a/packages/ember-runtime/tests/suites/enumerable/firstObject.js b/packages/ember-runtime/tests/suites/enumerable/firstObject.js index 28372de5c7b..822d4be1aed 100644 --- a/packages/ember-runtime/tests/suites/enumerable/firstObject.js +++ b/packages/ember-runtime/tests/suites/enumerable/firstObject.js @@ -1,5 +1,6 @@ import {SuiteModuleBuilder} from 'ember-runtime/tests/suites/suite'; import {get} from 'ember-metal/property_get'; +import {set} from 'ember-metal/property_set'; var suite = SuiteModuleBuilder.create(); @@ -15,4 +16,14 @@ suite.test('returns undefined if enumerable is empty', function() { equal(get(obj, 'firstObject'), undefined); }); +suite.test('can not be set', function() { + var obj = this.newObject([]); + + equal(get(obj, 'firstObject'), this.toArray(obj)[0]); + + throws(function() { + set(obj, 'firstObject', 'foo!'); + }, /Cannot set read-only property "firstObject" on object/); +}); + export default suite;