Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Fix proto return value for native classes #16551

Merged
merged 1 commit into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/ember-runtime/lib/system/core_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ function makeCtor(base) {
};
}

Class.willReopen = () => {
Class.willReopen = function() {
if (wasApplied) {
Class.PrototypeMixin = Mixin.create(Class.PrototypeMixin);
}

wasApplied = false;
};

Class.proto = () => {
Class.proto = function() {
let superclass = Class.superclass;
if (superclass) {
superclass.proto();
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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');
}
}
);