commit ed33c6b71235b4146cd69e45e67d9b75fed41c79
parent d70e9cf41b96863b16f792343ca18cd4b927b341
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 29 Oct 2015 02:23:22 -0400
Update Bluebird to 2.10.2
Diffstat:
| M | resource/bluebird.js | | | 713 | ++++++++++++++++++++++++++++--------------------------------------------------- |
1 file changed, 249 insertions(+), 464 deletions(-)
diff --git a/resource/bluebird.js b/resource/bluebird.js
@@ -1,14 +1,14 @@
/* @preserve
* The MIT License (MIT)
*
- * Copyright (c) 2014 Petka Antonov
+ * Copyright (c) 2013-2015 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>
+ * furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
@@ -23,11 +23,11 @@
*
*/
/**
- * bluebird build version 2.9.27
+ * bluebird build version 2.10.2
* Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, cancel, using, filter, any, each, timers
*/
!function(e){
- //
+ //
// Added by Zotero
//
EXPORTED_SYMBOLS = ["Promise"];
@@ -99,13 +99,13 @@
// Ignore some errors during tests
if (e.message && e.message.indexOf(' -- ignore') != -1) return;
- self.debug('Unhandled rejection:\n\n' + e.stack);
+ self.debug('Possibly unhandled rejection:\n\n' + e.stack);
throw e;
});
return;
-
- if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Promise=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof _dereq_=="function"&&_dereq_;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
+
+ if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Promise=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof _dereq_=="function"&&_dereq_;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
module.exports = function(Promise) {
var SomePromiseArray = Promise._SomePromiseArray;
@@ -173,8 +173,6 @@ Async.prototype.throwLater = function(fn, arg) {
arg = fn;
fn = function () { throw arg; };
}
- var domain = this._getDomain();
- if (domain !== undefined) fn = domain.bind(fn);
if (typeof setTimeout !== "undefined") {
setTimeout(function() {
fn(arg);
@@ -188,73 +186,18 @@ Async.prototype.throwLater = function(fn, arg) {
}
};
-Async.prototype._getDomain = function() {};
-
-if (!true) {
-if (util.isNode) {
- var EventsModule = _dereq_("events");
-
- var domainGetter = function() {
- var domain = process.domain;
- if (domain === null) return undefined;
- return domain;
- };
-
- if (EventsModule.usingDomains) {
- Async.prototype._getDomain = domainGetter;
- } else {
- var descriptor =
- Object.getOwnPropertyDescriptor(EventsModule, "usingDomains");
-
- if (descriptor) {
- if (!descriptor.configurable) {
- process.on("domainsActivated", function() {
- Async.prototype._getDomain = domainGetter;
- });
- } else {
- var usingDomains = false;
- Object.defineProperty(EventsModule, "usingDomains", {
- configurable: false,
- enumerable: true,
- get: function() {
- return usingDomains;
- },
- set: function(value) {
- if (usingDomains || !value) return;
- usingDomains = true;
- Async.prototype._getDomain = domainGetter;
- util.toFastProperties(process);
- process.emit("domainsActivated");
- }
- });
- }
- }
- }
-}
-}
-
function AsyncInvokeLater(fn, receiver, arg) {
- var domain = this._getDomain();
- if (domain !== undefined) fn = domain.bind(fn);
this._lateQueue.push(fn, receiver, arg);
this._queueTick();
}
function AsyncInvoke(fn, receiver, arg) {
- var domain = this._getDomain();
- if (domain !== undefined) fn = domain.bind(fn);
this._normalQueue.push(fn, receiver, arg);
this._queueTick();
}
function AsyncSettlePromises(promise) {
- var domain = this._getDomain();
- if (domain !== undefined) {
- var fn = domain.bind(promise._settlePromises);
- this._normalQueue.push(fn, promise, undefined);
- } else {
- this._normalQueue._pushOne(promise);
- }
+ this._normalQueue._pushOne(promise);
this._queueTick();
}
@@ -263,13 +206,18 @@ if (!util.hasDevTools) {
Async.prototype.invoke = AsyncInvoke;
Async.prototype.settlePromises = AsyncSettlePromises;
} else {
+ if (schedule.isStatic) {
+ schedule = function(fn) { setTimeout(fn, 0); };
+ }
Async.prototype.invokeLater = function (fn, receiver, arg) {
if (this._trampolineEnabled) {
AsyncInvokeLater.call(this, fn, receiver, arg);
} else {
- setTimeout(function() {
- fn.call(receiver, arg);
- }, 100);
+ this._schedule(function() {
+ setTimeout(function() {
+ fn.call(receiver, arg);
+ }, 100);
+ });
}
};
@@ -277,9 +225,9 @@ if (!util.hasDevTools) {
if (this._trampolineEnabled) {
AsyncInvoke.call(this, fn, receiver, arg);
} else {
- setTimeout(function() {
+ this._schedule(function() {
fn.call(receiver, arg);
- }, 0);
+ });
}
};
@@ -287,16 +235,14 @@ if (!util.hasDevTools) {
if (this._trampolineEnabled) {
AsyncSettlePromises.call(this, promise);
} else {
- setTimeout(function() {
+ this._schedule(function() {
promise._settlePromises();
- }, 0);
+ });
}
};
}
Async.prototype.invokeFirst = function (fn, receiver, arg) {
- var domain = this._getDomain();
- if (domain !== undefined) fn = domain.bind(fn);
this._normalQueue.unshift(fn, receiver, arg);
this._queueTick();
};
@@ -334,7 +280,7 @@ Async.prototype._reset = function () {
module.exports = new Async();
module.exports.firstLineError = firstLineError;
-},{"./queue.js":28,"./schedule.js":31,"./util.js":38,"events":39}],3:[function(_dereq_,module,exports){
+},{"./queue.js":28,"./schedule.js":31,"./util.js":38}],3:[function(_dereq_,module,exports){
"use strict";
module.exports = function(Promise, INTERNAL, tryConvertToPromise) {
var rejectThis = function(_, e) {
@@ -347,7 +293,6 @@ var targetRejected = function(e, context) {
};
var bindingResolved = function(thisArg, context) {
- this._setBoundTo(thisArg);
if (this._isPending()) {
this._resolveCallback(context.target);
}
@@ -362,6 +307,8 @@ Promise.prototype.bind = function (thisArg) {
var ret = new Promise(INTERNAL);
ret._propagateFrom(this, 1);
var target = this._target();
+
+ ret._setBoundTo(maybePromise);
if (maybePromise instanceof Promise) {
var context = {
promiseRejectionQueued: false,
@@ -373,7 +320,6 @@ Promise.prototype.bind = function (thisArg) {
maybePromise._then(
bindingResolved, bindingRejected, ret._progress, ret, context);
} else {
- ret._setBoundTo(thisArg);
ret._resolveCallback(target);
}
return ret;
@@ -396,13 +342,12 @@ Promise.bind = function (thisArg, value) {
var maybePromise = tryConvertToPromise(thisArg);
var ret = new Promise(INTERNAL);
+ ret._setBoundTo(maybePromise);
if (maybePromise instanceof Promise) {
- maybePromise._then(function(thisArg) {
- ret._setBoundTo(thisArg);
+ maybePromise._then(function() {
ret._resolveCallback(value);
}, ret._reject, ret._progress, ret, null);
} else {
- ret._setBoundTo(thisArg);
ret._resolveCallback(value);
}
return ret;
@@ -982,7 +927,8 @@ var captureStackTrace = (function stackDetection() {
catch(e) {
hasStackAfterThrow = ("stack" in e);
}
- if (!("stack" in err) && hasStackAfterThrow) {
+ if (!("stack" in err) && hasStackAfterThrow &&
+ typeof Error.stackTraceLimit === "number") {
stackFramePattern = v8stackFramePattern;
formatStack = v8stackFormatter;
return function captureStackTrace(o) {
@@ -1124,7 +1070,7 @@ function safePredicate(predicate, e) {
CatchFilter.prototype.doFilter = function (e) {
var cb = this._callback;
var promise = this._promise;
- var boundTo = promise._boundTo;
+ var boundTo = promise._boundValue();
for (var i = 0, len = this._instances.length; i < len; ++i) {
var item = this._instances[i];
var itemIsErrorType = item === Error ||
@@ -1202,6 +1148,7 @@ return createContext;
},{}],10:[function(_dereq_,module,exports){
"use strict";
module.exports = function(Promise, CapturedTrace) {
+var getDomain = Promise._getDomain;
var async = _dereq_("./async.js");
var Warning = _dereq_("./errors.js").Warning;
var util = _dereq_("./util.js");
@@ -1212,11 +1159,19 @@ var debugging = false || (util.isNode &&
(!!process.env["BLUEBIRD_DEBUG"] ||
process.env["NODE_ENV"] === "development"));
+if (util.isNode && process.env["BLUEBIRD_DEBUG"] == 0) debugging = false;
+
if (debugging) {
async.disableTrampolineIfNecessary();
}
+Promise.prototype._ignoreRejections = function() {
+ this._unsetRejectionIsUnhandled();
+ this._bitField = this._bitField | 16777216;
+};
+
Promise.prototype._ensurePossibleRejectionHandled = function () {
+ if ((this._bitField & 16777216) !== 0) return;
this._setRejectionIsUnhandled();
async.invokeLater(this._notifyUnhandledRejection, this, undefined);
};
@@ -1315,11 +1270,17 @@ Promise.prototype._warn = function(message) {
};
Promise.onPossiblyUnhandledRejection = function (fn) {
- possiblyUnhandledRejection = typeof fn === "function" ? fn : undefined;
+ var domain = getDomain();
+ possiblyUnhandledRejection =
+ typeof fn === "function" ? (domain === null ? fn : domain.bind(fn))
+ : undefined;
};
Promise.onUnhandledRejectionHandled = function (fn) {
- unhandledRejectionHandled = typeof fn === "function" ? fn : undefined;
+ var domain = getDomain();
+ unhandledRejectionHandled =
+ typeof fn === "function" ? (domain === null ? fn : domain.bind(fn))
+ : undefined;
};
Promise.longStackTraces = function () {
@@ -1352,7 +1313,6 @@ return function() {
"use strict";
var util = _dereq_("./util.js");
var isPrimitive = util.isPrimitive;
-var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
module.exports = function(Promise) {
var returner = function () {
@@ -1383,7 +1343,7 @@ Promise.prototype["return"] =
Promise.prototype.thenReturn = function (value) {
if (value === undefined) return this.then(returnUndefined);
- if (wrapsPrimitiveReceiver && isPrimitive(value)) {
+ if (isPrimitive(value)) {
return this._then(
wrapper(value, 2),
undefined,
@@ -1391,6 +1351,8 @@ Promise.prototype.thenReturn = function (value) {
undefined,
undefined
);
+ } else if (value instanceof Promise) {
+ value._ignoreRejections();
}
return this._then(returner, undefined, undefined, value, undefined);
};
@@ -1399,7 +1361,7 @@ Promise.prototype["throw"] =
Promise.prototype.thenThrow = function (reason) {
if (reason === undefined) return this.then(throwUndefined);
- if (wrapsPrimitiveReceiver && isPrimitive(reason)) {
+ if (isPrimitive(reason)) {
return this._then(
wrapper(reason, 1),
undefined,
@@ -1639,7 +1601,6 @@ Promise.filter = function (promises, fn, options) {
"use strict";
module.exports = function(Promise, NEXT_FILTER, tryConvertToPromise) {
var util = _dereq_("./util.js");
-var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
var isPrimitive = util.isPrimitive;
var thrower = util.thrower;
@@ -1661,7 +1622,7 @@ function throw$(r) {
}
function promisedFinally(ret, reasonOrValue, isFulfilled) {
var then;
- if (wrapsPrimitiveReceiver && isPrimitive(reasonOrValue)) {
+ if (isPrimitive(reasonOrValue)) {
then = isFulfilled ? return$(reasonOrValue) : throw$(reasonOrValue);
} else {
then = isFulfilled ? returnThis : throwThis;
@@ -1674,7 +1635,7 @@ function finallyHandler(reasonOrValue) {
var handler = this.handler;
var ret = promise._isBound()
- ? handler.call(promise._boundTo)
+ ? handler.call(promise._boundValue())
: handler();
if (ret !== undefined) {
@@ -1699,7 +1660,7 @@ function tapHandler(value) {
var handler = this.handler;
var ret = promise._isBound()
- ? handler.call(promise._boundTo, value)
+ ? handler.call(promise._boundValue(), value)
: handler(value);
if (ret !== undefined) {
@@ -1990,6 +1951,7 @@ module.exports = function(Promise,
apiRejection,
tryConvertToPromise,
INTERNAL) {
+var getDomain = Promise._getDomain;
var async = _dereq_("./async.js");
var util = _dereq_("./util.js");
var tryCatch = util.tryCatch;
@@ -2000,7 +1962,8 @@ var EMPTY_ARRAY = [];
function MappingPromiseArray(promises, fn, limit, _filter) {
this.constructor$(promises);
this._promise._captureStackTrace();
- this._callback = fn;
+ var domain = getDomain();
+ this._callback = domain === null ? fn : domain.bind(fn);
this._preservedValues = _filter === INTERNAL
? new Array(this.length())
: null;
@@ -2035,7 +1998,7 @@ MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
if (preservedValues !== null) preservedValues[index] = value;
var callback = this._callback;
- var receiver = this._promise._boundTo;
+ var receiver = this._promise._boundValue();
this._promise._pushContext();
var ret = tryCatch(callback).call(receiver, value, index, length);
this._promise._popContext();
@@ -2173,7 +2136,8 @@ var errorObj = util.errorObj;
function spreadAdapter(val, nodeback) {
var promise = this;
if (!util.isArray(val)) return successAdapter.call(promise, val, nodeback);
- var ret = tryCatch(nodeback).apply(promise._boundTo, [null].concat(val));
+ var ret =
+ tryCatch(nodeback).apply(promise._boundValue(), [null].concat(val));
if (ret === errorObj) {
async.throwLater(ret.e);
}
@@ -2181,7 +2145,7 @@ function spreadAdapter(val, nodeback) {
function successAdapter(val, nodeback) {
var promise = this;
- var receiver = promise._boundTo;
+ var receiver = promise._boundValue();
var ret = val === undefined
? tryCatch(nodeback).call(receiver, null)
: tryCatch(nodeback).call(receiver, null, val);
@@ -2197,13 +2161,13 @@ function errorAdapter(reason, nodeback) {
newReason.cause = reason;
reason = newReason;
}
- var ret = tryCatch(nodeback).call(promise._boundTo, reason);
+ var ret = tryCatch(nodeback).call(promise._boundValue(), reason);
if (ret === errorObj) {
async.throwLater(ret.e);
}
}
-Promise.prototype.asCallback =
+Promise.prototype.asCallback =
Promise.prototype.nodeify = function (nodeback, options) {
if (typeof nodeback == "function") {
var adapter = successAdapter;
@@ -2312,7 +2276,24 @@ var reflect = function() {
var apiRejection = function(msg) {
return Promise.reject(new TypeError(msg));
};
+
var util = _dereq_("./util.js");
+
+var getDomain;
+if (util.isNode) {
+ getDomain = function() {
+ var ret = process.domain;
+ if (ret === undefined) ret = null;
+ return ret;
+ };
+} else {
+ getDomain = function() {
+ return null;
+ };
+}
+util.notEnumerableProp(Promise, "_getDomain", getDomain);
+
+var UNDEFINED_BINDING = {};
var async = _dereq_("./async.js");
var errors = _dereq_("./errors.js");
var TypeError = Promise.TypeError = errors.TypeError;
@@ -2511,8 +2492,12 @@ Promise.prototype._then = function (
if (!haveInternalData) ret._setIsMigrated();
}
- var callbackIndex =
- target._addCallbacks(didFulfill, didReject, didProgress, ret, receiver);
+ var callbackIndex = target._addCallbacks(didFulfill,
+ didReject,
+ didProgress,
+ ret,
+ receiver,
+ getDomain());
if (target._isResolved() && !target._isSettlePromisesQueued()) {
async.invoke(
@@ -2593,8 +2578,10 @@ Promise.prototype._receiverAt = function (index) {
? this._receiver0
: this[
index * 5 - 5 + 4];
- if (ret === undefined && this._isBound()) {
- return this._boundTo;
+ if (ret === UNDEFINED_BINDING) {
+ return undefined;
+ } else if (ret === undefined && this._isBound()) {
+ return this._boundValue();
}
return ret;
};
@@ -2617,6 +2604,20 @@ Promise.prototype._rejectionHandlerAt = function (index) {
: this[index * 5 - 5 + 1];
};
+Promise.prototype._boundValue = function() {
+ var ret = this._boundTo;
+ if (ret !== undefined) {
+ if (ret instanceof Promise) {
+ if (ret.isFulfilled()) {
+ return ret.value();
+ } else {
+ return undefined;
+ }
+ }
+ }
+ return ret;
+};
+
Promise.prototype._migrateCallbacks = function (follower, index) {
var fulfill = follower._fulfillmentHandlerAt(index);
var reject = follower._rejectionHandlerAt(index);
@@ -2624,7 +2625,8 @@ Promise.prototype._migrateCallbacks = function (follower, index) {
var promise = follower._promiseAt(index);
var receiver = follower._receiverAt(index);
if (promise instanceof Promise) promise._setIsMigrated();
- this._addCallbacks(fulfill, reject, progress, promise, receiver);
+ if (receiver === undefined) receiver = UNDEFINED_BINDING;
+ this._addCallbacks(fulfill, reject, progress, promise, receiver, null);
};
Promise.prototype._addCallbacks = function (
@@ -2632,7 +2634,8 @@ Promise.prototype._addCallbacks = function (
reject,
progress,
promise,
- receiver
+ receiver,
+ domain
) {
var index = this._length();
@@ -2644,20 +2647,34 @@ Promise.prototype._addCallbacks = function (
if (index === 0) {
this._promise0 = promise;
if (receiver !== undefined) this._receiver0 = receiver;
- if (typeof fulfill === "function" && !this._isCarryingStackTrace())
- this._fulfillmentHandler0 = fulfill;
- if (typeof reject === "function") this._rejectionHandler0 = reject;
- if (typeof progress === "function") this._progressHandler0 = progress;
+ if (typeof fulfill === "function" && !this._isCarryingStackTrace()) {
+ this._fulfillmentHandler0 =
+ domain === null ? fulfill : domain.bind(fulfill);
+ }
+ if (typeof reject === "function") {
+ this._rejectionHandler0 =
+ domain === null ? reject : domain.bind(reject);
+ }
+ if (typeof progress === "function") {
+ this._progressHandler0 =
+ domain === null ? progress : domain.bind(progress);
+ }
} else {
var base = index * 5 - 5;
this[base + 3] = promise;
this[base + 4] = receiver;
- if (typeof fulfill === "function")
- this[base + 0] = fulfill;
- if (typeof reject === "function")
- this[base + 1] = reject;
- if (typeof progress === "function")
- this[base + 2] = progress;
+ if (typeof fulfill === "function") {
+ this[base + 0] =
+ domain === null ? fulfill : domain.bind(fulfill);
+ }
+ if (typeof reject === "function") {
+ this[base + 1] =
+ domain === null ? reject : domain.bind(reject);
+ }
+ if (typeof progress === "function") {
+ this[base + 2] =
+ domain === null ? progress : domain.bind(progress);
+ }
}
this._setLength(index + 1);
return index;
@@ -2752,7 +2769,7 @@ Promise.prototype._settlePromiseFromHandler = function (
promise._pushContext();
var x;
if (receiver === APPLY && !this._isRejected()) {
- x = tryCatch(handler).apply(this._boundTo, value);
+ x = tryCatch(handler).apply(this._boundValue(), value);
} else {
x = tryCatch(handler).call(receiver, value);
}
@@ -2822,8 +2839,6 @@ Promise.prototype._settlePromiseAt = function (index) {
this._isCarryingStackTrace() ? this._getCarriedStackTrace() : undefined;
var value = this._settledValue;
var receiver = this._receiverAt(index);
-
-
this._clearCallbackDataAtIndex(index);
if (typeof handler === "function") {
@@ -2950,7 +2965,10 @@ Promise.prototype._settlePromises = function () {
}
};
-Promise._makeSelfResolutionError = makeSelfResolutionError;
+util.notEnumerableProp(Promise,
+ "_makeSelfResolutionError",
+ makeSelfResolutionError);
+
_dereq_("./progress.js")(Promise, PromiseArray);
_dereq_("./method.js")(Promise, INTERNAL, tryConvertToPromise, apiRejection);
_dereq_("./bind.js")(Promise, INTERNAL, tryConvertToPromise);
@@ -3085,7 +3103,7 @@ PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
if (maybePromise instanceof Promise) {
maybePromise = maybePromise._target();
if (isResolved) {
- maybePromise._unsetRejectionIsUnhandled();
+ maybePromise._ignoreRejections();
} else if (maybePromise._isPending()) {
maybePromise._proxyPromiseArray(this, i);
} else if (maybePromise._isFulfilled()) {
@@ -3284,12 +3302,21 @@ var canEvaluate = util.canEvaluate;
var TypeError = _dereq_("./errors").TypeError;
var defaultSuffix = "Async";
var defaultPromisified = {__isPromisified__: true};
-var noCopyPropsPattern =
- /^(?:length|name|arguments|caller|callee|prototype|__isPromisified__)$/;
-var defaultFilter = function(name, func) {
+var noCopyProps = [
+ "arity", "length",
+ "name",
+ "arguments",
+ "caller",
+ "callee",
+ "prototype",
+ "__isPromisified__"
+];
+var noCopyPropsPattern = new RegExp("^(?:" + noCopyProps.join("|") + ")$");
+
+var defaultFilter = function(name) {
return util.isIdentifier(name) &&
name.charAt(0) !== "_" &&
- !util.isClass(func);
+ name !== "constructor";
};
function propsFilter(key) {
@@ -3433,6 +3460,7 @@ function(callback, receiver, originalName, fn) {
"nodebackForPromise",
"tryCatch",
"errorObj",
+ "notEnumerableProp",
"INTERNAL","'use strict'; \n\
var ret = function (Parameters) { \n\
'use strict'; \n\
@@ -3450,7 +3478,7 @@ function(callback, receiver, originalName, fn) {
} \n\
return promise; \n\
}; \n\
- ret.__isPromisified__ = true; \n\
+ notEnumerableProp(ret, '__isPromisified__', true); \n\
return ret; \n\
"
.replace("Parameters", parameterDeclaration(newParameterCount))
@@ -3464,6 +3492,7 @@ function(callback, receiver, originalName, fn) {
nodebackForPromise,
util.tryCatch,
util.errorObj,
+ util.notEnumerableProp,
INTERNAL
);
};
@@ -3490,7 +3519,7 @@ function makeNodePromisifiedClosure(callback, receiver, _, fn) {
}
return promise;
}
- promisified.__isPromisified__ = true;
+ util.notEnumerableProp(promisified, "__isPromisified__", true);
return promisified;
}
@@ -3507,11 +3536,16 @@ function promisifyAll(obj, suffix, filter, promisifier) {
var key = methods[i];
var fn = methods[i+1];
var promisifiedKey = key + suffix;
- obj[promisifiedKey] = promisifier === makeNodePromisified
- ? makeNodePromisified(key, THIS, key, fn, suffix)
- : promisifier(fn, function() {
- return makeNodePromisified(key, THIS, key, fn, suffix);
- });
+ if (promisifier === makeNodePromisified) {
+ obj[promisifiedKey] =
+ makeNodePromisified(key, THIS, key, fn, suffix);
+ } else {
+ var promisified = promisifier(fn, function() {
+ return makeNodePromisified(key, THIS, key, fn, suffix);
+ });
+ util.notEnumerableProp(promisified, "__isPromisified__", true);
+ obj[promisifiedKey] = promisified;
+ }
}
util.toFastProperties(obj);
return obj;
@@ -3793,6 +3827,7 @@ module.exports = function(Promise,
apiRejection,
tryConvertToPromise,
INTERNAL) {
+var getDomain = Promise._getDomain;
var async = _dereq_("./async.js");
var util = _dereq_("./util.js");
var tryCatch = util.tryCatch;
@@ -3821,7 +3856,8 @@ function ReductionPromiseArray(promises, fn, accum, _each) {
}
}
if (!(isPromise || this._zerothIsAccum)) this._gotAccum = true;
- this._callback = fn;
+ var domain = getDomain();
+ this._callback = domain === null ? fn : domain.bind(fn);
this._accum = accum;
if (!rejected) async.invoke(init, this, undefined);
}
@@ -3875,7 +3911,7 @@ ReductionPromiseArray.prototype._promiseFulfilled = function (value, index) {
if (!gotAccum) return;
var callback = this._callback;
- var receiver = this._promise._boundTo;
+ var receiver = this._promise._boundValue();
var ret;
for (var i = this._reducingIndex; i < length; ++i) {
@@ -3947,7 +3983,10 @@ if (util.isNode && typeof MutationObserver === "undefined") {
schedule = util.isRecentNode
? function(fn) { GlobalSetImmediate.call(global, fn); }
: function(fn) { ProcessNextTick.call(process, fn); };
-} else if (typeof MutationObserver !== "undefined") {
+} else if ((typeof MutationObserver !== "undefined") &&
+ !(typeof window !== "undefined" &&
+ window.navigator &&
+ window.navigator.standalone)) {
schedule = function(fn) {
var div = document.createElement("div");
var observer = new MutationObserver(fn);
@@ -4297,12 +4336,7 @@ function doThenable(x, then, context) {
function resolveFromThenable(value) {
if (!promise) return;
- if (x === value) {
- promise._rejectCallback(
- Promise._makeSelfResolutionError(), false, true);
- } else {
- promise._resolveCallback(value);
- }
+ promise._resolveCallback(value);
promise = null;
}
@@ -4332,10 +4366,16 @@ var TimeoutError = Promise.TimeoutError;
var afterTimeout = function (promise, message) {
if (!promise.isPending()) return;
- if (typeof message !== "string") {
- message = "operation timed out";
+
+ var err;
+ if(!util.isPrimitive(message) && (message instanceof Error)) {
+ err = message;
+ } else {
+ if (typeof message !== "string") {
+ message = "operation timed out";
+ }
+ err = new TimeoutError(message);
}
- var err = new TimeoutError(message);
util.markAsOriginatingFromRejection(err);
promise._attachExtraTrace(err);
promise._cancel(err);
@@ -4522,10 +4562,20 @@ module.exports = function (Promise, apiRejection, tryConvertToPromise,
"you must pass at least 2 arguments to Promise.using");
var fn = arguments[len - 1];
if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- len--;
+
+ var input;
+ var spreadArgs = true;
+ if (len === 2 && Array.isArray(arguments[0])) {
+ input = arguments[0];
+ len = input.length;
+ spreadArgs = false;
+ } else {
+ input = arguments;
+ len--;
+ }
var resources = new Array(len);
for (var i = 0; i < len; ++i) {
- var resource = arguments[i];
+ var resource = input[i];
if (Disposer.isDisposer(resource)) {
var disposer = resource;
resource = resource.promise();
@@ -4549,7 +4599,8 @@ module.exports = function (Promise, apiRejection, tryConvertToPromise,
promise._pushContext();
var ret;
try {
- ret = fn.apply(undefined, vals);
+ ret = spreadArgs
+ ? fn.apply(undefined, vals) : fn.call(undefined, vals);
} finally {
promise._popContext();
}
@@ -4612,7 +4663,9 @@ var errorObj = {e: {}};
var tryCatchTarget;
function tryCatcher() {
try {
- return tryCatchTarget.apply(this, arguments);
+ var target = tryCatchTarget;
+ tryCatchTarget = null;
+ return target.apply(this, arguments);
} catch (e) {
errorObj.e = e;
return errorObj;
@@ -4673,6 +4726,7 @@ function withAppended(target, appendee) {
function getDataPropertyOrDefault(obj, key, defaultValue) {
if (es5.isES5) {
var desc = Object.getOwnPropertyDescriptor(obj, key);
+
if (desc != null) {
return desc.get == null && desc.set == null
? desc.value
@@ -4695,23 +4749,32 @@ function notEnumerableProp(obj, name, value) {
return obj;
}
-
-var wrapsPrimitiveReceiver = (function() {
- return this !== "string";
-}).call("string");
-
function thrower(r) {
throw r;
}
var inheritedDataKeys = (function() {
+ var excludedPrototypes = [
+ Array.prototype,
+ Object.prototype,
+ Function.prototype
+ ];
+
+ var isExcludedProto = function(val) {
+ for (var i = 0; i < excludedPrototypes.length; ++i) {
+ if (excludedPrototypes[i] === val) {
+ return true;
+ }
+ }
+ return false;
+ };
+
if (es5.isES5) {
- var oProto = Object.prototype;
var getKeys = Object.getOwnPropertyNames;
return function(obj) {
var ret = [];
var visitedKeys = Object.create(null);
- while (obj != null && obj !== oProto) {
+ while (obj != null && !isExcludedProto(obj)) {
var keys;
try {
keys = getKeys(obj);
@@ -4732,11 +4795,23 @@ var inheritedDataKeys = (function() {
return ret;
};
} else {
+ var hasProp = {}.hasOwnProperty;
return function(obj) {
+ if (isExcludedProto(obj)) return [];
var ret = [];
+
/*jshint forin:false */
- for (var key in obj) {
- ret.push(key);
+ enumeration: for (var key in obj) {
+ if (hasProp.call(obj, key)) {
+ ret.push(key);
+ } else {
+ for (var i = 0; i < excludedPrototypes.length; ++i) {
+ if (hasProp.call(excludedPrototypes[i], key)) {
+ continue enumeration;
+ }
+ }
+ ret.push(key);
+ }
}
return ret;
};
@@ -4744,13 +4819,22 @@ var inheritedDataKeys = (function() {
})();
+var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/;
function isClass(fn) {
try {
if (typeof fn === "function") {
var keys = es5.names(fn.prototype);
- if (es5.isES5) return keys.length > 1;
- return keys.length > 0 &&
- !(keys.length === 1 && keys[0] === "constructor");
+
+ var hasMethods = es5.isES5 && keys.length > 1;
+ var hasMethodsOtherThanConstructor = keys.length > 0 &&
+ !(keys.length === 1 && keys[0] === "constructor");
+ var hasThisAssignmentAndStaticMethods =
+ thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0;
+
+ if (hasMethods || hasMethodsOtherThanConstructor ||
+ hasThisAssignmentAndStaticMethods) {
+ return true;
+ }
}
return false;
} catch (e) {
@@ -4803,7 +4887,7 @@ function originatesFromRejection(e) {
}
function canAttachTrace(obj) {
- // Added by Zotero
+ // Added by Zotero
return obj && obj.stack && es5.propertyIsWritable(obj, "stack");
return obj instanceof Error && es5.propertyIsWritable(obj, "stack");
@@ -4833,7 +4917,9 @@ function copyDescriptors(from, to, filter) {
for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
if (filter(key)) {
- es5.defineProperty(to, key, es5.getDescriptor(from, key));
+ try {
+ es5.defineProperty(to, key, es5.getDescriptor(from, key));
+ } catch (ignore) {}
}
}
}
@@ -4855,7 +4941,6 @@ var ret = {
inherits: inherits,
withAppended: withAppended,
maybeWrapAsError: maybeWrapAsError,
- wrapsPrimitiveReceiver: wrapsPrimitiveReceiver,
toFastProperties: toFastProperties,
filledRange: filledRange,
toString: safeToString,
@@ -4874,311 +4959,11 @@ ret.isRecentNode = ret.isNode && (function() {
var version = process.versions.node.split(".").map(Number);
return (version[0] === 0 && version[1] > 10) || (version[0] > 0);
})();
-try {throw new Error(); } catch (e) {ret.lastLineError = e;}
-module.exports = ret;
-
-},{"./es5.js":14}],39:[function(_dereq_,module,exports){
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// 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:
-//
-// 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.
-
-function EventEmitter() {
- this._events = this._events || {};
- this._maxListeners = this._maxListeners || undefined;
-}
-module.exports = EventEmitter;
-
-// Backwards-compat with node 0.10.x
-EventEmitter.EventEmitter = EventEmitter;
-
-EventEmitter.prototype._events = undefined;
-EventEmitter.prototype._maxListeners = undefined;
-
-// By default EventEmitters will print a warning if more than 10 listeners are
-// added to it. This is a useful default which helps finding memory leaks.
-EventEmitter.defaultMaxListeners = 10;
-
-// Obviously not all Emitters should be limited to 10. This function allows
-// that to be increased. Set to zero for unlimited.
-EventEmitter.prototype.setMaxListeners = function(n) {
- if (!isNumber(n) || n < 0 || isNaN(n))
- throw TypeError('n must be a positive number');
- this._maxListeners = n;
- return this;
-};
-
-EventEmitter.prototype.emit = function(type) {
- var er, handler, len, args, i, listeners;
-
- if (!this._events)
- this._events = {};
-
- // If there is no 'error' event listener then throw.
- if (type === 'error') {
- if (!this._events.error ||
- (isObject(this._events.error) && !this._events.error.length)) {
- er = arguments[1];
- if (er instanceof Error) {
- throw er; // Unhandled 'error' event
- }
- throw TypeError('Uncaught, unspecified "error" event.');
- }
- }
-
- handler = this._events[type];
-
- if (isUndefined(handler))
- return false;
-
- if (isFunction(handler)) {
- switch (arguments.length) {
- // fast cases
- case 1:
- handler.call(this);
- break;
- case 2:
- handler.call(this, arguments[1]);
- break;
- case 3:
- handler.call(this, arguments[1], arguments[2]);
- break;
- // slower
- default:
- len = arguments.length;
- args = new Array(len - 1);
- for (i = 1; i < len; i++)
- args[i - 1] = arguments[i];
- handler.apply(this, args);
- }
- } else if (isObject(handler)) {
- len = arguments.length;
- args = new Array(len - 1);
- for (i = 1; i < len; i++)
- args[i - 1] = arguments[i];
-
- listeners = handler.slice();
- len = listeners.length;
- for (i = 0; i < len; i++)
- listeners[i].apply(this, args);
- }
-
- return true;
-};
-
-EventEmitter.prototype.addListener = function(type, listener) {
- var m;
-
- if (!isFunction(listener))
- throw TypeError('listener must be a function');
-
- if (!this._events)
- this._events = {};
-
- // To avoid recursion in the case that type === "newListener"! Before
- // adding it to the listeners, first emit "newListener".
- if (this._events.newListener)
- this.emit('newListener', type,
- isFunction(listener.listener) ?
- listener.listener : listener);
-
- if (!this._events[type])
- // Optimize the case of one listener. Don't need the extra array object.
- this._events[type] = listener;
- else if (isObject(this._events[type]))
- // If we've already got an array, just append.
- this._events[type].push(listener);
- else
- // Adding the second element, need to change to array.
- this._events[type] = [this._events[type], listener];
-
- // Check for listener leak
- if (isObject(this._events[type]) && !this._events[type].warned) {
- var m;
- if (!isUndefined(this._maxListeners)) {
- m = this._maxListeners;
- } else {
- m = EventEmitter.defaultMaxListeners;
- }
-
- if (m && m > 0 && this._events[type].length > m) {
- this._events[type].warned = true;
- console.error('(node) warning: possible EventEmitter memory ' +
- 'leak detected. %d listeners added. ' +
- 'Use emitter.setMaxListeners() to increase limit.',
- this._events[type].length);
- if (typeof console.trace === 'function') {
- // not supported in IE 10
- console.trace();
- }
- }
- }
-
- return this;
-};
-
-EventEmitter.prototype.on = EventEmitter.prototype.addListener;
-
-EventEmitter.prototype.once = function(type, listener) {
- if (!isFunction(listener))
- throw TypeError('listener must be a function');
- var fired = false;
+if (ret.isNode) ret.toFastProperties(process);
- function g() {
- this.removeListener(type, g);
-
- if (!fired) {
- fired = true;
- listener.apply(this, arguments);
- }
- }
-
- g.listener = listener;
- this.on(type, g);
-
- return this;
-};
-
-// emits a 'removeListener' event iff the listener was removed
-EventEmitter.prototype.removeListener = function(type, listener) {
- var list, position, length, i;
-
- if (!isFunction(listener))
- throw TypeError('listener must be a function');
-
- if (!this._events || !this._events[type])
- return this;
-
- list = this._events[type];
- length = list.length;
- position = -1;
-
- if (list === listener ||
- (isFunction(list.listener) && list.listener === listener)) {
- delete this._events[type];
- if (this._events.removeListener)
- this.emit('removeListener', type, listener);
-
- } else if (isObject(list)) {
- for (i = length; i-- > 0;) {
- if (list[i] === listener ||
- (list[i].listener && list[i].listener === listener)) {
- position = i;
- break;
- }
- }
-
- if (position < 0)
- return this;
-
- if (list.length === 1) {
- list.length = 0;
- delete this._events[type];
- } else {
- list.splice(position, 1);
- }
-
- if (this._events.removeListener)
- this.emit('removeListener', type, listener);
- }
-
- return this;
-};
-
-EventEmitter.prototype.removeAllListeners = function(type) {
- var key, listeners;
-
- if (!this._events)
- return this;
-
- // not listening for removeListener, no need to emit
- if (!this._events.removeListener) {
- if (arguments.length === 0)
- this._events = {};
- else if (this._events[type])
- delete this._events[type];
- return this;
- }
-
- // emit removeListener for all listeners on all events
- if (arguments.length === 0) {
- for (key in this._events) {
- if (key === 'removeListener') continue;
- this.removeAllListeners(key);
- }
- this.removeAllListeners('removeListener');
- this._events = {};
- return this;
- }
-
- listeners = this._events[type];
-
- if (isFunction(listeners)) {
- this.removeListener(type, listeners);
- } else {
- // LIFO order
- while (listeners.length)
- this.removeListener(type, listeners[listeners.length - 1]);
- }
- delete this._events[type];
-
- return this;
-};
-
-EventEmitter.prototype.listeners = function(type) {
- var ret;
- if (!this._events || !this._events[type])
- ret = [];
- else if (isFunction(this._events[type]))
- ret = [this._events[type]];
- else
- ret = this._events[type].slice();
- return ret;
-};
-
-EventEmitter.listenerCount = function(emitter, type) {
- var ret;
- if (!emitter._events || !emitter._events[type])
- ret = 0;
- else if (isFunction(emitter._events[type]))
- ret = 1;
- else
- ret = emitter._events[type].length;
- return ret;
-};
-
-function isFunction(arg) {
- return typeof arg === 'function';
-}
-
-function isNumber(arg) {
- return typeof arg === 'number';
-}
-
-function isObject(arg) {
- return typeof arg === 'object' && arg !== null;
-}
-
-function isUndefined(arg) {
- return arg === void 0;
-}
+try {throw new Error(); } catch (e) {ret.lastLineError = e;}
+module.exports = ret;
-},{}]},{},[4])(4)
+},{"./es5.js":14}]},{},[4])(4)
}); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }
\ No newline at end of file