Skip to content

Instantly share code, notes, and snippets.

@Nek

Nek/bundle.js

Created Feb 5, 2014
Embed
What would you like to do?
transpiled code
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var wrapGenerator = require('regeneratorify/runtime').wrapGenerator;
wrapGenerator.mark(listen);
function listen(el, evType) {
return wrapGenerator(function listen$($ctx) {
while (1) switch ($ctx.next) {
case 0:
if (!true) {
$ctx.next = 5;
break;
}
$ctx.next = 3;
return function(cb) {
var fire = function(ev) {
el.removeEventListener(evType, fire);
cb(null, ev);
}
el.addEventListener(evType, fire);
}
case 3:
$ctx.next = 0;
break;
case 5:
case "end":
return $ctx.stop();
}
}, this);
}
var gens = require('gens');
function go(gen) {
gens(gen)(function(err) { if (err) throw err; });
}
go(wrapGenerator.mark(function() {
var clicks;
return wrapGenerator(function($ctx) {
while (1) switch ($ctx.next) {
case 0:
clicks = listen(document.getElementById('search'), 'click');
while (true)
console.log(clicks.next().value);
case 2:
case "end":
return $ctx.stop();
}
}, this);
}));
},{"gens":44,"regeneratorify/runtime":50}],2:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function(Promise, Promise$_CreatePromiseArray, PromiseArray) {
var SomePromiseArray = require("./some_promise_array.js")(PromiseArray);
var ASSERT = require("./assert.js");
function Promise$_Any(promises, useBound, caller) {
var ret = Promise$_CreatePromiseArray(
promises,
SomePromiseArray,
caller,
useBound === true && promises._isBound()
? promises._boundTo
: void 0
);
var promise = ret.promise();
if (promise.isRejected()) {
return promise;
}
ret.setHowMany(1);
ret.setUnwrap();
ret.init();
return promise;
}
Promise.any = function Promise$Any(promises) {
return Promise$_Any(promises, false, Promise.any);
};
Promise.prototype.any = function Promise$any() {
return Promise$_Any(this, true, this.any);
};
};
},{"./assert.js":3,"./some_promise_array.js":36}],3:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = (function(){
var AssertionError = (function() {
function AssertionError(a) {
this.constructor$(a);
this.message = a;
this.name = "AssertionError";
}
AssertionError.prototype = new Error();
AssertionError.prototype.constructor = AssertionError;
AssertionError.prototype.constructor$ = Error;
return AssertionError;
})();
return function assert(boolExpr, message) {
if (boolExpr === true) return;
var ret = new AssertionError(message);
if (Error.captureStackTrace) {
Error.captureStackTrace(ret, assert);
}
if (console && console.error) {
console.error(ret.stack + "");
}
throw ret;
};
})();
},{}],4:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
var ASSERT = require("./assert.js");
var schedule = require("./schedule.js");
var Queue = require("./queue.js");
var errorObj = require("./util.js").errorObj;
var tryCatch1 = require("./util.js").tryCatch1;
function Async() {
this._isTickUsed = false;
this._length = 0;
this._lateBuffer = new Queue();
this._functionBuffer = new Queue(25000 * 3);
var self = this;
this.consumeFunctionBuffer = function Async$consumeFunctionBuffer() {
self._consumeFunctionBuffer();
};
}
Async.prototype.haveItemsQueued = function Async$haveItemsQueued() {
return this._length > 0;
};
Async.prototype.invokeLater = function Async$invokeLater(fn, receiver, arg) {
this._lateBuffer.push(fn, receiver, arg);
this._queueTick();
};
Async.prototype.invoke = function Async$invoke(fn, receiver, arg) {
var functionBuffer = this._functionBuffer;
functionBuffer.push(fn, receiver, arg);
this._length = functionBuffer.length();
this._queueTick();
};
Async.prototype._consumeFunctionBuffer =
function Async$_consumeFunctionBuffer() {
var functionBuffer = this._functionBuffer;
while(functionBuffer.length() > 0) {
var fn = functionBuffer.shift();
var receiver = functionBuffer.shift();
var arg = functionBuffer.shift();
fn.call(receiver, arg);
}
this._reset();
this._consumeLateBuffer();
};
Async.prototype._consumeLateBuffer = function Async$_consumeLateBuffer() {
var buffer = this._lateBuffer;
while(buffer.length() > 0) {
var fn = buffer.shift();
var receiver = buffer.shift();
var arg = buffer.shift();
var res = tryCatch1(fn, receiver, arg);
if (res === errorObj) {
this._queueTick();
throw res.e;
}
}
};
Async.prototype._queueTick = function Async$_queue() {
if (!this._isTickUsed) {
schedule(this.consumeFunctionBuffer);
this._isTickUsed = true;
}
};
Async.prototype._reset = function Async$_reset() {
this._isTickUsed = false;
this._length = 0;
};
module.exports = new Async();
},{"./assert.js":3,"./queue.js":29,"./schedule.js":32,"./util.js":40}],5:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
var Promise = require("./promise.js")();
module.exports = Promise;
},{"./promise.js":21}],6:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function(Promise) {
Promise.prototype.call = function Promise$call(propertyName) {
var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
return this._then(function(obj) {
return obj[propertyName].apply(obj, args);
},
void 0,
void 0,
void 0,
void 0,
this.call
);
};
function Promise$getter(obj) {
var prop = typeof this === "string"
? this
: ("" + this);
return obj[prop];
}
Promise.prototype.get = function Promise$get(propertyName) {
return this._then(
Promise$getter,
void 0,
void 0,
propertyName,
void 0,
this.get
);
};
};
},{}],7:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function(Promise, INTERNAL) {
var errors = require("./errors.js");
var async = require("./async.js");
var ASSERT = require("./assert.js");
var CancellationError = errors.CancellationError;
var SYNC_TOKEN = {};
Promise.prototype._cancel = function Promise$_cancel() {
if (!this.isCancellable()) return this;
var parent;
if ((parent = this._cancellationParent) !== void 0) {
parent.cancel(SYNC_TOKEN);
return;
}
var err = new CancellationError();
this._attachExtraTrace(err);
this._rejectUnchecked(err);
};
Promise.prototype.cancel = function Promise$cancel(token) {
if (!this.isCancellable()) return this;
if (token === SYNC_TOKEN) {
this._cancel();
return this;
}
async.invokeLater(this._cancel, this, void 0);
return this;
};
Promise.prototype.cancellable = function Promise$cancellable() {
if (this._cancellable()) return this;
this._setCancellable();
this._cancellationParent = void 0;
return this;
};
Promise.prototype.uncancellable = function Promise$uncancellable() {
var ret = new Promise(INTERNAL);
ret._setTrace(this.uncancellable, this);
ret._follow(this);
ret._unsetCancellable();
if (this._isBound()) ret._setBoundTo(this._boundTo);
return ret;
};
Promise.prototype.fork =
function Promise$fork(didFulfill, didReject, didProgress) {
var ret = this._then(didFulfill, didReject, didProgress,
void 0, void 0, this.fork);
ret._setCancellable();
ret._cancellationParent = void 0;
return ret;
};
};
},{"./assert.js":3,"./async.js":4,"./errors.js":11}],8:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function() {
var ASSERT = require("./assert.js");
var inherits = require("./util.js").inherits;
var defineProperty = require("./es5.js").defineProperty;
var rignore = new RegExp(
"\\b(?:[\\w.]*Promise(?:Array|Spawn)?\\$_\\w+|" +
"tryCatch(?:1|2|Apply)|new \\w*PromiseArray|" +
"\\w*PromiseArray\\.\\w*PromiseArray|" +
"setTimeout|CatchFilter\\$_\\w+|makeNodePromisified|processImmediate|" +
"process._tickCallback|nextTick|Async\\$\\w+)\\b"
);
var rtraceline = null;
var formatStack = null;
var areNamesMangled = false;
function formatNonError(obj) {
var str;
if (typeof obj === "function") {
str = "[function " +
(obj.name || "anonymous") +
"]";
}
else {
str = obj.toString();
var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
if (ruselessToString.test(str)) {
try {
var newStr = JSON.stringify(obj);
str = newStr;
}
catch(e) {
}
}
if (str.length === 0) {
str = "(empty array)";
}
}
return ("(<" + snip(str) + ">, no stack trace)");
}
function snip(str) {
var maxChars = 41;
if (str.length < maxChars) {
return str;
}
return str.substr(0, maxChars - 3) + "...";
}
function CapturedTrace(ignoreUntil, isTopLevel) {
if (!areNamesMangled) {
}
this.captureStackTrace(ignoreUntil, isTopLevel);
}
inherits(CapturedTrace, Error);
CapturedTrace.prototype.captureStackTrace =
function CapturedTrace$captureStackTrace(ignoreUntil, isTopLevel) {
captureStackTrace(this, ignoreUntil, isTopLevel);
};
CapturedTrace.possiblyUnhandledRejection =
function CapturedTrace$PossiblyUnhandledRejection(reason) {
if (typeof console === "object") {
var message;
if (typeof reason === "object" || typeof reason === "function") {
var stack = reason.stack;
message = "Possibly unhandled " + formatStack(stack, reason);
}
else {
message = "Possibly unhandled " + String(reason);
}
if (typeof console.error === "function" ||
typeof console.error === "object") {
console.error(message);
}
else if (typeof console.log === "function" ||
typeof console.error === "object") {
console.log(message);
}
}
};
areNamesMangled = CapturedTrace.prototype.captureStackTrace.name !==
"CapturedTrace$captureStackTrace";
CapturedTrace.combine = function CapturedTrace$Combine(current, prev) {
var curLast = current.length - 1;
for (var i = prev.length - 1; i >= 0; --i) {
var line = prev[i];
if (current[curLast] === line) {
current.pop();
curLast--;
}
else {
break;
}
}
current.push("From previous event:");
var lines = current.concat(prev);
var ret = [];
for (var i = 0, len = lines.length; i < len; ++i) {
if ((rignore.test(lines[i]) ||
(i > 0 && !rtraceline.test(lines[i])) &&
lines[i] !== "From previous event:")
) {
continue;
}
ret.push(lines[i]);
}
return ret;
};
CapturedTrace.isSupported = function CapturedTrace$IsSupported() {
return typeof captureStackTrace === "function";
};
var captureStackTrace = (function stackDetection() {
if (typeof Error.stackTraceLimit === "number" &&
typeof Error.captureStackTrace === "function") {
rtraceline = /^\s*at\s*/;
formatStack = function(stack, error) {
if (typeof stack === "string") return stack;
if (error.name !== void 0 &&
error.message !== void 0) {
return error.name + ". " + error.message;
}
return formatNonError(error);
};
var captureStackTrace = Error.captureStackTrace;
return function CapturedTrace$_captureStackTrace(
receiver, ignoreUntil) {
captureStackTrace(receiver, ignoreUntil);
};
}
var err = new Error();
if (!areNamesMangled && typeof err.stack === "string" &&
typeof "".startsWith === "function" &&
(err.stack.startsWith("stackDetection@")) &&
stackDetection.name === "stackDetection") {
defineProperty(Error, "stackTraceLimit", {
writable: true,
enumerable: false,
configurable: false,
value: 25
});
rtraceline = /@/;
var rline = /[@\n]/;
formatStack = function(stack, error) {
if (typeof stack === "string") {
return (error.name + ". " + error.message + "\n" + stack);
}
if (error.name !== void 0 &&
error.message !== void 0) {
return error.name + ". " + error.message;
}
return formatNonError(error);
};
return function captureStackTrace(o, fn) {
var name = fn.name;
var stack = new Error().stack;
var split = stack.split(rline);
var i, len = split.length;
for (i = 0; i < len; i += 2) {
if (split[i] === name) {
break;
}
}
split = split.slice(i + 2);
len = split.length - 2;
var ret = "";
for (i = 0; i < len; i += 2) {
ret += split[i];
ret += "@";
ret += split[i + 1];
ret += "\n";
}
o.stack = ret;
};
}
else {
formatStack = function(stack, error) {
if (typeof stack === "string") return stack;
if ((typeof error === "object" ||
typeof error === "function") &&
error.name !== void 0 &&
error.message !== void 0) {
return error.name + ". " + error.message;
}
return formatNonError(error);
};
return null;
}
})();
return CapturedTrace;
};
},{"./assert.js":3,"./es5.js":13,"./util.js":40}],9:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function(NEXT_FILTER) {
var util = require("./util.js");
var tryCatch1 = util.tryCatch1;
var errorObj = util.errorObj;
var keys = require("./es5.js").keys;
function CatchFilter(instances, callback, promise) {
this._instances = instances;
this._callback = callback;
this._promise = promise;
}
function CatchFilter$_safePredicate(predicate, e) {
var safeObject = {};
var retfilter = tryCatch1(predicate, safeObject, e);
if (retfilter === errorObj) return retfilter;
var safeKeys = keys(safeObject);
if (safeKeys.length) {
errorObj.e = new TypeError(
"Catch filter must inherit from Error "
+ "or be a simple predicate function");
return errorObj;
}
return retfilter;
}
CatchFilter.prototype.doFilter = function CatchFilter$_doFilter(e) {
var cb = this._callback;
var promise = this._promise;
var boundTo = promise._isBound() ? promise._boundTo : void 0;
for (var i = 0, len = this._instances.length; i < len; ++i) {
var item = this._instances[i];
var itemIsErrorType = item === Error ||
(item != null && item.prototype instanceof Error);
if (itemIsErrorType && e instanceof item) {
var ret = tryCatch1(cb, boundTo, e);
if (ret === errorObj) {
NEXT_FILTER.e = ret.e;
return NEXT_FILTER;
}
return ret;
} else if (typeof item === "function" && !itemIsErrorType) {
var shouldHandle = CatchFilter$_safePredicate(item, e);
if (shouldHandle === errorObj) {
this._promise._attachExtraTrace(errorObj.e);
e = errorObj.e;
break;
} else if (shouldHandle) {
var ret = tryCatch1(cb, boundTo, e);
if (ret === errorObj) {
NEXT_FILTER.e = ret.e;
return NEXT_FILTER;
}
return ret;
}
}
}
NEXT_FILTER.e = e;
return NEXT_FILTER;
};
return CatchFilter;
};
},{"./es5.js":13,"./util.js":40}],10:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
var util = require("./util.js");
var ASSERT = require("./assert.js");
var isPrimitive = util.isPrimitive;
var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
module.exports = function(Promise) {
var returner = function Promise$_returner() {
return this;
};
var thrower = function Promise$_thrower() {
throw this;
};
var wrapper = function Promise$_wrapper(value, action) {
if (action === 1) {
return function Promise$_thrower() {
throw value;
};
}
else if (action === 2) {
return function Promise$_returner() {
return value;
};
}
};
Promise.prototype["return"] =
Promise.prototype.thenReturn =
function Promise$thenReturn(value) {
if (wrapsPrimitiveReceiver && isPrimitive(value)) {
return this._then(
wrapper(value, 2),
void 0,
void 0,
void 0,
void 0,
this.thenReturn
);
}
return this._then(returner, void 0, void 0,
value, void 0, this.thenReturn);
};
Promise.prototype["throw"] =
Promise.prototype.thenThrow =
function Promise$thenThrow(reason) {
if (wrapsPrimitiveReceiver && isPrimitive(reason)) {
return this._then(
wrapper(reason, 1),
void 0,
void 0,
void 0,
void 0,
this.thenThrow
);
}
return this._then(thrower, void 0, void 0,
reason, void 0, this.thenThrow);
};
};
},{"./assert.js":3,"./util.js":40}],11:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
var global = require("./global.js");
var Objectfreeze = require("./es5.js").freeze;
var util = require("./util.js");
var inherits = util.inherits;
var isObject = util.isObject;
var notEnumerableProp = util.notEnumerableProp;
var Error = global.Error;
function isStackAttached(val) {
return (val & 1) > 0;
}
function isHandled(val) {
return (val & 2) > 0;
}
function withStackAttached(val) {
return (val | 1);
}
function withHandledMarked(val) {
return (val | 2);
}
function withHandledUnmarked(val) {
return (val & (~2));
}
function ensureNotHandled(reason) {
var field;
if (isObject(reason) &&
((field = reason["__promiseHandled__"]) !== void 0)) {
reason["__promiseHandled__"] = withHandledUnmarked(field);
}
return reason;
}
function markAsOriginatingFromRejection(e) {
try {
notEnumerableProp(e, "isAsync", true);
}
catch(ignore) {}
}
function originatesFromRejection(e) {
if (e == null) return false;
return ((e instanceof RejectionError) ||
e["isAsync"] === true);
}
function attachDefaultState(obj) {
try {
notEnumerableProp(obj, "__promiseHandled__", 0);
return true;
}
catch(e) {
return false;
}
}
function isError(obj) {
return obj instanceof Error;
}
function canAttach(obj) {
if (isError(obj)) {
var handledState = obj["__promiseHandled__"];
if (handledState === void 0) {
return attachDefaultState(obj);
}
return !isStackAttached(handledState);
}
return false;
}
function subError(nameProperty, defaultMessage) {
function SubError(message) {
if (!(this instanceof SubError)) return new SubError(message);
this.message = typeof message === "string" ? message : defaultMessage;
this.name = nameProperty;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
inherits(SubError, Error);
return SubError;
}
var TypeError = global.TypeError;
if (typeof TypeError !== "function") {
TypeError = subError("TypeError", "type error");
}
var RangeError = global.RangeError;
if (typeof RangeError !== "function") {
RangeError = subError("RangeError", "range error");
}
var CancellationError = subError("CancellationError", "cancellation error");
var TimeoutError = subError("TimeoutError", "timeout error");
function RejectionError(message) {
this.name = "RejectionError";
this.message = message;
this.cause = message;
this.isAsync = true;
if (message instanceof Error) {
this.message = message.message;
this.stack = message.stack;
}
else if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
inherits(RejectionError, Error);
var key = "__BluebirdErrorTypes__";
var errorTypes = global[key];
if (!errorTypes) {
errorTypes = Objectfreeze({
CancellationError: CancellationError,
TimeoutError: TimeoutError,
RejectionError: RejectionError
});
notEnumerableProp(global, key, errorTypes);
}
module.exports = {
Error: Error,
TypeError: TypeError,
RangeError: RangeError,
CancellationError: errorTypes.CancellationError,
RejectionError: errorTypes.RejectionError,
TimeoutError: errorTypes.TimeoutError,
originatesFromRejection: originatesFromRejection,
markAsOriginatingFromRejection: markAsOriginatingFromRejection,
attachDefaultState: attachDefaultState,
ensureNotHandled: ensureNotHandled,
withHandledUnmarked: withHandledUnmarked,
withHandledMarked: withHandledMarked,
withStackAttached: withStackAttached,
isStackAttached: isStackAttached,
isHandled: isHandled,
canAttach: canAttach
};
},{"./es5.js":13,"./global.js":17,"./util.js":40}],12:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function(Promise) {
var TypeError = require('./errors.js').TypeError;
function apiRejection(msg) {
var error = new TypeError(msg);
var ret = Promise.rejected(error);
var parent = ret._peekContext();
if (parent != null) {
parent._attachExtraTrace(error);
}
return ret;
}
return apiRejection;
};
},{"./errors.js":11}],13:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
var isES5 = (function(){
"use strict";
return this === void 0;
})();
if (isES5) {
module.exports = {
freeze: Object.freeze,
defineProperty: Object.defineProperty,
keys: Object.keys,
getPrototypeOf: Object.getPrototypeOf,
isArray: Array.isArray,
isES5: isES5
};
}
else {
var has = {}.hasOwnProperty;
var str = {}.toString;
var proto = {}.constructor.prototype;
function ObjectKeys(o) {
var ret = [];
for (var key in o) {
if (has.call(o, key)) {
ret.push(key);
}
}
return ret;
}
function ObjectDefineProperty(o, key, desc) {
o[key] = desc.value;
return o;
}
function ObjectFreeze(obj) {
return obj;
}
function ObjectGetPrototypeOf(obj) {
try {
return Object(obj).constructor.prototype;
}
catch (e) {
return proto;
}
}
function ArrayIsArray(obj) {
try {
return str.call(obj) === "[object Array]";
}
catch(e) {
return false;
}
}
module.exports = {
isArray: ArrayIsArray,
keys: ObjectKeys,
defineProperty: ObjectDefineProperty,
freeze: ObjectFreeze,
getPrototypeOf: ObjectGetPrototypeOf,
isES5: isES5
};
}
},{}],14:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function(Promise) {
var ASSERT = require("./assert.js");
var isArray = require("./util.js").isArray;
function Promise$_filter(booleans) {
var values = this._settledValue;
var len = values.length;
var ret = new Array(len);
var j = 0;
for (var i = 0; i < len; ++i) {
if (booleans[i]) ret[j++] = values[i];
}
ret.length = j;
return ret;
}
var ref = {ref: null};
Promise.filter = function Promise$Filter(promises, fn) {
return Promise.map(promises, fn, ref)
._then(Promise$_filter, void 0, void 0,
ref.ref, void 0, Promise.filter);
};
Promise.prototype.filter = function Promise$filter(fn) {
return this.map(fn, ref)
._then(Promise$_filter, void 0, void 0,
ref.ref, void 0, this.filter);
};
};
},{"./assert.js":3,"./util.js":40}],15:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
module.exports = function(Promise, NEXT_FILTER) {
var util = require("./util.js");
var ensureNotHandled = require("./errors.js").ensureNotHandled;
var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
var isPrimitive = util.isPrimitive;
var thrower = util.thrower;
function returnThis() {
return this;
}
function throwThis() {
ensureNotHandled(this);
throw this;
}
function makeReturner(r) {
return function Promise$_returner() {
return r;
};
}
function makeThrower(r) {
return function Promise$_thrower() {
ensureNotHandled(r);
throw r;
};
}
function promisedFinally(ret, reasonOrValue, isFulfilled) {
var useConstantFunction =
wrapsPrimitiveReceiver && isPrimitive(reasonOrValue);
if (isFulfilled) {
return ret._then(
useConstantFunction
? returnThis
: makeReturner(reasonOrValue),
thrower, void 0, reasonOrValue, void 0, promisedFinally);
}
else {
return ret._then(
useConstantFunction
? throwThis
: makeThrower(reasonOrValue),
thrower, void 0, reasonOrValue, void 0, promisedFinally);
}
}
function finallyHandler(reasonOrValue) {
var promise = this.promise;
var handler = this.handler;
var ret = promise._isBound()
? handler.call(promise._boundTo)
: handler();
if (ret !== void 0) {
var maybePromise = Promise._cast(ret, finallyHandler, void 0);
if (Promise.is(maybePromise)) {
return promisedFinally(maybePromise, reasonOrValue,
promise.isFulfilled());
}
}
if (promise.isRejected()) {
ensureNotHandled(reasonOrValue);
NEXT_FILTER.e = reasonOrValue;
return NEXT_FILTER;
}
else {
return reasonOrValue;
}
}
Promise.prototype.lastly = Promise.prototype["finally"] =
function Promise$finally(handler) {
if (typeof handler !== "function") return this.then();
var promiseAndHandler = {
promise: this,
handler: handler
};
return this._then(finallyHandler, finallyHandler, void 0,
promiseAndHandler, void 0, this.lastly);
};
};
},{"./errors.js":11,"./util.js":40}],16:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function(Promise, apiRejection, INTERNAL) {
var PromiseSpawn = require("./promise_spawn.js")(Promise, INTERNAL);
var errors = require("./errors.js");
var TypeError = errors.TypeError;
Promise.coroutine = function Promise$Coroutine(generatorFunction) {
if (typeof generatorFunction !== "function") {
throw new TypeError("generatorFunction must be a function");
}
var PromiseSpawn$ = PromiseSpawn;
return function anonymous() {
var generator = generatorFunction.apply(this, arguments);
var spawn = new PromiseSpawn$(void 0, void 0, anonymous);
spawn._generator = generator;
spawn._next(void 0);
return spawn.promise();
};
};
Promise.spawn = function Promise$Spawn(generatorFunction) {
if (typeof generatorFunction !== "function") {
return apiRejection("generatorFunction must be a function");
}
var spawn = new PromiseSpawn(generatorFunction, this, Promise.spawn);
var ret = spawn.promise();
spawn._run(Promise.spawn);
return ret;
};
};
},{"./errors.js":11,"./promise_spawn.js":25}],17:[function(require,module,exports){
(function (process,global){/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = (function(){
if (typeof this !== "undefined") {
return this;
}
if (typeof process !== "undefined" &&
typeof global !== "undefined" &&
typeof process.execPath === "string") {
return global;
}
if (typeof window !== "undefined" &&
typeof document !== "undefined" &&
typeof navigator !== "undefined" && navigator !== null &&
typeof navigator.appName === "string") {
if(window.wrappedJSObject !== undefined){
return window.wrappedJSObject;
}
return window;
}
})();
}).call(this,require("/Users/Nek/Projects/regenerator-async/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"/Users/Nek/Projects/regenerator-async/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":41}],18:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function(
Promise, Promise$_CreatePromiseArray, PromiseArray, apiRejection) {
var ASSERT = require("./assert.js");
function Promise$_mapper(values) {
var fn = this;
var receiver = void 0;
if (typeof fn !== "function") {
receiver = fn.receiver;
fn = fn.fn;
}
var shouldDefer = false;
var ret = new Array(values.length);
if (receiver === void 0) {
for (var i = 0, len = values.length; i < len; ++i) {
var value = fn(values[i], i, len);
if (!shouldDefer) {
var maybePromise = Promise._cast(value,
Promise$_mapper, void 0);
if (maybePromise instanceof Promise) {
if (maybePromise.isFulfilled()) {
ret[i] = maybePromise._settledValue;
continue;
}
else {
shouldDefer = true;
}
value = maybePromise;
}
}
ret[i] = value;
}
}
else {
for (var i = 0, len = values.length; i < len; ++i) {
var value = fn.call(receiver, values[i], i, len);
if (!shouldDefer) {
var maybePromise = Promise._cast(value,
Promise$_mapper, void 0);
if (maybePromise instanceof Promise) {
if (maybePromise.isFulfilled()) {
ret[i] = maybePromise._settledValue;
continue;
}
else {
shouldDefer = true;
}
value = maybePromise;
}
}
ret[i] = value;
}
}
return shouldDefer
? Promise$_CreatePromiseArray(ret, PromiseArray,
Promise$_mapper, void 0).promise()
: ret;
}
function Promise$_Map(promises, fn, useBound, caller, ref) {
if (typeof fn !== "function") {
return apiRejection("fn must be a function");
}
if (useBound === true && promises._isBound()) {
fn = {
fn: fn,
receiver: promises._boundTo
};
}
var ret = Promise$_CreatePromiseArray(
promises,
PromiseArray,
caller,
useBound === true && promises._isBound()
? promises._boundTo
: void 0
).promise();
if (ref !== void 0) {
ref.ref = ret;
}
return ret._then(
Promise$_mapper,
void 0,
void 0,
fn,
void 0,
caller
);
}
Promise.prototype.map = function Promise$map(fn, ref) {
return Promise$_Map(this, fn, true, this.map, ref);
};
Promise.map = function Promise$Map(promises, fn, ref) {
return Promise$_Map(promises, fn, false, Promise.map, ref);
};
};
},{"./assert.js":3}],19:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function(Promise) {
var util = require("./util.js");
var async = require("./async.js");
var ASSERT = require("./assert.js");
var tryCatch2 = util.tryCatch2;
var tryCatch1 = util.tryCatch1;
var errorObj = util.errorObj;
function thrower(r) {
throw r;
}
function Promise$_successAdapter(val, receiver) {
var nodeback = this;
var ret = tryCatch2(nodeback, receiver, null, val);
if (ret === errorObj) {
async.invokeLater(thrower, void 0, ret.e);
}
}
function Promise$_errorAdapter(reason, receiver) {
var nodeback = this;
var ret = tryCatch1(nodeback, receiver, reason);
if (ret === errorObj) {
async.invokeLater(thrower, void 0, ret.e);
}
}
Promise.prototype.nodeify = function Promise$nodeify(nodeback) {
if (typeof nodeback == "function") {
this._then(
Promise$_successAdapter,
Promise$_errorAdapter,
void 0,
nodeback,
this._isBound() ? this._boundTo : null,
this.nodeify
);
}
return this;
};
};
},{"./assert.js":3,"./async.js":4,"./util.js":40}],20:[function(require,module,exports){
/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function(Promise, isPromiseArrayProxy) {
var ASSERT = require("./assert.js");
var util = require("./util.js");
var async = require("./async.js");
var tryCatch1 = util.tryCatch1;
var errorObj = util.errorObj;
Promise.prototype.progressed = function Promise$progressed(handler) {
return this._then(void 0, void 0, handler,
void 0, void 0, this.progressed);
};
Promise.prototype._progress = function Promise$_progress(progressValue) {
if (this._isFollowingOrFulfilledOrRejected()) return;
this._progressUnchecked(progressValue);
};
Promise.prototype._progressHandlerAt =
function Promise$_progressHandlerAt(index) {
if (index === 0) return this._progressHandler0;
return this[index + 2 - 5];
};
Promise.prototype._doProgressWith =
function Promise$_doProgressWith(progression) {
var progressValue = progression.value;
var handler = progression.handler;
var promise = progression.promise;
var receiver = progression.receiver;
this._pushContext();
var ret = tryCatch1(handler, receiver, progressValue);
this._popContext();
if (ret === errorObj) {
if (ret.e != null &&
ret.e.name === "StopProgressPropagation") {
ret.e["__promiseHandled__"] = 2;
}
else {
promise._attachExtraTrace(ret.e);
promise._progress(ret.e);
}
}
else if (Promise.is(ret)) {
ret._then(promise._progress, null, null, promise, void 0,
this._progress);
}
else {
promise._progress(ret);
}
};
Promise.prototype._progressUnchecked =
function Promise$_progressUnchecked(progressValue) {
if (!this.isPending()) return;
var len = this._length();
for (var i = 0; i < len; i += 5) {
var handler = this._progressHandlerAt(i);
var promise = this._promiseAt(i);
if (!Promise.is(promise)) {
var receiver = this._receiverAt(i);
if (typeof handler === "function") {
handler.call(receiver, progressValue, promise);
}
else if (Promise.is(receiver) && receiver._isProxied()) {
receiver._progressUnchecked(progressValue);
}
else if (isPromiseArrayProxy(receiver, promise)) {
receiver._promiseProgressed(progressValue, promise);
}
continue;
}
if (typeof handler === "function") {
async.invoke(this._doProgressWith, this, {
handler: handler,
promise: promise,
receiver: this._receiverAt(i),
value: progressValue
});
}
else {
async.invoke(promise._progress, promise, progressValue);
}
}
};
};
},{"./assert.js":3,"./async.js":4,"./util.js":40}],21:[function(require,module,exports){
(function (process){/**
* Copyright (c) 2014 Petka Antonov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:</p>
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
"use strict";
module.exports = function() {
var global = require("./global.js");
var ASSERT = require("./assert.js");
var util = require("./util.js");
var async = require("./async.js");
var errors = require("./errors.js");
var INTERNAL = function(){};
var APPLY = {};
var NEXT_FILTER = {e: null};
var PromiseArray = require("./promise_array.js")(Promise, INTERNAL);
var CapturedTrace = require("./captured_trace.js")();
var CatchFilter = require("./catch_filter.js")(NEXT_FILTER);
var PromiseResolver = require("./promise_resolver.js");
var isArray = util.isArray;
var notEnumerableProp = util.notEnumerableProp;
var isObject = util.isObject;
var ensurePropertyExpansion = util.ensurePropertyExpansion;
var errorObj = util.errorObj;
var tryCatch1 = util.tryCatch1;
var tryCatch2 = util.tryCatch2;
var tryCatchApply = util.tryCatchApply;
var RangeError = errors.RangeError;
var TypeError = errors.TypeError;
var CancellationError = errors.CancellationError;
var TimeoutError = errors.TimeoutError;
var RejectionError = errors.RejectionError;
var originatesFromRejection = errors.originatesFromRejection;
var markAsOriginatingFromRejection = errors.markAsOriginatingFromRejection;
var ensureNotHandled = errors.ensureNotHandled;
var withHandledMarked = errors.withHandledMarked;
var withStackAttached = errors.withStackAttached;
var isStackAttached = errors.isStackAttached;
var isHandled = errors.isHandled;
var canAttach = errors.canAttach;
var thrower = util.thrower;
var apiRejection = require("./errors_api_rejection")(Promise);
var makeSelfResolutionError = function Promise$_makeSelfResolutionError() {
return new TypeError("circular promise resolution chain");
};
function isPromise(obj) {
if (obj === void 0) return false;
return obj instanceof Promise;
}
function isPromiseArrayProxy(receiver, promiseSlotValue) {
if (receiver instanceof PromiseArray) {
return promiseSlotValue >= 0;
}
return false;
}
function Promise(resolver) {
if (typeof resolver !== "function") {
throw new TypeError("the promise constructor requires a resolver function");
}
if (this.constructor !== Promise) {
throw new TypeError("the promise constructor cannot be invoked directly");
}
this._bitField = 0;
this._fulfillmentHandler0 = void 0;
this._rejectionHandler0 = void 0;
this._promise0 = void 0;
this._receiver0 = void 0;
this._settledValue = void 0;
this._boundTo = void 0;
if (resolver !== INTERNAL) this._resolveFromResolver(resolver);
}
Promise.prototype.bind = function Promise$bind(thisArg) {
var ret = new Promise(INTERNAL);
if (debugging) ret._setTrace(this.bind, this);
ret._follow(this);
ret._setBoundTo(thisArg);
if (this._cancellable()) {
ret._setCancellable();
ret._cancellationParent = this;
}
return ret;
};
Promise.prototype.toString = function Promise$toString() {
return "[object Promise]";
};
Promise.prototype.caught = Promise.prototype["catch"] =
function Promise$catch(fn) {
var len = arguments.length;
if (len > 1) {
var catchInstances = new Array(len - 1),
j = 0, i;
for (i = 0; i < len - 1; ++i) {
var item = arguments[i];
if (typeof item === "function") {
catchInstances[j++] = item;
}
else {
var catchFilterTypeError =
new TypeError(
"A catch filter must be an error constructor "
+ "or a filter function");
this._attachExtraTrace(catchFilterTypeError);
async.invoke(this._reject, this, catchFilterTypeError);
return;
}
}
catchInstances.length = j;
fn = arguments[i];
this._resetTrace(this.caught);
var catchFilter = new CatchFilter(catchInstances, fn, this);
return this._then(void 0, catchFilter.doFilter, void 0,
catchFilter, void 0, this.caught);
}
return this._then(void 0, fn, void 0, void 0, void 0, this.caught);
};
Promise.prototype.then =
function Promise$then(didFulfill, didReject, didProgress) {
return this._then(didFulfill, didReject, didProgress,
void 0, void 0, this.then);
};
Promise.prototype.done =
function Promise$done(didFulfill, didReject, didProgress) {
var promise = this._then(didFulfill, didReject, didProgress,
void 0, void 0, this.done);
promise._setIsFinal();
};
Promise.prototype.spread = function Promise$spread(didFulfill, didReject) {
return this._then(didFulfill, didReject, void 0,
APPLY, void 0, this.spread);
};
Promise.prototype.isFulfilled = function Promise$isFulfilled() {
return (this._bitField & 268435456) > 0;
};
Promise.prototype.isRejected = function Promise$isRejected() {
return (this._bitField & 134217728) > 0;
};
Promise.prototype.isPending = function Promise$isPending() {
return !this.isResolved();
};
Promise.prototype.isResolved = function Promise$isResolved() {
return (this._bitField & 402653184) > 0;
};
Promise.prototype.isCancellable = function Promise$isCancellable() {
return !this.isResolved() &&
this._cancellable();
};
Promise.prototype.toJSON = function Promise$toJSON() {
var ret = {
isFulfilled: false,
isRejected: false,
fulfillmentValue: void 0,
rejectionReason: void 0
};
if (this.isFulfilled()) {
ret.fulfillmentValue = this._settledValue;
ret.isFulfilled = true;
}
else if (this.isRejected()) {
ret.rejectionReason = this._settledValue;
ret.isRejected = true;
}
return ret;
};
Promise.prototype.all = function Promise$all() {
return Promise$_all(this, true, this.all);
};
Promise.is = isPromise;
function Promise$_all(promises, useBound, caller) {
return Promise$_CreatePromiseArray(
promises,
PromiseArray,
caller,
useBound === true && promises._isBound()
? promises._boundTo
: void 0
).promise();
}
Promise.all = function Promise$All(promises) {
return Promise$_all(promises, false, Promise.all);
};
Promise.join = function Promise$Join() {
var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
return Promise$_CreatePromiseArray(
args, PromiseArray, Promise.join, void 0).promise();
};
Promise.resolve = Promise.fulfilled =
function Promise$Resolve(value, caller) {
var ret = new Promise(INTERNAL);
if (debugging) ret._setTrace(typeof caller === "function"
? caller
: Promise.resolve, void 0);
if (ret._tryFollow(value)) {
return ret;
}
ret._cleanValues();
ret._setFulfilled();
ret._settledValue = value;
return ret;
};
Promise.reject = Promise.rejected = function Promise$Reject(reason) {
var ret = new Promise(INTERNAL);
if (debugging) ret._setTrace(Promise.reject, void 0);
markAsOriginatingFromRejection(reason);
ret._cleanValues();
ret._setRejected();
ret._settledValue = reason;
return ret;
};
Promise.prototype.error = function Promise$_error(fn) {
return this.caught(originatesFromRejection, fn);
};
Promise.prototype._resolveFromSyncValue =
function Promise$_resolveFromSyncValue(value, caller) {
if (value === errorObj) {
this._cleanValues();
this._setRejected();
this._settledValue = value.e;
}
else {
var maybePromise = Promise._cast(value, caller, void 0);
if (maybePromise instanceof Promise) {
this._follow(maybePromise);
}
else {
this._cleanValues();
this._setFulfilled();
this._settledValue = value;
}
}
};
Promise.method = function Promise$_Method(fn) {
if (typeof fn !== "function") {
throw new TypeError("fn must be a function");
}
return function Promise$_method() {
var value;
switch(arguments.length) {
case 0: value = tryCatch1(fn, this, void 0); break;
case 1: value = tryCatch1(fn, this, arguments[0]); break;
case 2: value = tryCatch2(fn, this, arguments[0], arguments[1]); break;
default:
var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
value = tryCatchApply(fn, args, this); break;
}
var ret = new Promise(INTERNAL);
if (debugging) ret._setTrace(Promise$_method, void 0);
ret._resolveFromSyncValue(value, Promise$_method);
return ret;
};
};
Promise.attempt = Promise["try"] = function Promise$_Try(fn, args, ctx) {
if (typeof fn !== "function") {
return apiRejection("fn must be a function");
}
var value = isArray(args)
? tryCatchApply(fn, args, ctx)
: tryCatch1(fn, ctx, args);
var ret = new Promise(INTERNAL);
if (debugging) ret._setTrace(Promise.attempt, void 0);
ret._resolveFromSyncValue(value, Promise.attempt);
return ret;
};
Promise.defer = Promise.pending = function Promise$Defer(caller) {
var promise = new Promise(INTERNAL);
if (debugging) promise._setTrace(typeof caller === "function"
? caller : Promise.defer, void 0);
return new PromiseResolver(promise);
};
Promise.bind = function Promise$Bind(thisArg) {
var ret = new Promise(INTERNAL);
if (debugging) ret._setTrace(Promise.bind, void 0);
ret._setFulfilled();
ret._setBoundTo(thisArg);
return ret;
};
Promise.cast = function Promise$_Cast(obj, caller) {
if (typeof caller !== "function") {
caller = Promise.cast;
}
var ret = Promise._cast(obj, caller, void 0);
if (!(ret instanceof Promise)) {
return Promise.resolve(ret, caller);
}
return ret;
};
Promise.onPossiblyUnhandledRejection =
function Promise$OnPossiblyUnhandledRejection(fn) {
if (typeof fn === "function") {
CapturedTrace.possiblyUnhandledRejection = fn;
}
else {
CapturedTrace.possiblyUnhandledRejection = void 0;
}
};
var debugging = false || !!(
typeof process !== "undefined" &&
typeof process.execPath === "string" &&
typeof process.env === "object" &&
(process.env["BLUEBIRD_DEBUG"] ||
process.env["NODE_ENV"] === "development")
);
Promise.longStackTraces = function Promise$LongStackTraces() {
if (async.haveItemsQueued() &&
debugging === false
) {
throw new Error("cannot enable long stack traces after promises have been created");
}
debugging = CapturedTrace.isSupported();
};
Promise.hasLongStackTraces = function Promise$HasLongStackTraces() {
return debugging && CapturedTrace.isSupported();
};
Promise.prototype._setProxyHandlers =
function Promise$_setProxyHandlers(receiver, promiseSlotValue) {
var index = this._length();
if (index >= 4194303 - 5) {
index = 0;
this._setLength(0);
}
if (index === 0) {
this._promise0 = promiseSlotValue;
this._receiver0 = receiver;
}
else {
var i = index - 5;
this[i + 3] = promiseSlotValue;
this[i + 4] = receiver;
this[i + 0] =
this[i + 1] =
this[i + 2] = void 0;
}
this._setLength(index + 5);
};
Promise.prototype._proxyPromiseArray =
function Promise$_proxyPromiseArray(promiseArray, index) {
this._setProxyHandlers(promiseArray, index);
};
Promise.prototype._proxyPromise = function Promise$_proxyPromise(promise) {
promise._setProxied();
this._setProxyHandlers(promise, -1);
};
Promise.prototype._then =
function Promise$_then(
didFulfill,
didReject,
didProgress,
receiver,
internalData,
caller
) {
var haveInternalData = internalData !== void 0;
var ret = haveInternalData ? internalData : new Promise(INTERNAL);
if (debugging && !haveInternalData) {
var haveSameContext = this._peekContext() === this._traceParent;
ret._traceParent = haveSameContext ? this._traceParent : this;
ret._setTrace(typeof caller === "function"
? caller
: this._then, this);
}
if (!haveInternalData && this._isBound()) {
ret._setBoundTo(this._boundTo);
}
var callbackIndex =
this._addCallbacks(didFulfill, didReject, didProgress, ret, receiver);
if (!haveInternalData && this._cancellable()) {
ret._setCancellable();
ret._cancellationParent = this;
}
if (this.isResolved()) {
async.invoke(this._queueSettleAt, this, callbackIndex);
}
return ret;
};
Promise.prototype._length = function Promise$_length() {
return this._bitField & 4194303;
};
Promise.prototype._isFollowingOrFulfilledOrRejected =
function Promise$_isFollowingOrFulfilledOrRejected() {
return (this._bitField & 939524096) > 0;
};
Promise.prototype._isFollowing = function Promise$_isFollowing() {
return (this._bitField & 536870912) === 536870912;
};
Promise.prototype._setLength = function Promise$_setLength(len) {
this._bitField = (this._bitField & -4194304) |
(len & 4194303);
};
Promise.prototype._cancellable = function Promise$_cancellable() {
return (this._bitField & 67108864) > 0;
};
Promise.prototype._setFulfilled = function Promise$_setFulfilled() {
this._bitField = this._bitField | 268435456;
};
Promise.prototype._setRejected = function Promise$_setRejected() {
this._bitField = this._bitField | 134217728;
};
Promise.prototype._setFollowing = function Promise$_setFollowing() {
this._bitField = this._bitField | 536870912;
};
Promise.prototype._setIsFinal = function Promise$_setIsFinal() {
this._bitField = this._bitField | 33554432;
};
Promise.prototype._isFinal = function Promise$_isFinal() {
return (this._bitField & 33554432) > 0;
};
Promise.prototype._setCancellable = function Promise$_setCancellable() {
this._bitField = this._bitField | 67108864;
};
Promise.prototype._unsetCancellable = function Promise$_unsetCancellable() {
this._bitField = this._bitField & (~67108864);
};
Promise.prototype._receiverAt = function Promise$_receiverAt(index) {
var ret;
if (index === 0) {
ret = this._receiver0;
}
else {
ret = this[index + 4 - 5];
}
if (this._isBound() && ret === void 0) {
return this._boundTo;
}
return ret;
};
Promise.prototype._promiseAt = function Promise$_promiseAt(index) {
if (index === 0) return this._promise0;
return this[index + 3 - 5];
};
Promise.prototype._fulfillmentHandlerAt =
function Promise$_fulfillmentHandlerAt(index) {
if (index === 0) return this._fulfillmentHandler0;
return this[index + 0 - 5];
};
Promise.prototype._rejectionHandlerAt =
function Promise$_rejectionHandlerAt(index) {
if (index === 0) return this._rejectionHandler0;
return this[index + 1 - 5];
};
Promise.prototype._unsetAt = function Promise$_unsetAt(index) {
if (index === 0) {
this._fulfillmentHandler0 =
this._rejectionHandler0 =
this._progressHandler0 =
this._promise0 =
this._receiver0 = void 0;
}
else {
this[index - 5 + 0] =
this[index - 5 + 1] =
this[index - 5 + 2] =
this[index - 5 + 3] =
this[index - 5 + 4] = void 0;
}
};
Promise.prototype._resolveFromResolver =
function Promise$_resolveFromResolver(resolver) {
var promise = this;
var localDebugging = debugging;
if (localDebugging) {
this._setTrace(this._resolveFromResolver, void 0);
this._pushContext();
}
function Promise$_resolver(val) {
if (promise._tryFollow(val)) {
return;
}
promise._fulfill(val);
}
function Promise$_rejecter(val) {
promise._attachExtraTrace(val);
markAsOriginatingFromRejection(val);
promise._reject(val);
}
var r = tryCatch2(resolver, void 0, Promise$_resolver, Promise$_rejecter);
if (localDebugging) this._popContext();
if (r !== void 0 && r === errorObj) {
promise._reject(r.e);
}
};
Promise.prototype._addCallbacks = function Promise$_addCallbacks(
fulfill,
reject,
progress,
promise,
receiver
) {
var index = this._length();
if (index >= 4194303 - 5) {
index = 0;
this._setLength(0);
}
if (index === 0) {
this._promise0 = promise;
if (receiver !== void 0) this._receiver0 = receiver;
if (typeof fulfill === "function") this._fulfillmentHandler0 = fulfill;
if (typeof reject === "function") this._rejectionHandler0 = reject;
if (typeof progress === "function") this._progressHandler0 = progress;
}
else {
var i = index - 5;
this[i + 3] = promise;
this[i + 4] = receiver;
this[i + 0] = typeof fulfill === "function"
? fulfill : void 0;
this[i + 1] = typeof reject === "function"
? reject : void 0;
this[i + 2] = typeof progress === "function"
? progress : void 0;
}
this._setLength(index + 5);
return index;
};
Promise.prototype._setBoundTo = function Promise$_setBoundTo(obj) {
if (obj !== void 0) {
this._bitField = this._bitField | 8388608;
this._boundTo = obj;
}
else {
this._bitField = this._bitField & (~8388608);
}
};
Promise.prototype._isBound = function Promise$_isBound() {
return (this._bitField & 8388608) === 8388608;
};
Promise.prototype._spreadSlowCase =
function Promise$_spreadSlowCase(targetFn, promise, values, boundTo) {
var promiseForAll =
Promise$_CreatePromiseArray
(values, PromiseArray, this._spreadSlowCase, boundTo)
.promise()
._then(function() {
return targetFn.apply(boundTo, arguments);
}, void 0, void 0, APPLY, void 0, this._spreadSlowCase);
promise._follow(promiseForAll);
};
Promise.prototype._markHandled = function Promise$_markHandled(value) {
if( typeof value === "object" &&
value !== null) {
var handledState = value["__promiseHandled__"];
if (handledState === void 0) {
notEnumerableProp(value, "__promiseHandled__", 2);
}
else {
value["__promiseHandled__"] =
withHandledMarked(handledState);
}
}
};
Promise.prototype._callSpread =
function Promise$_callSpread(handler, promise, value, localDebugging) {
var boundTo = this._isBound() ? this._boundTo : void 0;
if (isArray(value)) {
var caller = this._settlePromiseFromHandler;
for (var i = 0, len = value.length; i < len; ++i) {
if (isPromise(Promise._cast(value[i], caller, void 0))) {
this._spreadSlowCase(handler, promise, value, boundTo);
return;
}
}
}
if (localDebugging) promise._pushContext();
return tryCatchApply(handler, value, boundTo);
};
Promise.prototype._callHandler =
function Promise$_callHandler(
handler, receiver, promise, value, localDebugging) {
var x;
if (receiver === APPLY && !this.isRejected()) {
x = this._callSpread(handler, promise, value, localDebugging);
}
else {
if (localDebugging) promise._pushContext();
x = tryCatch1(handler, receiver, value);
}
if (localDebugging) promise._popContext();
return x;
};
Promise.prototype._settlePromiseFromHandler =
function Promise$_settlePromiseFromHandler(
handler, receiver, value, promise
) {
if (!isPromise(promise)) {
handler.call(receiver, value, promise);
return;
}
if (this.isRejected()) this._markHandled(value);
var localDebugging = debugging;
var x = this._callHandler(handler, receiver,
promise, value, localDebugging);
if (promise._isFollowing()) return;
if (x === errorObj || x === promise || x === NEXT_FILTER) {
var err = x === promise
? makeSelfResolutionError()
: ensureNotHandled(x.e);
if (x !== NEXT_FILTER) promise._attachExtraTrace(err);
promise._rejectUnchecked(err);
}
else {
var castValue = Promise._cast(x,
localDebugging ? this._settlePromiseFromHandler : void 0,
promise);
if (isPromise(castValue)) {
promise._follow(castValue);
if (castValue._cancellable()) {
promise._cancellationParent = castValue;
promise._setCancellable();
}
}
else {
promise._fulfillUnchecked(x);
}
}
};
Promise.prototype._follow =
function Promise$_follow(promise) {
this._setFollowing();
if (promise.isPending()) {
if (promise._cancellable() ) {
this._cancellationParent = promise;
this._setCancellable();
}
promise._proxyPromise(this);
}
else if (promise.isFulfilled()) {
this._fulfillUnchecked(promise._settledValue);
}
else {
this._rejectUnchecked(promise._settledValue);
}
if (debugging &&
promise._traceParent == null) {
promise._traceParent = this;
}
};
Promise.prototype._tryFollow =
function Promise$_tryFollow(value) {
if (this._isFollowingOrFulfilledOrRejected() ||
value === this) {
return false;
}
var maybePromise = Promise._cast(value, this._tryFollow, void 0);
if (!isPromise(maybePromise)) {
return false;
}
this._follow(maybePromise);
return true;
};
Promise.prototype._resetTrace = function Promise$_resetTrace(caller) {
if (debugging) {
var context = this._peekContext();
var isTopLevel = context === void 0;
this._trace = new CapturedTrace(
typeof caller === "function"
? caller
: this._resetTrace,
isTopLevel
);
}
};
Promise.prototype._setTrace = function Promise$_setTrace(caller, parent) {
if (debugging) {
var context = this._peekContext();
this._traceParent = context;
var isTopLevel = context === void 0;
if (parent !== void 0 &&
parent._traceParent === context) {
this._trace = parent._trace;
}
else {
this._trace = new CapturedTrace(
typeof caller === "function"
? caller
: this._setTrace,
isTopLevel
);
}
}
return this;
};
Promise.prototype._attachExtraTrace =
function Promise$_attachExtraTrace(error) {
if (debugging &&
canAttach(error)) {
var promise = this;
var stack = error.stack;
stack = typeof stack === "string"
? stack.split("\n") : [];
var headerLineCount = 1;
while(promise != null &&
promise._trace != null) {
stack = CapturedTrace.combine(
stack,
promise._trace.stack.split("\n")
);
promise = promise._traceParent;
}
var max = Error.stackTraceLimit + headerLineCount;
var len = stack.length;
if (len > max) {
stack.length = max;
}
if (stack.length <= headerLineCount) {
error.stack = "(No stack trace)";
}
else {
error.stack = stack.join("\n");
}
error["__promiseHandled__"] =
withStackAttached(error["__promiseHandled__"]);
}
};
Promise.prototype._notifyUnhandledRejection =
function Promise$_notifyUnhandledRejection(reason) {
if (!isHandled(reason["__promiseHandled__"])) {
reason["__promiseHandled__"] =
withHandledMarked(reason["__promiseHandled__"]);
CapturedTrace.possiblyUnhandledRejection(reason, this);
}
};
Promise.prototype._unhandledRejection =
function Promise$_unhandledRejection(reason) {
if (!isHandled(reason["__promiseHandled__"])) {
async.invokeLater(this._notifyUnhandledRejection, this, reason);
}
};
Promise.prototype._cleanValues = function Promise$_cleanValues() {
if (this._cancellable()) {
this._cancellationParent = void 0;
}
};
Promise.prototype._fulfill = function Promise$_fulfill(value) {
if (this._isFollowingOrFulfilledOrRejected()) return;
this._fulfillUnchecked(value);
};
Promise.prototype._reject = function Promise$_reject(reason) {
if (this._isFollowingOrFulfilledOrRejected()) return;
this._rejectUnchecked(reason);
};
Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) {
var handler = this.isFulfilled()
? this._fulfillmentHandlerAt(index)
: this._rejectionHandlerAt(index);
var value = this._settledValue;
var receiver = this._receiverAt(index);
var promise = this._promiseAt(index);
if (typeof handler === "function") {
this._settlePromiseFromHandler(handler, receiver, value, promise);
}
else {
var done = false;
var isFulfilled = this.isFulfilled();
if (receiver !== void 0) {
if (receiver instanceof Promise &&
receiver._isProxied()) {
receiver._unsetProxied();
if (isFulfilled) receiver._fulfillUnchecked(value);
else receiver._rejectUnchecked(value);
done = true;
}
else if (isPromiseArrayProxy(receiver, promise)) {
if (isFulfilled) receiver._promiseFulfilled(value, promise);
else receiver._promiseRejected(value, promise);
done = true;
}
}
if (!done) {
if (isFulfilled) promise._fulfill(value);
else promise._reject(value);
}
}
if (index >= 256) {
this._queueGC();
}
};
Promise.prototype._isProxied = function Promise$_isProxied() {
return (this._bitField & 4194304) === 4194304;
};
Promise.prototype._setProxied = function Promise$_setProxied() {
this._bitField = this._bitField | 4194304;
};
Promise.prototype._unsetProxied = function Promise$_unsetProxied() {
this._bitField = this._bitField & (~4194304);
};
Promise.prototype._isGcQueued = function Promise$_isGcQueued() {
return (this._bitField & -1073741824) === -1073741824;
};
Promise.prototype._setGcQueued = function Promise$_setGcQueued() {
this._bitField = this._bitField | -1073741824;
};
Promise.prototype._unsetGcQueued = function Promise$_unsetGcQueued() {
this._bitField = this._bitField & (~-1073741824);
};
Promise.prototype._queueGC = function Promise$_queueGC() {
if (this._isGcQueued()) return;
this._setGcQueued();
async.invokeLater(this._gc, this, void 0);
};
Promise.prototype._gc = function Promise$gc() {
var len = this._length();
this._unsetAt(0);
for (var i = 0; i < len; i++) {
delete this[i];
}
this._setLength(0);
this._unsetGcQueued();
};
Promise.prototype._queueSettleAt = function Promise$_queueSettleAt(index) {
async.invoke(this._settlePromiseAt, this, index);
};
Promise.prototype._fulfillUnchecked =
function Promise$_fulfillUnchecked(value) {
if (!this.isPending()) return;
if (value === this) {
var err = makeSelfResolutionError();
this._attachExtraTrace(err);
return this._rejectUnchecked(err);
}
this._cleanValues();
this._setFulfilled();
this._settledValue = value;
var len = this._length();
if (len > 0) {
async.invoke(this._fulfillPromises, this, len);
}
};
Promise.prototype._fulfillPromises = function Promise$_fulfillPromises(len) {
len = this._length();
for (var i = 0; i < len; i+= 5) {
this._settlePromiseAt(i);
}
};
Promise.prototype._rejectUnchecked =
function Promise$_rejectUnchecked(reason) {
if (!this.isPending()) return;
if (reason === this) {
var err = makeSelfResolutionError();
this._attachExtraTrace(err);
return this._rejectUnchecked(err);
}
this._cleanValues();
this._setRejected();
this._settledValue = reason;
if (this._isFinal()) {
async.invokeLater(thrower, void 0, reason);
return;
}
var len = this._length();
if (len > 0) {
async.invoke(this._rejectPromises, this, len);
}
else {
this._ensurePossibleRejectionHandled(reason);
}
};