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] Ensures Ember.A is a constructor #17238

Merged
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
28 changes: 26 additions & 2 deletions packages/@ember/-internals/runtime/lib/mixins/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -1641,12 +1641,36 @@ let A;

if (ENV.EXTEND_PROTOTYPES.Array) {
NativeArray.apply(Array.prototype);
A = arr => arr || [];

A = function(arr) {
deprecate(
'`new A()` has been deprecated, please update to calling A as a function: `A()`',
!(this instanceof A),
{
id: 'array.new-array-wrapper',
until: '3.9.0',
url: 'https://emberjs.com/deprecations/v3.x#toc_array-new-array-wrapper',
}
);

return arr || [];
};
} else {
A = arr => {
A = function(arr) {
deprecate(
'`new A()` has been deprecated, please update to calling A as a function: `A()`',
!(this instanceof A),
{
id: 'array.new-array-wrapper',
until: '3.9.0',
url: 'https://emberjs.com/deprecations/v3.x#toc_array-new-array-wrapper',
}
);

if (!arr) {
arr = [];
}

return ArrayMixin.detect(arr) ? arr : NativeArray.apply(arr);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,15 @@ moduleFor(
assert.ok(EmberArray.detect(A()), 'returned an ember array');
assert.ok(EmberArray.detect(A([1, 2])), 'returned an ember array');
}

['@test new Ember.A'](assert) {
expectDeprecation(() => {
assert.deepEqual(new A([1, 2]), [1, 2], 'array values were not be modified');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya, woah this was never an intended feature...

assert.deepEqual(new A(), [], 'returned an array with no arguments');
assert.deepEqual(new A(null), [], 'returned an array with a null argument');
assert.ok(EmberArray.detect(new A()), 'returned an ember array');
assert.ok(EmberArray.detect(new A([1, 2])), 'returned an ember array');
});
}
}
);