"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/bluebird/js/main/bind.js" (7 Feb 2017, 2012 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 "use strict";
    2 module.exports = function(Promise, INTERNAL, tryConvertToPromise) {
    3 var rejectThis = function(_, e) {
    4     this._reject(e);
    5 };
    6 
    7 var targetRejected = function(e, context) {
    8     context.promiseRejectionQueued = true;
    9     context.bindingPromise._then(rejectThis, rejectThis, null, this, e);
   10 };
   11 
   12 var bindingResolved = function(thisArg, context) {
   13     if (this._isPending()) {
   14         this._resolveCallback(context.target);
   15     }
   16 };
   17 
   18 var bindingRejected = function(e, context) {
   19     if (!context.promiseRejectionQueued) this._reject(e);
   20 };
   21 
   22 Promise.prototype.bind = function (thisArg) {
   23     var maybePromise = tryConvertToPromise(thisArg);
   24     var ret = new Promise(INTERNAL);
   25     ret._propagateFrom(this, 1);
   26     var target = this._target();
   27 
   28     ret._setBoundTo(maybePromise);
   29     if (maybePromise instanceof Promise) {
   30         var context = {
   31             promiseRejectionQueued: false,
   32             promise: ret,
   33             target: target,
   34             bindingPromise: maybePromise
   35         };
   36         target._then(INTERNAL, targetRejected, ret._progress, ret, context);
   37         maybePromise._then(
   38             bindingResolved, bindingRejected, ret._progress, ret, context);
   39     } else {
   40         ret._resolveCallback(target);
   41     }
   42     return ret;
   43 };
   44 
   45 Promise.prototype._setBoundTo = function (obj) {
   46     if (obj !== undefined) {
   47         this._bitField = this._bitField | 131072;
   48         this._boundTo = obj;
   49     } else {
   50         this._bitField = this._bitField & (~131072);
   51     }
   52 };
   53 
   54 Promise.prototype._isBound = function () {
   55     return (this._bitField & 131072) === 131072;
   56 };
   57 
   58 Promise.bind = function (thisArg, value) {
   59     var maybePromise = tryConvertToPromise(thisArg);
   60     var ret = new Promise(INTERNAL);
   61 
   62     ret._setBoundTo(maybePromise);
   63     if (maybePromise instanceof Promise) {
   64         maybePromise._then(function() {
   65             ret._resolveCallback(value);
   66         }, ret._reject, ret._progress, ret, null);
   67     } else {
   68         ret._resolveCallback(value);
   69     }
   70     return ret;
   71 };
   72 };