Skip to content

Commit

Permalink
Merge pull request #16270 from hjdivad/hjdivad/es5-getters-return-raw…
Browse files Browse the repository at this point in the history
…-descriptors

ES5 getters return raw descriptors
  • Loading branch information
rwjblue authored Feb 28, 2018
2 parents e0d4b3f + 95b47f6 commit 8ef8dc6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/ember-metal/lib/property_get.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@module @ember/object
*/

import { assert } from 'ember-debug';
import { assert, deprecate } from 'ember-debug';
import { HAS_NATIVE_PROXY, symbol } from 'ember-utils';
import { DESCRIPTOR_TRAP, EMBER_METAL_ES5_GETTERS, MANDATORY_GETTER } from 'ember/features';
import { isPath } from './path_cache';
Expand Down Expand Up @@ -96,6 +96,15 @@ export function get(obj, keyName) {
if (DESCRIPTOR_TRAP && isDescriptorTrap(value)) {
descriptor = value[DESCRIPTOR];
} else if (isDescriptor(value)) {
deprecate(
`[DEPRECATED] computed property '${keyName}' was not set on object '${obj && obj.toString && obj.toString()}' via 'defineProperty'`,
!EMBER_METAL_ES5_GETTERS,
{
id: 'ember-meta.descriptor-on-object',
until: '3.5.0',
url: 'https://emberjs.com/deprecations/v3.x#toc_use-defineProperty-to-define-computed-properties'
}
);
descriptor = value;
}
}
Expand Down
17 changes: 17 additions & 0 deletions packages/ember-metal/tests/accessors/get_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getWithDefault,
Mixin,
observer,
computed,
} from '../..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

Expand All @@ -27,6 +28,22 @@ moduleFor('get', class extends AbstractTestCase {
}
}

['@test implicitly computing the values of descriptors on properties is deprecated'](assert) {
let cp = computed(() => 'value');
let obj = {
cp,
toString() { return 'myobject'; }
};

let result;

expectDeprecation(() => {
result = get(obj, 'cp');
}, /\[DEPRECATED\] computed property 'cp' was not set on object 'myobject' via 'defineProperty'/);

assert.equal(result, 'value', 'descriptor');
}

['@test should retrieve a number key on an object'](assert) {
let obj = { 1: 'first' };

Expand Down

0 comments on commit 8ef8dc6

Please sign in to comment.