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 release] Ensure Ember.isArray does not trigger proxy assertion. #16564

Merged
merged 1 commit into from
Apr 21, 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
13 changes: 12 additions & 1 deletion packages/ember-runtime/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { DEBUG } from '@glimmer/env';
import { PROXY_CONTENT } from 'ember-metal';
import { HAS_NATIVE_PROXY } from 'ember-utils';
import EmberArray from './mixins/array';
import EmberObject from './system/object';

Expand Down Expand Up @@ -48,7 +51,15 @@ const { toString } = Object.prototype;
@return {Boolean} true if the passed object is an array or Array-like
@public
*/
export function isArray(obj) {
export function isArray(_obj) {
let obj = _obj;
if (DEBUG && HAS_NATIVE_PROXY && typeof _obj === 'object' && _obj !== null) {
let possibleProxyContent = _obj[PROXY_CONTENT];
if (possibleProxyContent !== undefined) {
obj = possibleProxyContent;
}
}

if (!obj || obj.setInterval) {
return false;
}
Expand Down
14 changes: 14 additions & 0 deletions packages/ember-runtime/tests/core/is_array_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isArray } from '../../lib/utils';
import { A as emberA } from '../../lib/mixins/array';
import ArrayProxy from '../../lib/system/array_proxy';
import EmberObject from '../../lib/system/object';
import { window } from 'ember-browser-environment';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

Expand Down Expand Up @@ -32,6 +33,19 @@ moduleFor(
assert.equal(isArray(arrayProxy), true, '[]');
}

'@test Ember.isArray does not trigger proxy assertion when probing for length GH#16495'(
assert
) {
let instance = EmberObject.extend({
// intentionally returning non-null / non-undefined
unknownProperty() {
return false;
},
}).create();

assert.equal(isArray(instance), false);
}

['@test Ember.isArray(fileList)'](assert) {
if (window && typeof window.FileList === 'function') {
let fileListElement = document.createElement('input');
Expand Down