aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/core/shim
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /node_modules/montage/core/shim
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'node_modules/montage/core/shim')
-rwxr-xr-xnode_modules/montage/core/shim/array.js78
-rwxr-xr-xnode_modules/montage/core/shim/string.js66
-rwxr-xr-xnode_modules/montage/core/shim/structures.js552
-rwxr-xr-xnode_modules/montage/core/shim/timers.js87
-rwxr-xr-xnode_modules/montage/core/shim/weak-map.js454
5 files changed, 1237 insertions, 0 deletions
diff --git a/node_modules/montage/core/shim/array.js b/node_modules/montage/core/shim/array.js
new file mode 100755
index 00000000..ff5d5d37
--- /dev/null
+++ b/node_modules/montage/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*/
20if (!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*/
64if (!Array.isArray) {
65 Object.defineProperty(Array, "isArray", {
66 value: function(obj) {
67 return Object.prototype.toString.call(obj) === "[object Array]";
68 }
69 });
70}
71
72if (!Array.isCanvasPixelArray) {
73 Object.defineProperty(Array, "isCanvasPixelArray", {
74 value: function(obj) {
75 return Object.prototype.toString.call(obj) === "[object CanvasPixelArray]";
76 }
77 });
78}
diff --git a/node_modules/montage/core/shim/string.js b/node_modules/montage/core/shim/string.js
new file mode 100755
index 00000000..1b71cec3
--- /dev/null
+++ b/node_modules/montage/core/shim/string.js
@@ -0,0 +1,66 @@
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 String object.
8 @see [String class]{@link external:String}
9 @module montage/core/shim/string
10*/
11
12/**
13 @external String
14 */
15Object.defineProperties(String.prototype, /** @lends external:String.prototype#*/{
16 /**
17 @function external:String.addEventListener
18 @param {Listener} type The type of event listener.
19 @param {Listener} listener The event listener.
20 @param {Function} useCapture The capturing function.
21 */
22 addEventListener: {
23 value: function(type, listener, useCapture) {
24 //NO OP, on purpose
25 }
26
27 },
28 /**
29 Capitalizes the first letter in the string.
30 @function external:String.toCapitalized
31 @returns {String} The original string with its first letter capitalized.
32 @example
33 var fname = "abe";
34 var lname = "lincoln";
35 var name = fname.toCapitalized() + " " + lname.toCapitalized();
36 // name == "Abe Lincoln"
37 */
38 toCapitalized: {
39 value: function() {
40 return this.charAt(0).toUpperCase() + this.slice(1);
41 }
42 },
43
44 /**
45 Returns true if the two strings are equal, otherwise returns false.
46 @function external:String.equals
47 @param {Object} anObject The object to compare to the string.
48 @returns {Boolean} Returns true if the string is equal to <code>anObject</code>.
49 */
50 equals: {
51 value: function(anObject) {
52 if (this.toString() === anObject) {
53 return true;
54 }
55
56 if (!anObject || !(anObject instanceof String)) {
57 return false;
58 }
59
60 return (this == anObject);
61 }
62 }
63
64});
65
66
diff --git a/node_modules/montage/core/shim/structures.js b/node_modules/montage/core/shim/structures.js
new file mode 100755
index 00000000..2f3d7d05
--- /dev/null
+++ b/node_modules/montage/core/shim/structures.js
@@ -0,0 +1,552 @@
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// Specification:
8// http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets
9
10/**
11 This module provides common data structure utililties, such as maps and sets.
12 @module montage/core/shim/structures
13 @see [Map class]{@link module:montage/core/shim/structures.Map}
14 */
15/**
16 @class module:montage/core/shim/structures.Map
17 @classdesc Provides a Map data structure for managing key/value pairs, including methods for querying and manipulating map elements. A map cannot contain duplicate keys; each key can map to at most one value.
18 */
19exports.Map = Map;
20function Map(ignored, options) {
21 if (!(this instanceof Map)) {
22 return new Map(ignored, options);
23 }
24 options = options || {};
25 var eq = options.eq || Set.eq;
26 var hash = options.hash || Set.hash;
27 this._set = Set(
28 undefined,
29 {
30 eq: function (a, b) {
31 return eq(a.key, b.key);
32 },
33 hash: function (pair) {
34 return hash(pair.key);
35 }
36 }
37 );
38}
39
40Object.defineProperties(Map.prototype, /** @lends module:montage/core/shim/structures.Map# */ {
41/**
42 @function
43 @returns this._set.empty()
44 */
45 empty: {
46 value: function () {
47 return this._set.empty();
48 }
49 },
50
51 /**
52 Returns the value associated with the <code>key</code> parameter, if it exists.
53 @function
54 @param {String} key The name of the key.
55 @returns {Object} The value of the specified key, if it exists; otherwise returns undefined.
56 */
57 get: {
58 value: function (key) {
59 var pair = this._set.get({
60 key: key
61 });
62 return pair ? pair.value : undefined;
63 }
64 },
65
66 /**
67 Adds a new key/value pair to the map.
68 @function
69 @param {Object} key The key to use for the new pair.
70 @param {Object} value The value to associate with the key.
71 @returns key, value
72 */
73 set: {
74 value: function (key, value) {
<