3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
7 <link rel="import" href="/tvcm.html">
11 tvcm.exportTo('tvcm', function() {
12 function asArray(arrayish) {
14 for (var i = 0; i < arrayish.length; i++)
15 values.push(arrayish[i]);
19 function compareArrays(x, y, elementCmp) {
20 var minLength = Math.min(x.length, y.length);
21 for (var i = 0; i < minLength; i++) {
22 var tmp = elementCmp(x[i], y[i]);
26 if (x.length == y.length)
29 if (x[i] === undefined)
36 * Compares two values when one or both might be undefined. Undefined
37 * values are sorted after defined.
39 function comparePossiblyUndefinedValues(x, y, cmp) {
40 if (x !== undefined && y !== undefined)
49 function concatenateArrays(/*arguments*/) {
51 for (var i = 0; i < arguments.length; i++) {
52 if (!(arguments[i] instanceof Array))
53 throw new Error('Arguments ' + i + 'is not an array');
54 values.push.apply(values, arguments[i]);
59 function concatenateObjects(/*arguments*/) {
61 for (var i = 0; i < arguments.length; i++) {
62 var object = arguments[i];
63 for (var j in object) {
64 result[j] = object[j];
70 function dictionaryKeys(dict) {
77 function dictionaryValues(dict) {
80 values.push(dict[key]);
84 function dictionaryLength(dict) {
91 function iterItems(dict, fn, opt_this) {
92 opt_this = opt_this || this;
94 fn.call(opt_this, key, dict[key]);
97 function iterObjectFieldsRecursively(object, func) {
98 if (!(object instanceof Object))
101 if (object instanceof Array) {
102 for (var i = 0; i < object.length; i++) {
103 func(object, i, object[i]);
104 iterObjectFieldsRecursively(object[i], func);
109 for (var key in object) {
110 var value = object[key];
111 func(object, key, value);
112 iterObjectFieldsRecursively(value, func);
116 function identity(d) {
120 function findFirstIndexInArray(ary, opt_func, opt_this) {
121 var func = opt_func || identity;
122 for (var i = 0; i < ary.length; i++) {
123 if (func.call(opt_this, ary[i], i))
129 function findFirstInArray(ary, opt_func, opt_this) {
130 var i = findFirstIndexInArray(ary, opt_func, opt_func);
138 concatenateArrays: concatenateArrays,
139 concatenateObjects: concatenateObjects,
140 compareArrays: compareArrays,
141 comparePossiblyUndefinedValues: comparePossiblyUndefinedValues,
142 dictionaryLength: dictionaryLength,
143 dictionaryKeys: dictionaryKeys,
144 dictionaryValues: dictionaryValues,
145 iterItems: iterItems,
146 iterObjectFieldsRecursively: iterObjectFieldsRecursively,
147 findFirstIndexInArray: findFirstIndexInArray,
148 findFirstInArray: findFirstInArray