diff options
Diffstat (limited to 'node_modules/montage-user/core/shim/array.js')
-rwxr-xr-x | node_modules/montage-user/core/shim/array.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/node_modules/montage-user/core/shim/array.js b/node_modules/montage-user/core/shim/array.js new file mode 100755 index 00000000..ff5d5d37 --- /dev/null +++ b/node_modules/montage-user/core/shim/array.js | |||
@@ -0,0 +1,78 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /** | ||
7 | Defines extensions to native Array object. | ||
8 | @see [Array class]{@link external:Array} | ||
9 | @module montage/core/shim/array | ||
10 | */ | ||
11 | /** | ||
12 | @external Array | ||
13 | */ | ||
14 | |||
15 | /** | ||
16 | @function external:Array#equals | ||
17 | @param {object} right The object to compare. | ||
18 | @returns {Boolean} true or false | ||
19 | */ | ||
20 | if (!Array.prototype.equals) { | ||
21 | Object.defineProperty(Array.prototype, "equals", { | ||
22 | value: function (right) { | ||
23 | var i = 0, | ||
24 | length = this.length, | ||
25 | lhs, | ||
26 | rhs; | ||
27 | |||
28 | if (this === right) { | ||
29 | return true; | ||
30 | } | ||
31 | |||
32 | if (!right || !Array.isArray(right)) { | ||
33 | return false; | ||
34 | } | ||
35 | |||
36 | if (length !== right.length) { | ||
37 | return false; | ||
38 | } else { | ||
39 | for (; i < length; ++i) { | ||
40 | if (i in this) { | ||
41 | lhs = this[i], | ||
42 | rhs = right[i]; | ||
43 | |||
44 | if (lhs !== rhs && (lhs && rhs && !lhs.equals(rhs))) { | ||
45 | return false; | ||
46 | } | ||
47 | } else { | ||
48 | if (i in right) { | ||
49 | return false; | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | return true; | ||
55 | } | ||
56 | }); | ||
57 | } | ||
58 | /** | ||
59 | Shim implementation of Array.isArray() for browsers that don't yet support it. | ||
60 | @function external:Array.isArray | ||
61 | @param {object} obj The object to determine if its an array. | ||
62 | @returns {Array} Object.prototype.toString.call(obj) === "[object Array]" | ||
63 | */ | ||
64 | if (!Array.isArray) { | ||
65 | Object.defineProperty(Array, "isArray", { | ||
66 | value: function(obj) { | ||
67 | return Object.prototype.toString.call(obj) === "[object Array]"; | ||
68 | } | ||
69 | }); | ||
70 | } | ||
71 | |||
72 | if (!Array.isCanvasPixelArray) { | ||
73 | Object.defineProperty(Array, "isCanvasPixelArray", { | ||
74 | value: function(obj) { | ||
75 | return Object.prototype.toString.call(obj) === "[object CanvasPixelArray]"; | ||
76 | } | ||
77 | }); | ||
78 | } | ||