Skip to content
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
5 changes: 4 additions & 1 deletion packages/ember-runtime/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const TYPE_MAP = {
'[object Array]': 'array',
'[object Date]': 'date',
'[object RegExp]': 'regexp',
'[object Object]': 'object'
'[object Object]': 'object',
'[object FileList]': 'filelist'
};

const { toString } = Object.prototype;
Expand Down Expand Up @@ -70,6 +71,7 @@ export function isArray(obj) {
| 'array' | An instance of Array |
| 'regexp' | An instance of RegExp |
| 'date' | An instance of Date |
| 'filelist' | An instance of FileList |
| 'class' | An Ember class (created using Ember.Object.extend()) |
| 'instance' | An Ember object instance |
| 'error' | An instance of the Error object |
Expand All @@ -91,6 +93,7 @@ export function isArray(obj) {
Ember.typeOf([1, 2, 90]); // 'array'
Ember.typeOf(/abc/); // 'regexp'
Ember.typeOf(new Date()); // 'date'
Ember.typeOf(event.target.files); // 'filelist'
Ember.typeOf(Ember.Object.extend()); // 'class'
Ember.typeOf(Ember.Object.create()); // 'instance'
Ember.typeOf(new Error('teamocil')); // 'error'
Expand Down
10 changes: 10 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 '../../utils';
import { A as emberA } from '../../system/native_array';
import ArrayProxy from '../../system/array_proxy';
import { environment } from 'ember-environment';

QUnit.module('Ember Type Checking');

Expand All @@ -26,3 +27,12 @@ QUnit.test('Ember.isArray', function() {
equal(isArray(fn), false, 'function() {}');
equal(isArray(arrayProxy), true, '[]');
});

if (environment.window && typeof environment.window.FileList === 'function') {
QUnit.test('Ember.isArray(fileList)', function() {
let fileListElement = document.createElement('input');
fileListElement.type = 'file';
let fileList = fileListElement.files;
equal(isArray(fileList), false, 'fileList');
});
}
10 changes: 10 additions & 0 deletions packages/ember-runtime/tests/core/type_of_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { typeOf } from '../../utils';
import EmberObject from '../../system/object';
import { environment } from 'ember-environment';

QUnit.module('Ember Type Checking');

Expand Down Expand Up @@ -36,3 +37,12 @@ QUnit.test('Ember.typeOf', function() {
equal(typeOf(EmberObject.extend()), 'class', 'item of type class');
equal(typeOf(new Error()), 'error', 'item of type error');
});

if (environment.window && typeof environment.window.FileList === 'function') {
QUnit.test('Ember.typeOf(fileList)', function() {
let fileListElement = document.createElement('input');
fileListElement.type = 'file';
let fileList = fileListElement.files;
equal(typeOf(fileList), 'filelist', 'item of type filelist');
});
}