Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: Source/devtools/front_end/platform/Promise.js

Issue 692343002: Revert of [DevTools] Extract platform module. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @param {string} error
7 * @return {!Promise.<T>}
8 * @template T
9 */
10 Promise.rejectWithError = function(error)
11 {
12 return Promise.reject(new Error(error));
13 }
14
15 /**
16 * @param {function((T|undefined))} callback
17 * @return {!Promise.<T>}
18 * @template T
19 */
20 Promise.prototype.thenOrCatch = function(callback)
21 {
22 return this.then(callback, reject.bind(this));
23
24 /**
25 * @param {*} e
26 * @this {Promise}
27 */
28 function reject(e)
29 {
30 this._reportError(e);
31 callback(undefined);
32 }
33 }
34
35 Promise.prototype.done = function()
36 {
37 this.catchAndReport();
38 }
39
40 /**
41 * @return {!Promise}
42 */
43 Promise.prototype.catchAndReport = function()
44 {
45 return this.catch(this._reportError.bind(this));
46 }
47
48 /**
49 * @param {*} e
50 */
51 Promise.prototype._reportError = function(e)
52 {
53 if (e instanceof Error)
54 console.error(e.stack);
55 else
56 console.error(e);
57 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/platform/DOMExtension.js ('k') | Source/devtools/front_end/platform/module.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698