diff --git a/packages/ember-application/tests/system/dependency_injection/normalization_test.js b/packages/ember-application/tests/system/dependency_injection/normalization_test.js index 296e59c28db..0b0d5f49114 100644 --- a/packages/ember-application/tests/system/dependency_injection/normalization_test.js +++ b/packages/ember-application/tests/system/dependency_injection/normalization_test.js @@ -1,5 +1,4 @@ import run from "ember-metal/run_loop"; -import { forEach } from "ember-metal/array"; import Application from "ember-application/system/application"; var application, registry; @@ -38,7 +37,7 @@ QUnit.test('normalization', function() { QUnit.test('normalization is indempotent', function() { var examples = ['controller:posts', 'controller:posts.post.index', 'controller:blog/posts.post_index', 'template:foo_bar']; - forEach.call(examples, function (example) { + examples.forEach((example) => { equal(registry.normalize(registry.normalize(example)), registry.normalize(example)); }); }); diff --git a/packages/ember-application/tests/system/initializers_test.js b/packages/ember-application/tests/system/initializers_test.js index c5f99a03351..4cba01d9553 100644 --- a/packages/ember-application/tests/system/initializers_test.js +++ b/packages/ember-application/tests/system/initializers_test.js @@ -1,7 +1,6 @@ import isEnabled from "ember-metal/features"; import run from "ember-metal/run_loop"; import Application from "ember-application/system/application"; -import { indexOf } from "ember-metal/array"; import jQuery from "ember-views/system/jquery"; import Registry from "container/registry"; @@ -228,10 +227,10 @@ QUnit.test("initializers can have multiple dependencies", function () { }); }); - ok(indexOf.call(order, a.name) < indexOf.call(order, b.name), 'a < b'); - ok(indexOf.call(order, b.name) < indexOf.call(order, c.name), 'b < c'); - ok(indexOf.call(order, b.name) < indexOf.call(order, afterB.name), 'b < afterB'); - ok(indexOf.call(order, c.name) < indexOf.call(order, afterC.name), 'c < afterC'); + ok(order.indexOf(a.name) < order.indexOf(b.name), 'a < b'); + ok(order.indexOf(b.name) < order.indexOf(c.name), 'b < c'); + ok(order.indexOf(b.name) < order.indexOf(afterB.name), 'b < afterB'); + ok(order.indexOf(c.name) < order.indexOf(afterC.name), 'c < afterC'); }); QUnit.test("initializers set on Application subclasses should not be shared between apps", function() { diff --git a/packages/ember-application/tests/system/instance_initializers_test.js b/packages/ember-application/tests/system/instance_initializers_test.js index 2877d800be8..5f7fbeee12f 100644 --- a/packages/ember-application/tests/system/instance_initializers_test.js +++ b/packages/ember-application/tests/system/instance_initializers_test.js @@ -2,7 +2,6 @@ import isEnabled from "ember-metal/features"; import run from "ember-metal/run_loop"; import Application from "ember-application/system/application"; import ApplicationInstance from "ember-application/system/application-instance"; -import { indexOf } from "ember-metal/array"; import jQuery from "ember-views/system/jquery"; var app, initializeContextFeatureEnabled; @@ -232,10 +231,10 @@ if (isEnabled('ember-application-instance-initializers')) { }); }); - ok(indexOf.call(order, a.name) < indexOf.call(order, b.name), 'a < b'); - ok(indexOf.call(order, b.name) < indexOf.call(order, c.name), 'b < c'); - ok(indexOf.call(order, b.name) < indexOf.call(order, afterB.name), 'b < afterB'); - ok(indexOf.call(order, c.name) < indexOf.call(order, afterC.name), 'c < afterC'); + ok(order.indexOf(a.name) < order.indexOf(b.name), 'a < b'); + ok(order.indexOf(b.name) < order.indexOf(c.name), 'b < c'); + ok(order.indexOf(b.name) < order.indexOf(afterB.name), 'b < afterB'); + ok(order.indexOf(c.name) < order.indexOf(afterC.name), 'c < afterC'); }); QUnit.test("initializers set on Application subclasses should not be shared between apps", function() { diff --git a/packages/ember-metal/lib/array.js b/packages/ember-metal/lib/array.js deleted file mode 100644 index 4b29b1d80a2..00000000000 --- a/packages/ember-metal/lib/array.js +++ /dev/null @@ -1,135 +0,0 @@ -/** -@module ember -@submodule ember-metal -*/ - -var ArrayPrototype = Array.prototype; - -// Testing this is not ideal, but we want to use native functions -// if available, but not to use versions created by libraries like Prototype -var isNativeFunc = function(func) { - // This should probably work in all browsers likely to have ES5 array methods - return func && Function.prototype.toString.call(func).indexOf('[native code]') > -1; -}; - -var defineNativeShim = function(nativeFunc, shim) { - if (isNativeFunc(nativeFunc)) { - return nativeFunc; - } - return shim; -}; - -// From: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/map -var map = defineNativeShim(ArrayPrototype.map, function(fun, ...thisp) { - //"use strict"; - - if (this === void 0 || this === null || typeof fun !== "function") { - throw new TypeError(); - } - - var t = Object(this); - var len = t.length >>> 0; - var res = new Array(len); - - for (var i = 0; i < len; i++) { - if (i in t) { - res[i] = fun.call(thisp[0], t[i], i, t); - } - } - - return res; -}); - -// From: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/foreach -var forEach = defineNativeShim(ArrayPrototype.forEach, function(fun, ...thisp) { - //"use strict"; - - if (this === void 0 || this === null || typeof fun !== "function") { - throw new TypeError(); - } - - var t = Object(this); - var len = t.length >>> 0; - - for (var i = 0; i < len; i++) { - if (i in t) { - fun.call(thisp[0], t[i], i, t); - } - } -}); - -var indexOf = defineNativeShim(ArrayPrototype.indexOf, function(obj, fromIndex) { - if (fromIndex === null || fromIndex === undefined) { - fromIndex = 0; - } else if (fromIndex < 0) { - fromIndex = Math.max(0, this.length + fromIndex); - } - - for (var i = fromIndex, j = this.length; i < j; i++) { - if (this[i] === obj) { - return i; - } - } - return -1; -}); - -var lastIndexOf = defineNativeShim(ArrayPrototype.lastIndexOf, function(obj, fromIndex) { - var len = this.length; - var idx; - - if (fromIndex === undefined) { - fromIndex = len-1; - } else { - fromIndex = (fromIndex < 0) ? Math.ceil(fromIndex) : Math.floor(fromIndex); - } - - if (fromIndex < 0) { - fromIndex += len; - } - - for (idx = fromIndex; idx >= 0; idx--) { - if (this[idx] === obj) { - return idx; - } - } - return -1; -}); - -var filter = defineNativeShim(ArrayPrototype.filter, function(fn, context) { - var i, value; - var result = []; - var length = this.length; - - for (i = 0; i < length; i++) { - if (this.hasOwnProperty(i)) { - value = this[i]; - if (fn.call(context, value, i, this)) { - result.push(value); - } - } - } - return result; -}); - -if (Ember.SHIM_ES5) { - ArrayPrototype.map = ArrayPrototype.map || map; - ArrayPrototype.forEach = ArrayPrototype.forEach || forEach; - ArrayPrototype.filter = ArrayPrototype.filter || filter; - ArrayPrototype.indexOf = ArrayPrototype.indexOf || indexOf; - ArrayPrototype.lastIndexOf = ArrayPrototype.lastIndexOf || lastIndexOf; -} - -/** - Array polyfills to support ES5 features in older browsers. - - @namespace Ember - @property ArrayPolyfills - @public -*/ -export { - map, - forEach, - filter, - indexOf, - lastIndexOf -}; diff --git a/packages/ember-metal/lib/chains.js b/packages/ember-metal/lib/chains.js index 52b8ed422fe..71ca01b1577 100644 --- a/packages/ember-metal/lib/chains.js +++ b/packages/ember-metal/lib/chains.js @@ -1,7 +1,6 @@ import Ember from "ember-metal/core"; // warn, assert, etc; import { get, normalizeTuple } from "ember-metal/property_get"; import { meta as metaFor } from "ember-metal/utils"; -import { forEach } from "ember-metal/array"; import { watchKey, unwatchKey } from "ember-metal/watch_key"; var warn = Ember.warn; @@ -32,9 +31,7 @@ export function flushPendingChains() { var queue = pendingQueue; pendingQueue = []; - forEach.call(queue, (q) => { - q[0].add(q[1]); - }); + queue.forEach((q) => q[0].add(q[1])); warn('Watching an undefined global, Ember expects watched globals to be' + ' setup by the time the run loop is flushed, check for typos', pendingQueue.length === 0); diff --git a/packages/ember-metal/lib/expand_properties.js b/packages/ember-metal/lib/expand_properties.js index 28045b053ef..391a73952e6 100644 --- a/packages/ember-metal/lib/expand_properties.js +++ b/packages/ember-metal/lib/expand_properties.js @@ -1,5 +1,4 @@ import EmberError from 'ember-metal/error'; -import { forEach } from 'ember-metal/array'; /** @module ember @@ -43,13 +42,13 @@ export default function expandProperties(pattern, callback) { var parts = pattern.split(SPLIT_REGEX); var properties = [parts]; - forEach.call(parts, function(part, index) { + parts.forEach((part, index) => { if (part.indexOf(',') >= 0) { properties = duplicateAndReplace(properties, part.split(','), index); } }); - forEach.call(properties, function(property) { + properties.forEach((property) => { callback(property.join('')); }); } else { @@ -60,8 +59,8 @@ export default function expandProperties(pattern, callback) { function duplicateAndReplace(properties, currentParts, index) { var all = []; - forEach.call(properties, (property) => { - forEach.call(currentParts, (part) => { + properties.forEach((property) => { + currentParts.forEach((part) => { var current = property.slice(0); current[index] = part; all.push(current); diff --git a/packages/ember-metal/lib/main.js b/packages/ember-metal/lib/main.js index 0e82ebacacc..e192b500384 100644 --- a/packages/ember-metal/lib/main.js +++ b/packages/ember-metal/lib/main.js @@ -40,12 +40,6 @@ import { hasPropertyAccessors } from 'ember-metal/platform/define_property'; import create from 'ember-metal/platform/create'; -import { - filter, - forEach, - indexOf, - map -} from "ember-metal/array"; import Logger from "ember-metal/logger"; import { @@ -241,13 +235,6 @@ Ember.platform = { hasPropertyAccessors: hasPropertyAccessors }; -var EmberArrayPolyfills = Ember.ArrayPolyfills = {}; - -EmberArrayPolyfills.map = map; -EmberArrayPolyfills.forEach = forEach; -EmberArrayPolyfills.filter = filter; -EmberArrayPolyfills.indexOf = indexOf; - Ember.Error = EmberError; Ember.guidFor = guidFor; Ember.META_DESC = META_DESC; diff --git a/packages/ember-metal/lib/map.js b/packages/ember-metal/lib/map.js index 2f2239a7490..02f25ce6a22 100644 --- a/packages/ember-metal/lib/map.js +++ b/packages/ember-metal/lib/map.js @@ -22,7 +22,6 @@ */ import { guidFor } from "ember-metal/utils"; -import { indexOf } from "ember-metal/array"; import create from "ember-metal/platform/create"; import { deprecateProperty } from "ember-metal/deprecate_property"; @@ -150,7 +149,7 @@ OrderedSet.prototype = { if (presenceSet[guid] === true) { delete presenceSet[guid]; - var index = indexOf.call(list, obj); + var index = list.indexOf(obj); if (index > -1) { list.splice(index, 1); } diff --git a/packages/ember-metal/lib/mixin.js b/packages/ember-metal/lib/mixin.js index 21e24c16a52..f40d00dddbc 100644 --- a/packages/ember-metal/lib/mixin.js +++ b/packages/ember-metal/lib/mixin.js @@ -10,10 +10,6 @@ import Ember from "ember-metal/core"; // warn, assert, wrap, et; import merge from "ember-metal/merge"; -import { - indexOf as a_indexOf, - forEach as a_forEach -} from "ember-metal/array"; import o_create from "ember-metal/platform/create"; import { get } from "ember-metal/property_get"; import { set, trySet } from "ember-metal/property_set"; @@ -266,11 +262,11 @@ function addNormalizedProperty(base, key, value, meta, descs, values, concats, m descs[key] = value; values[key] = undefined; } else { - if ((concats && a_indexOf.call(concats, key) >= 0) || + if ((concats && concats.indexOf(key) >= 0) || key === 'concatenatedProperties' || key === 'mergedProperties') { value = applyConcatenatedProperties(base, key, value, values); - } else if ((mergings && a_indexOf.call(mergings, key) >= 0)) { + } else if ((mergings && mergings.indexOf(key) >= 0)) { value = applyMergedProperties(base, key, value, values); } else if (isMethod(value)) { value = giveMethodSuper(base, key, value, values, descs); @@ -313,7 +309,7 @@ function mergeMixins(mixins, m, descs, values, base, keys) { if (props.hasOwnProperty('toString')) { base.toString = props.toString; } } else if (currentMixin.mixins) { mergeMixins(currentMixin.mixins, m, descs, values, base, keys); - if (currentMixin._without) { a_forEach.call(currentMixin._without, removeKeys); } + if (currentMixin._without) { currentMixin._without.forEach(removeKeys); } } } } @@ -698,9 +694,7 @@ function _keys(ret, mixin, seen) { if (props.hasOwnProperty(key)) { ret[key] = true; } } } else if (mixin.mixins) { - a_forEach.call(mixin.mixins, (x) => { - _keys(ret, x, seen); - }); + mixin.mixins.forEach((x) => _keys(ret, x, seen)); } } diff --git a/packages/ember-metal/lib/observer.js b/packages/ember-metal/lib/observer.js index d79c085f111..169023ba1a7 100644 --- a/packages/ember-metal/lib/observer.js +++ b/packages/ember-metal/lib/observer.js @@ -2,7 +2,6 @@ import { watch, unwatch } from "ember-metal/watching"; -import { map } from "ember-metal/array"; import { listenersFor, addListener, @@ -90,12 +89,12 @@ export function _suspendObserver(obj, path, target, method, callback) { } export function _suspendBeforeObservers(obj, paths, target, method, callback) { - var events = map.call(paths, beforeEvent); + var events = paths.map(beforeEvent); return suspendListeners(obj, events, target, method, callback); } export function _suspendObservers(obj, paths, target, method, callback) { - var events = map.call(paths, changeEvent); + var events = paths.map(changeEvent); return suspendListeners(obj, events, target, method, callback); } diff --git a/packages/ember-metal/lib/run_loop.js b/packages/ember-metal/lib/run_loop.js index 6321b5a9ef4..6b5598fbb1e 100644 --- a/packages/ember-metal/lib/run_loop.js +++ b/packages/ember-metal/lib/run_loop.js @@ -2,7 +2,6 @@ import Ember from 'ember-metal/core'; import { GUID_KEY } from 'ember-metal/utils'; -import { indexOf } from 'ember-metal/array'; import { beginPropertyChanges, endPropertyChanges @@ -654,7 +653,7 @@ function checkAutoRun() { @private */ run._addQueue = function(name, after) { - if (indexOf.call(run.queues, name) === -1) { - run.queues.splice(indexOf.call(run.queues, after)+1, 0, name); + if (run.queues.indexOf(name) === -1) { + run.queues.splice(run.queues.indexOf(after)+1, 0, name); } }; diff --git a/packages/ember-metal/tests/run_loop/add_queue_test.js b/packages/ember-metal/tests/run_loop/add_queue_test.js index 77f2ea72db9..cd8c0443272 100644 --- a/packages/ember-metal/tests/run_loop/add_queue_test.js +++ b/packages/ember-metal/tests/run_loop/add_queue_test.js @@ -1,5 +1,4 @@ import run from 'ember-metal/run_loop'; -import { indexOf } from "ember-metal/array"; var originalQueues = run.queues; var queues; @@ -16,7 +15,7 @@ QUnit.module('system/run_loop/add_queue_test', { QUnit.test('adds a queue after a specified one', function() { run._addQueue('testeroo', 'blork'); - equal(indexOf.call(queues, 'testeroo'), 1, "new queue was added after specified queue"); + equal(queues.indexOf('testeroo'), 1, "new queue was added after specified queue"); }); QUnit.test('does not add the queue if it already exists', function() { diff --git a/packages/ember-routing-htmlbars/lib/keywords/closure-action.js b/packages/ember-routing-htmlbars/lib/keywords/closure-action.js index a8920b0488a..05057721875 100644 --- a/packages/ember-routing-htmlbars/lib/keywords/closure-action.js +++ b/packages/ember-routing-htmlbars/lib/keywords/closure-action.js @@ -1,5 +1,4 @@ import Stream from "ember-metal/streams/stream"; -import { map } from "ember-metal/array"; import { read, readArray @@ -14,10 +13,8 @@ export const ACTION = symbol('ACTION'); export default function closureAction(morph, env, scope, params, hash, template, inverse, visitor) { return new Stream(function() { - map.call(params, this.addDependency, this); - map.call(keys(hash), (item) => { - this.addDependency(item); - }); + params.map(this.addDependency, this); + keys(hash).map((item) => this.addDependency(item)); var rawAction = params[0]; var actionArguments = readArray(params.slice(1, params.length)); diff --git a/packages/ember-routing/lib/system/dsl.js b/packages/ember-routing/lib/system/dsl.js index 6f6729163c4..58036750dfb 100644 --- a/packages/ember-routing/lib/system/dsl.js +++ b/packages/ember-routing/lib/system/dsl.js @@ -1,6 +1,5 @@ import Ember from "ember-metal/core"; // FEATURES, assert import isEnabled from "ember-metal/features"; -import { indexOf } from "ember-metal/array"; /** @module ember @@ -32,7 +31,7 @@ DSL.prototype = { (function() { if (options.overrideNameAssertion === true) { return true; } - return indexOf.call(['array', 'basic', 'object', 'application'], name) === -1; + return ['array', 'basic', 'object', 'application'].indexOf(name) === -1; })() ); diff --git a/packages/ember-runtime/lib/system/each_proxy.js b/packages/ember-runtime/lib/system/each_proxy.js index 94d06bf1380..24465c5dedf 100644 --- a/packages/ember-runtime/lib/system/each_proxy.js +++ b/packages/ember-runtime/lib/system/each_proxy.js @@ -8,7 +8,6 @@ import Ember from "ember-metal/core"; // Ember.assert import { get } from "ember-metal/property_get"; import { guidFor } from "ember-metal/utils"; import { typeOf } from "ember-runtime/utils"; -import { indexOf } from "ember-metal/array"; import EmberArray from "ember-runtime/mixins/array"; // ES6TODO: WAT? Circular dep? import EmberObject from "ember-runtime/system/object"; import { computed } from "ember-metal/computed"; @@ -93,7 +92,7 @@ function removeObserverForContentKey(content, keyName, proxy, idx, loc) { guid = guidFor(item); indices = objects[guid]; - indices[indexOf.call(indices, loc)] = null; + indices[indices.indexOf(loc)] = null; } } } diff --git a/packages/ember-runtime/lib/system/lazy_load.js b/packages/ember-runtime/lib/system/lazy_load.js index 18bab54e4c3..11a5768940f 100644 --- a/packages/ember-runtime/lib/system/lazy_load.js +++ b/packages/ember-runtime/lib/system/lazy_load.js @@ -1,7 +1,6 @@ /*globals CustomEvent */ import Ember from "ember-metal/core"; // Ember.ENV.EMBER_LOAD_HOOKS -import { forEach } from "ember-metal/array"; import "ember-runtime/system/native_array"; // make sure Ember.A is setup. /** @@ -61,8 +60,6 @@ export function runLoadHooks(name, object) { } if (loadHooks[name]) { - forEach.call(loadHooks[name], function(callback) { - callback(object); - }); + loadHooks[name].forEach((callback) => callback(object)); } } diff --git a/packages/ember-runtime/lib/system/namespace.js b/packages/ember-runtime/lib/system/namespace.js index 6466a958eb6..cb4f4921008 100644 --- a/packages/ember-runtime/lib/system/namespace.js +++ b/packages/ember-runtime/lib/system/namespace.js @@ -6,7 +6,6 @@ // Ember.lookup, Ember.BOOTED, Ember.deprecate, Ember.NAME_KEY, Ember.anyUnprocessedMixins import Ember from "ember-metal/core"; import { get } from "ember-metal/property_get"; -import { indexOf } from "ember-metal/array"; import { GUID_KEY, guidFor @@ -61,7 +60,7 @@ var Namespace = EmberObject.extend({ Ember.lookup[toString] = undefined; delete Namespace.NAMESPACES_BY_ID[toString]; } - namespaces.splice(indexOf.call(namespaces, this), 1); + namespaces.splice(namespaces.indexOf(this), 1); this._super(...arguments); } }); diff --git a/packages/ember-runtime/lib/system/native_array.js b/packages/ember-runtime/lib/system/native_array.js index 350ff543ee9..d7039b1f1a8 100644 --- a/packages/ember-runtime/lib/system/native_array.js +++ b/packages/ember-runtime/lib/system/native_array.js @@ -7,7 +7,6 @@ import Ember from "ember-metal/core"; // Ember.EXTEND_PROTOTYPES import { _replace as replace } from "ember-metal/replace"; import { get } from "ember-metal/property_get"; import { Mixin } from "ember-metal/mixin"; -import { indexOf, lastIndexOf } from "ember-metal/array"; import EmberArray from "ember-runtime/mixins/array"; import MutableArray from "ember-runtime/mixins/mutable_array"; import Observable from "ember-runtime/mixins/observable"; @@ -84,9 +83,8 @@ var NativeArray = Mixin.create(MutableArray, Observable, Copyable, { return ret; }, - indexOf: indexOf, - - lastIndexOf: lastIndexOf, + indexOf: Array.prototype.indexOf, + lastIndexOf: Array.prototype.lastIndexOf, copy(deep) { if (deep) { diff --git a/packages/ember-runtime/tests/computed/reduce_computed_macros_test.js b/packages/ember-runtime/tests/computed/reduce_computed_macros_test.js index 49ba92ed392..14137ff1b65 100644 --- a/packages/ember-runtime/tests/computed/reduce_computed_macros_test.js +++ b/packages/ember-runtime/tests/computed/reduce_computed_macros_test.js @@ -10,7 +10,6 @@ import { beginPropertyChanges, endPropertyChanges } from "ember-metal/property_events"; -import { forEach } from "ember-metal/array"; import { observer, Mixin } from 'ember-metal/mixin'; import { sum as computedSum, @@ -467,7 +466,7 @@ QUnit.test("properties values can be replaced", function() { deepEqual(a1bs.mapBy('name'), ['item1'], "properties can be filtered by matching value"); }); -forEach.call([['uniq', computedUniq], ['union', computedUnion]], function (tuple) { +[['uniq', computedUniq], ['union', computedUnion]].forEach(function (tuple) { var alias = tuple[0]; var testedFunc = tuple[1]; diff --git a/packages/ember-views/tests/views/text_area_test.js b/packages/ember-views/tests/views/text_area_test.js index 33a55b0cd4b..17121298740 100644 --- a/packages/ember-views/tests/views/text_area_test.js +++ b/packages/ember-views/tests/views/text_area_test.js @@ -1,5 +1,4 @@ import EmberObject from "ember-runtime/system/object"; -import { forEach } from "ember-metal/array"; import run from "ember-metal/run_loop"; import TextArea from "ember-views/views/text_area"; import { get } from "ember-metal/property_get"; @@ -178,7 +177,7 @@ QUnit.test("value binding works properly for inputs that haven't been created", equal(textArea.$().val(), 'ohai', "value is reflected in the input element once it is created"); }); -forEach.call(['cut', 'paste', 'input'], function(eventName) { +['cut', 'paste', 'input'].forEach(function(eventName) { QUnit.test("should update the value on " + eventName + " events", function() { run(function() {