diff --git a/packages/ember-runtime/lib/system/core_object.js b/packages/ember-runtime/lib/system/core_object.js index ed4273fa096..1c0e75ab4ab 100644 --- a/packages/ember-runtime/lib/system/core_object.js +++ b/packages/ember-runtime/lib/system/core_object.js @@ -241,7 +241,7 @@ function makeCtor(base) { }; } - Class.willReopen = () => { + Class.willReopen = function() { if (wasApplied) { Class.PrototypeMixin = Mixin.create(Class.PrototypeMixin); } @@ -249,7 +249,7 @@ function makeCtor(base) { wasApplied = false; }; - Class.proto = () => { + Class.proto = function() { let superclass = Class.superclass; if (superclass) { superclass.proto(); @@ -260,7 +260,10 @@ function makeCtor(base) { Class.PrototypeMixin.applyPartial(Class.prototype); } - return Class.prototype; + // Native classes will call the nearest superclass's proto function, + // and proto is expected to return the current instance's prototype, + // so we need to return it from `this` instead + return this.prototype; }; return Class; diff --git a/packages/ember-runtime/tests/system/object/es-compatibility-test.js b/packages/ember-runtime/tests/system/object/es-compatibility-test.js index 182e023cdcf..0d3c74bf671 100644 --- a/packages/ember-runtime/tests/system/object/es-compatibility-test.js +++ b/packages/ember-runtime/tests/system/object/es-compatibility-test.js @@ -1,5 +1,5 @@ import EmberObject from '../../../lib/system/object'; -import { Mixin } from 'ember-metal'; +import { Mixin, defineProperty, computed } from 'ember-metal'; import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; moduleFor( @@ -277,5 +277,24 @@ moduleFor( assert.equal(obj.foo, 123, 'sets class fields on instance correctly'); assert.equal(obj.bar, 789, 'sets passed in properties on instance correctly'); } + + ['@test calling metaForProperty on a native class works'](assert) { + assert.expect(0); + + class SubEmberObject extends EmberObject {} + + defineProperty( + SubEmberObject.prototype, + 'foo', + computed('foo', { + get() { + return 'bar'; + }, + }) + ); + + // able to get meta without throwing an error + SubEmberObject.metaForProperty('foo'); + } } );