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

Unified Diff: third_party/polymer/v0_8/components/promise-polyfill/Promise.js

Issue 1155683008: Rename polymer and cr_elements v0_8 to v1_0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v1
Patch Set: fix a merge mistake Created 5 years, 7 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/v0_8/components/promise-polyfill/Promise.js
diff --git a/third_party/polymer/v0_8/components/promise-polyfill/Promise.js b/third_party/polymer/v0_8/components/promise-polyfill/Promise.js
deleted file mode 100644
index dc6f58f1b22efaf547c5d205a0203732cf21f0dd..0000000000000000000000000000000000000000
--- a/third_party/polymer/v0_8/components/promise-polyfill/Promise.js
+++ /dev/null
@@ -1,128 +0,0 @@
-function MakePromise (asap) {
- function Promise(fn) {
- if (typeof this !== 'object' || typeof fn !== 'function') throw new TypeError();
- this._state = null;
- this._value = null;
- this._deferreds = []
-
- doResolve(fn, resolve.bind(this), reject.bind(this));
- }
-
- function handle(deferred) {
- var me = this;
- if (this._state === null) {
- this._deferreds.push(deferred);
- return
- }
- asap(function() {
- var cb = me._state ? deferred.onFulfilled : deferred.onRejected
- if (typeof cb !== 'function') {
- (me._state ? deferred.resolve : deferred.reject)(me._value);
- return;
- }
- var ret;
- try {
- ret = cb(me._value);
- }
- catch (e) {
- deferred.reject(e);
- return;
- }
- deferred.resolve(ret);
- })
- }
-
- function resolve(newValue) {
- try { //Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
- if (newValue === this) throw new TypeError();
- if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
- var then = newValue.then;
- if (typeof then === 'function') {
- doResolve(then.bind(newValue), resolve.bind(this), reject.bind(this));
- return;
- }
- }
- this._state = true;
- this._value = newValue;
- finale.call(this);
- } catch (e) { reject.call(this, e); }
- }
-
- function reject(newValue) {
- this._state = false;
- this._value = newValue;
- finale.call(this);
- }
-
- function finale() {
- for (var i = 0, len = this._deferreds.length; i < len; i++) {
- handle.call(this, this._deferreds[i]);
- }
- this._deferreds = null;
- }
-
- /**
- * Take a potentially misbehaving resolver function and make sure
- * onFulfilled and onRejected are only called once.
- *
- * Makes no guarantees about asynchrony.
- */
- function doResolve(fn, onFulfilled, onRejected) {
- var done = false;
- try {
- fn(function (value) {
- if (done) return;
- done = true;
- onFulfilled(value);
- }, function (reason) {
- if (done) return;
- done = true;
- onRejected(reason);
- })
- } catch (ex) {
- if (done) return;
- done = true;
- onRejected(ex);
- }
- }
-
- Promise.prototype['catch'] = function (onRejected) {
- return this.then(null, onRejected);
- };
-
- Promise.prototype.then = function(onFulfilled, onRejected) {
- var me = this;
- return new Promise(function(resolve, reject) {
- handle.call(me, {
- onFulfilled: onFulfilled,
- onRejected: onRejected,
- resolve: resolve,
- reject: reject
- });
- })
- };
-
- Promise.resolve = function (value) {
- if (value && typeof value === 'object' && value.constructor === Promise) {
- return value;
- }
-
- return new Promise(function (resolve) {
- resolve(value);
- });
- };
-
- Promise.reject = function (value) {
- return new Promise(function (resolve, reject) {
- reject(value);
- });
- };
-
-
- return Promise;
-}
-
-if (typeof module !== 'undefined') {
- module.exports = MakePromise;
-}
-

Powered by Google App Engine
This is Rietveld 408576698