@@ -108,9 +108,9 @@ webdriver.promise.Thenable.prototype.isPending = function() {};
108
108
* @param {?(function(T): (R|webdriver.promise.Promise.<R>))= } opt_callback The
109
109
* function to call if this promise is successfully resolved. The function
110
110
* should expect a single argument: the promise's resolved value.
111
- * @param {?(function(* ): (R|webdriver.promise.Promise.<R>))= } opt_errback The
112
- * function to call if this promise is rejected. The function should expect
113
- * a single argument: the rejection reason.
111
+ * @param {?(function(Error ): (R|webdriver.promise.Promise.<R>))= } opt_errback
112
+ * The function to call if this promise is rejected. The function should
113
+ * expect a single argument: the rejection reason.
114
114
* @return {!webdriver.promise.Promise.<R> } A new promise which will be
115
115
* resolved with the result of the invoked callback.
116
116
* @template R
@@ -136,9 +136,9 @@ webdriver.promise.Thenable.prototype.then = function(
136
136
* });
137
137
* </code></pre>
138
138
*
139
- * @param {function(* ): (R|webdriver.promise.Promise.<R>) } errback The function
140
- * to call if this promise is rejected. The function should expect a single
141
- * argument: the rejection reason.
139
+ * @param {function(Error ): (R|webdriver.promise.Promise.<R>) } errback The
140
+ * function to call if this promise is rejected. The function should
141
+ * expect a single argument: the rejection reason.
142
142
* @return {!webdriver.promise.Promise.<R> } A new promise which will be
143
143
* resolved with the result of the invoked callback.
144
144
* @template R
@@ -429,10 +429,10 @@ webdriver.promise.Deferred = function(opt_flow) {
429
429
* @param {* } newValue The deferred's new value.
430
430
*/
431
431
function notifyAll ( newState , newValue ) {
432
- if ( newState === webdriver . promise . Deferred . State_ . REJECTED &&
433
- // We cannot check instanceof Error since the object may have been
434
- // created in a different JS context.
435
- goog . isObject ( newValue ) && goog . isString ( newValue . message ) ) {
432
+ if ( newState === webdriver . promise . Deferred . State_ . REJECTED ) {
433
+ if ( ! webdriver . promise . isError_ ( newValue ) ) {
434
+ newValue = Error ( newValue ? newValue : 'Promise rejected' ) ;
435
+ }
436
436
newValue = flow . annotateError ( /** @type {!Error } */ ( newValue ) ) ;
437
437
}
438
438
@@ -484,7 +484,8 @@ webdriver.promise.Deferred = function(opt_flow) {
484
484
* Registers a callback on this Deferred.
485
485
*
486
486
* @param {?(function(T): (R|webdriver.promise.Promise.<R>))= } opt_callback .
487
- * @param {?(function(*): (R|webdriver.promise.Promise.<R>))= } opt_errback .
487
+ * @param {?(function(Error):
488
+ * (R|webdriver.promise.Promise.<R>))=} opt_errback .
488
489
* @return {!webdriver.promise.Promise.<R> } A new promise representing the
489
490
* result of the callback.
490
491
* @template R
@@ -538,8 +539,8 @@ webdriver.promise.Deferred = function(opt_flow) {
538
539
/**
539
540
* Rejects this promise. If the error is itself a promise, this instance will
540
541
* be chained to it and be rejected with the error's resolved value.
541
- * @param {*= } opt_error The rejection reason, typically either a
542
- * { @code Error} or a { @code string} .
542
+ * @param {*= } opt_error The rejection reason. If not a { @link Error}, one
543
+ * will be created from the value's string representation .
543
544
*/
544
545
function reject ( opt_error ) {
545
546
resolve ( webdriver . promise . Deferred . State_ . REJECTED , opt_error ) ;
@@ -622,7 +623,7 @@ webdriver.promise.Deferred.State_ = {
622
623
webdriver . promise . isError_ = function ( value ) {
623
624
return value instanceof Error ||
624
625
goog . isObject ( value ) &&
625
- ( Object . prototype . toString . call ( value ) === '[object Error]' ||
626
+ ( goog . isString ( value . message ) ||
626
627
// A special test for goog.testing.JsUnitException.
627
628
value . isJsUnitException ) ;
628
629
@@ -1514,19 +1515,12 @@ webdriver.promise.ControlFlow.prototype.runEventLoop_ = function() {
1514
1515
} , this ) ;
1515
1516
1516
1517
this . trimHistory_ ( ) ;
1517
- var self = this ;
1518
1518
this . runInNewFrame_ ( task . execute , function ( result ) {
1519
1519
markTaskComplete ( ) ;
1520
1520
task . fulfill ( result ) ;
1521
1521
} , function ( error ) {
1522
1522
markTaskComplete ( ) ;
1523
-
1524
- if ( ! webdriver . promise . isError_ ( error ) &&
1525
- ! webdriver . promise . isPromise ( error ) ) {
1526
- error = Error ( error ) ;
1527
- }
1528
-
1529
- task . reject ( self . annotateError ( /** @type {!Error } */ ( error ) ) ) ;
1523
+ task . reject ( error ) ;
1530
1524
} , true ) ;
1531
1525
} ;
1532
1526
0 commit comments