aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/core/shim
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage/core/shim')
-rw-r--r--[-rwxr-xr-x]node_modules/montage/core/shim/immediate.js (renamed from node_modules/montage/core/shim/timers.js)44
-rwxr-xr-xnode_modules/montage/core/shim/structures.js22
2 files changed, 18 insertions, 48 deletions
diff --git a/node_modules/montage/core/shim/timers.js b/node_modules/montage/core/shim/immediate.js
index 859a7aec..3ac48f31 100755..100644
--- a/node_modules/montage/core/shim/timers.js
+++ b/node_modules/montage/core/shim/immediate.js
@@ -4,12 +4,13 @@
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */ 5 </copyright> */
6 6
7 /** 7/**
8 Defines [setImmediate()]{@link setImmediate} and [clearImmediate()]{@link clearImmediate} shim functions. 8 [setImmediate()]{@link setImmediate}
9 and [clearImmediate()]{@link clearImmediate} shim functions.
9 @see setImmediate 10 @see setImmediate
10 @see clearImmediate 11 @see clearImmediate
11 @module montage/core/shim/timers 12 @module montage/core/shim/immediate
12 */ 13*/
13 14
14/** 15/**
15 @function 16 @function
@@ -25,40 +26,13 @@
25 26
26(function (global) { 27(function (global) {
27 28
28var nextTick; 29var nextTick = require("../next-tick").nextTick;
29if (typeof process !== "undefined") {
30 nextTick = process.nextTick;
31} else if (typeof MessageChannel !== "undefined") {
32 // http://www.nonblocking.io/2011/06/windownexttick.html
33 var channel = new MessageChannel();
34 // linked list of tasks (single, with head node)
35 var head = {}, tail = head;
36
37 channel.port1.onmessage = function () {
38 var next = head.next;
39 var task = next.task;
40 head = next;
41 task();
42 };
43
44 nextTick = function (task) {
45 tail = tail.next = {task: task};
46 channel.port2.postMessage(void 0);
47 }
48} else if (typeof setTimeout !== "undefined") {
49
50 nextTick = function (callback) {
51 setTimeout(callback, 0);
52 };
53} else {
54 throw new Error("Can't shim setImmediate.");
55}
56 30
57if (typeof setImmediate === "undefined") { 31if (typeof setImmediate === "undefined") {
32
58 var nextHandle = 0; 33 var nextHandle = 0;
59 var handles = {}; 34 var handles = {};
60 35
61
62 global.setImmediate = function setImmediate(callback) { 36 global.setImmediate = function setImmediate(callback) {
63 var handle = nextHandle++; 37 var handle = nextHandle++;
64 var args = arguments.length > 1 ? 38 var args = arguments.length > 1 ?
@@ -77,11 +51,7 @@ if (typeof setImmediate === "undefined") {
77 global.clearImmediate = function clearImmediate(handle) { 51 global.clearImmediate = function clearImmediate(handle) {
78 delete handles[handle]; 52 delete handles[handle];
79 }; 53 };
80}
81 54
82// Make this work as a <script> for bootstrapping montage.js
83if (typeof bootstrap !== "undefined") {
84 bootstrap("core/shim/timers", function () {});
85} 55}
86 56
87})(typeof global === "undefined" ? window : global); 57})(typeof global === "undefined" ? window : global);
diff --git a/node_modules/montage/core/shim/structures.js b/node_modules/montage/core/shim/structures.js
index 2f3d7d05..fb8e2191 100755
--- a/node_modules/montage/core/shim/structures.js
+++ b/node_modules/montage/core/shim/structures.js
@@ -17,9 +17,9 @@
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. 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 */ 18 */
19exports.Map = Map; 19exports.Map = Map;
20function Map(ignored, options) { 20function Map(reserved, options) {
21 if (!(this instanceof Map)) { 21 if (!(this instanceof Map)) {
22 return new Map(ignored, options); 22 return new Map(reserved, options);
23 } 23 }
24 options = options || {}; 24 options = options || {};
25 var eq = options.eq || Set.eq; 25 var eq = options.eq || Set.eq;
@@ -131,9 +131,9 @@ Object.defineProperties(Map.prototype, /** @lends module:montage/core/shim/struc
131 @class module:montage/core/shim/structures.Set 131 @class module:montage/core/shim/structures.Set
132 */ 132 */
133exports.Set = Set; 133exports.Set = Set;
134function Set(ignored, options) { 134function Set(reserved, options) {
135 if (!(this instanceof Set)) { 135 if (!(this instanceof Set)) {
136 return new Set(ignored, options); 136 return new Set(reserved, options);
137 } 137 }
138 options = options || {}; 138 options = options || {};
139 var eq = options.eq || Set.eq; 139 var eq = options.eq || Set.eq;
@@ -238,13 +238,13 @@ Object.defineProperties(Set.prototype, /** @lends module:montage/core/shim/struc
238}); 238});
239/** 239/**
240 @class module:montage/core/shim/structures.OrderedSet 240 @class module:montage/core/shim/structures.OrderedSet
241 @param {boolean} ignored 241 @param {boolean} reserved
242 @param {object} options 242 @param {object} options
243*/ 243*/
244exports.OrderedSet = OrderedSet; 244exports.OrderedSet = OrderedSet;
245function OrderedSet(ignored, options) { 245function OrderedSet(reserved, options) {
246 if (!(this instanceof OrderedSet)) { 246 if (!(this instanceof OrderedSet)) {
247 return new OrderedSet(ignored, options); 247 return new OrderedSet(reserved, options);
248 } 248 }
249 options = options || {}; 249 options = options || {};
250 var eq = options.eq || OrderedSet.eq; 250 var eq = options.eq || OrderedSet.eq;
@@ -397,14 +397,14 @@ Set.hash = function (value) {
397/** 397/**
398 @exports CacheMap 398 @exports CacheMap
399 @function 399 @function
400 @param {Boolean} ignored 400 @param {Boolean} reserved
401 @param {String} options 401 @param {String} options
402 @returns new CacheMap(ignored, options) 402 @returns new CacheMap(reserved, options)
403 */ 403 */
404exports.CacheMap = CacheMap; 404exports.CacheMap = CacheMap;
405function CacheMap(ignored, options) { 405function CacheMap(reserved, options) {
406 if (!(this instanceof CacheMap)) { 406 if (!(this instanceof CacheMap)) {
407 return new CacheMap(ignored, options); 407 return new CacheMap(reserved, options);
408 } 408 }
409 options = options || {}; 409 options = options || {};
410 410