diff options
author | Eric Guzman | 2012-04-23 11:55:55 -0700 |
---|---|---|
committer | Eric Guzman | 2012-04-23 11:55:55 -0700 |
commit | cdd1189e349e2974681e2c451e861e5b0db570e4 (patch) | |
tree | d8823c3d050e011032c563d20c1a5f61e67ae740 /node_modules/montage/core/promise.js | |
parent | c0fce534c255ef1e25779e2f0e8de95bb4e160cf (diff) | |
parent | 5a0331fc26fcc2cdc6200086109e34440a2dec6a (diff) | |
download | ninja-cdd1189e349e2974681e2c451e861e5b0db570e4.tar.gz |
Merge branch 'refs/heads/master' into CSSPanelUpdates
Diffstat (limited to 'node_modules/montage/core/promise.js')
-rwxr-xr-x | node_modules/montage/core/promise.js | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/node_modules/montage/core/promise.js b/node_modules/montage/core/promise.js index eb9ccd86..7563a742 100755 --- a/node_modules/montage/core/promise.js +++ b/node_modules/montage/core/promise.js | |||
@@ -127,6 +127,7 @@ var PrimordialPromise = Creatable.create({ | |||
127 | 127 | ||
128 | // automatically subcreate each of the contained promise types | 128 | // automatically subcreate each of the contained promise types |
129 | var creation = Object.create(this); | 129 | var creation = Object.create(this); |
130 | creation.AbstractPromise = this.AbstractPromise.create(promiseDescriptor); | ||
130 | creation.DeferredPromise = this.DeferredPromise.create(promiseDescriptor); | 131 | creation.DeferredPromise = this.DeferredPromise.create(promiseDescriptor); |
131 | creation.FulfilledPromise = this.FulfilledPromise.create(promiseDescriptor); | 132 | creation.FulfilledPromise = this.FulfilledPromise.create(promiseDescriptor); |
132 | creation.RejectedPromise = this.RejectedPromise.create(promiseDescriptor); | 133 | creation.RejectedPromise = this.RejectedPromise.create(promiseDescriptor); |
@@ -156,7 +157,14 @@ var PrimordialPromise = Creatable.create({ | |||
156 | } | 157 | } |
157 | }, | 158 | }, |
158 | 159 | ||
160 | // deprecated | ||
159 | ref: { | 161 | ref: { |
162 | get: function () { | ||
163 | return this.resolve; | ||
164 | } | ||
165 | }, | ||
166 | |||
167 | resolve: { | ||
160 | value: function (object) { | 168 | value: function (object) { |
161 | // if it is already a promise, wrap it to guarantee | 169 | // if it is already a promise, wrap it to guarantee |
162 | // the full public API of this promise variety. | 170 | // the full public API of this promise variety. |
@@ -253,7 +261,8 @@ var PrimordialPromise = Creatable.create({ | |||
253 | self._reason = reason; | 261 | self._reason = reason; |
254 | self._error = error; | 262 | self._error = error; |
255 | self.Promise = this; | 263 | self.Promise = this; |
256 | errors.push(error && error.stack || self); | 264 | rejections.push(self); |
265 | errors.push(error ? (error.stack ? error.stack : error) : reason); | ||
257 | return self; | 266 | return self; |
258 | } | 267 | } |
259 | }, | 268 | }, |
@@ -266,8 +275,9 @@ var PrimordialPromise = Creatable.create({ | |||
266 | then: function (r, o, rejected) { | 275 | then: function (r, o, rejected) { |
267 | // remove this error from the list of unhandled errors on the console | 276 | // remove this error from the list of unhandled errors on the console |
268 | if (rejected) { | 277 | if (rejected) { |
269 | var at = errors.indexOf(this._error && this._error.stack || this); | 278 | var at = rejections.indexOf(this); |
270 | if (at !== -1) { | 279 | if (at !== -1) { |
280 | rejections.splice(at, 1); | ||
271 | errors.splice(at, 1); | 281 | errors.splice(at, 1); |
272 | } | 282 | } |
273 | } | 283 | } |
@@ -378,6 +388,10 @@ var PrimordialPromise = Creatable.create({ | |||
378 | } | 388 | } |
379 | 389 | ||
380 | }) | 390 | }) |
391 | }, | ||
392 | |||
393 | AbstractPromise: { | ||
394 | value: AbstractPromise | ||
381 | } | 395 | } |
382 | 396 | ||
383 | }); | 397 | }); |
@@ -411,7 +425,7 @@ var Promise = PrimordialPromise.create({}, { // Descriptor for each of the three | |||
411 | try { | 425 | try { |
412 | deferred.resolve(fulfilled ? fulfilled(value) : value); | 426 | deferred.resolve(fulfilled ? fulfilled(value) : value); |
413 | } catch (error) { | 427 | } catch (error) { |
414 | console.error(error.stack); | 428 | console.error(error.stack || error, fulfilled); |
415 | deferred.reject(error.message, error); | 429 | deferred.reject(error.message, error); |
416 | } | 430 | } |
417 | } | 431 | } |
@@ -556,18 +570,21 @@ var Promise = PrimordialPromise.create({}, { // Descriptor for each of the three | |||
556 | 570 | ||
557 | delay: { | 571 | delay: { |
558 | value: function (timeout) { | 572 | value: function (timeout) { |
559 | var deferred = this.Promise.defer(); | 573 | var self = this; |
560 | this.then(function (value) { | 574 | var promise; |
561 | clearTimeout(handle); | 575 | if (arguments.length === 0) { |
562 | deferred.resolve(value); | 576 | timeout = this; |
563 | }, function (reason, error, rejection) { | 577 | } else { |
564 | clearTimeout(handle); | 578 | promise = this; |
565 | deferred.resolve(rejection); | 579 | } |
580 | return Promise.ref(timeout) | ||
581 | .then(function (timeout) { | ||
582 | var deferred = self.Promise.defer(); | ||
583 | setTimeout(function () { | ||
584 | deferred.resolve(promise); | ||
585 | }, timeout); | ||
586 | return deferred.promise; | ||
566 | }); | 587 | }); |
567 | var handle = setTimeout(function () { | ||
568 | deferred.reject("Timed out"); | ||
569 | }, timeout); | ||
570 | return deferred.promise; | ||
571 | } | 588 | } |
572 | }, | 589 | }, |
573 | 590 | ||
@@ -582,7 +599,7 @@ var Promise = PrimordialPromise.create({}, { // Descriptor for each of the three | |||
582 | deferred.resolve(rejection); | 599 | deferred.resolve(rejection); |
583 | }).end(); | 600 | }).end(); |
584 | var handle = setTimeout(function () { | 601 | var handle = setTimeout(function () { |
585 | deferred.reject("Timed out"); | 602 | deferred.reject("Timed out", new Error("Timed out")); |
586 | }, timeout); | 603 | }, timeout); |
587 | return deferred.promise; | 604 | return deferred.promise; |
588 | } | 605 | } |
@@ -657,6 +674,7 @@ var Promise = PrimordialPromise.create({}, { // Descriptor for each of the three | |||
657 | 674 | ||
658 | }); | 675 | }); |
659 | 676 | ||
677 | var rejections = []; | ||
660 | var errors = []; | 678 | var errors = []; |
661 | // Live console objects are not handled on tablets | 679 | // Live console objects are not handled on tablets |
662 | if (typeof window !== "undefined" && !window.Touch) { | 680 | if (typeof window !== "undefined" && !window.Touch) { |