Skip to content

Commit

Permalink
Merge pull request #16564 from rwjblue/is-array-proxy
Browse files Browse the repository at this point in the history
[BUGFIX release] Ensure Ember.isArray does not trigger proxy assertion.
  • Loading branch information
rwjblue authored Apr 21, 2018
2 parents c3bc302 + 74039e7 commit 2773a26
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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

0 comments on commit 2773a26

Please sign in to comment.