Chromium Code Reviews| Index: chrome/browser/resources/google_now/common_test_util.js |
| diff --git a/chrome/browser/resources/google_now/common_test_util.js b/chrome/browser/resources/google_now/common_test_util.js |
| index 754e2578fa2f6bf059a5b2b70fbb7ea8c6ed0bed..2c475288faaf32c1baeebfc4d66057b1831783c5 100644 |
| --- a/chrome/browser/resources/google_now/common_test_util.js |
| +++ b/chrome/browser/resources/google_now/common_test_util.js |
| @@ -82,16 +82,38 @@ function getMockHandlerContainer(eventIdentifier) { |
| var Promise = function() { |
| function PromisePrototypeObject(asyncTask) { |
| var result; |
| + var resolved = false; |
| asyncTask( |
| function(asyncResult) { |
| result = asyncResult; |
| + resolved = true; |
| }, |
| - function() {}); // Errors are unsupported. |
| + function(asyncFailureResult) { |
| + result = asyncResult; |
| + resolved = false; |
| + }); |
| function then(callback) { |
| - callback.call(null, result); |
| + if (resolved) { |
| + callback.call(null, result); |
| + } |
| + return this; |
| } |
| - return {then: then, isPromise: true}; |
| + |
| + // Promises use the function name catch to call back error handlers. |
|
skare_
2014/02/13 23:53:52
(no action required, just a suggestion based on fi
robliao
2014/02/14 00:05:11
Done.
|
| + // We can't use catch since function or variable names cannot use the word |
|
skare_
2014/02/13 23:53:52
or just "We can't use 'catch' since it's reserved"
robliao
2014/02/14 00:05:11
This isn't strictly true, since it works fine for
|
| + // catch. |
| + function catchFunc(callback) { |
| + if (!resolved) { |
| + callback.call(null, result); |
| + } |
| + return this; |
| + } |
| + |
| + var promiseObj = {then: then, isPromise: true}; |
| + // Using the name 'catch' above during initialization will trigger an error. |
| + promiseObj.catch = catchFunc; |
|
skare_
2014/02/13 23:37:03
does promiseObj.catch = function(...) {} work?
robliao
2014/02/13 23:43:20
It does, but the named functions follows other non
skare_
2014/02/13 23:53:52
return {then: then, isPromise: true, catch: catchF
robliao
2014/02/14 00:05:11
This won't work since "catch" is reserved in objec
skare_
2014/02/14 00:19:26
will catch* you in person since I might have const
robliao
2014/02/14 01:57:04
And done.
On 2014/02/14 00:19:26, Travis Skare wro
|
| + return promiseObj; |
| } |
| function all(arrayOfPromises) { |