commit 75411066414b7a87f66f023fc01388e58b741388
parent 27804bb47c23a3387ab6a1112e14ea084bbe3535
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 9 Oct 2014 14:14:10 -0400
Update Bluebird to 2.3.5
Our modifications no longer include a custom yield handler to
automatically call all() on yielded arrays (which maintained Bluebird
1.x behavior). It's now necessary to call all() or similar explicitly.
Also fixed a few incorrect yields hidden by that behavior.
Diffstat:
6 files changed, 123 insertions(+), 74 deletions(-)
diff --git a/chrome/content/zotero/bindings/attachmentbox.xml b/chrome/content/zotero/bindings/attachmentbox.xml
@@ -142,7 +142,7 @@
Zotero.spawn(function* () {
Zotero.debug('Refreshing attachment box');
- yield [this.item.loadItemData(), this.item.loadNote()];
+ yield Zotero.Promise.all([this.item.loadItemData(), this.item.loadNote()]);
var attachmentBox = document.getAnonymousNodes(this)[0];
var title = this._id('title');
diff --git a/chrome/content/zotero/itemPane.js b/chrome/content/zotero/itemPane.js
@@ -148,7 +148,7 @@ var ZoteroItemPane = new function() {
box.mode = 'edit';
}
- yield [item.loadItemData(), item.loadCreators()];
+ yield Zotero.Promise.all([item.loadItemData(), item.loadCreators()]);
box.item = item;
});
diff --git a/chrome/content/zotero/locateMenu.js b/chrome/content/zotero/locateMenu.js
@@ -380,7 +380,7 @@ var Zotero_LocateMenu = new function() {
return _getURL(item).then((val) => val !== false);
}
this.handleItems = Zotero.Promise.coroutine(function* (items, event) {
- var urls = yield [_getURL(item) for each(item in items)];
+ var urls = yield Zotero.Promise.all([_getURL(item) for each(item in items)]);
ZoteroPane_Local.loadURI([url for each(url in urls) if(url)], event);
});
diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js
@@ -288,10 +288,10 @@ Zotero.DataObject.prototype._getLinkedObject = Zotero.Promise.coroutine(function
var predicate = Zotero.Relations.linkedObjectPredicate;
var uri = Zotero.URI['get' + this._ObjectType + 'URI'](this);
- var links = yield [
+ var links = yield Zotero.Promise.all([
Zotero.Relations.getSubject(false, predicate, uri),
Zotero.Relations.getObject(uri, predicate, false)
- ];
+ ]);
links = links[0].concat(links[1]);
if (!links.length) {
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -1080,7 +1080,7 @@ Zotero.Item.prototype.addRelatedItem = Zotero.Promise.coroutine(function* (itemI
return false;
}
- var current = yield this._getRelatedItems(true);
+ var current = this._getRelatedItems(true);
if (current.indexOf(itemID) != -1) {
Zotero.debug("Item " + this.id + " already related to item "
+ itemID + " in Zotero.Item.addItem()");
@@ -1115,7 +1115,7 @@ Zotero.Item.prototype.removeRelatedItem = Zotero.Promise.coroutine(function* (it
}
itemID = parsedInt;
- var current = yield this._getRelatedItems(true);
+ var current = this._getRelatedItems(true);
var index = current.indexOf(itemID);
if (index == -1) {
@@ -1630,7 +1630,7 @@ Zotero.Item.prototype.save = Zotero.Promise.coroutine(function* (options) {
if (this._changed.relatedItems) {
var removed = [];
var newids = [];
- var currentIDs = yield this._getRelatedItems(true);
+ var currentIDs = this._getRelatedItems(true);
for each(var id in currentIDs) {
newids.push(id);
@@ -1655,7 +1655,7 @@ Zotero.Item.prototype.save = Zotero.Promise.coroutine(function* (options) {
if (this._changed.relatedItems) {
var removed = [];
var newids = [];
- var currentIDs = yield this._getRelatedItems(true);
+ var currentIDs = this._getRelatedItems(true);
for each(var id in this._previousData.related) {
if (currentIDs.indexOf(id) == -1) {
@@ -4195,7 +4195,7 @@ Zotero.Item.prototype.toJSON = Zotero.Promise.coroutine(function* (options, patc
// Tags
obj.tags = [];
yield this.loadTags()
- var tags = yield this.getTags();
+ var tags = this.getTags();
for (let i=0; i<tags.length; i++) {
obj.tags.push(tags[i]);
}
@@ -4724,7 +4724,7 @@ Zotero.Item.prototype._setRelatedItems = Zotero.Promise.coroutine(function* (ite
throw ('ids must be an array in Zotero.Items._setRelatedItems()');
}
- var currentIDs = yield this._getRelatedItems(true);
+ var currentIDs = this._getRelatedItems(true);
var oldIDs = []; // children being kept
var newIDs = []; // new children
diff --git a/resource/bluebird.js b/resource/bluebird.js
@@ -1,5 +1,5 @@
/**
- * bluebird build version 2.2.2
+ * bluebird build version 2.3.5
* Features enabled: core, race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, progress, cancel, using, filter, any, each, timers
*/
/**
@@ -25,7 +25,7 @@
*
*/
!function(e){
- //
+ //
// Added by Zotero
//
EXPORTED_SYMBOLS = ["Promise"];
@@ -44,33 +44,33 @@
var timer = Components.classes["@mozilla.org/timer;1"]
.createInstance(Components.interfaces.nsITimer);
timer.initWithCallback({"notify":function() {
- // Remove timer from array so it can be garbage collected
- _runningTimers.splice(_runningTimers.indexOf(timer), 1);
-
- // Execute callback function
- try {
- func();
- } catch(err) {
- // Rethrow errors that occur so that they appear in the error
- // console with the appropriate name and line numbers. While the
- // the errors appear without this, the line numbers get eaten.
- var scriptError = Components.classes["@mozilla.org/scripterror;1"]
- .createInstance(Components.interfaces.nsIScriptError);
- scriptError.init(
- err.message || err.toString(),
- err.fileName || err.filename || null,
- null,
- err.lineNumber || null,
- null,
- scriptError.errorFlag,
- 'component javascript'
- );
- Components.classes["@mozilla.org/consoleservice;1"]
- .getService(Components.interfaces.nsIConsoleService)
- .logMessage(scriptError);
- global.debug(err, 1);
- global.debug(err.stack, 1);
- }
+ // Remove timer from array so it can be garbage collected
+ _runningTimers.splice(_runningTimers.indexOf(timer), 1);
+
+ // Execute callback function
+ try {
+ func();
+ } catch(err) {
+ // Rethrow errors that occur so that they appear in the error
+ // console with the appropriate name and line numbers. While the
+ // the errors appear without this, the line numbers get eaten.
+ var scriptError = Components.classes["@mozilla.org/scripterror;1"]
+ .createInstance(Components.interfaces.nsIScriptError);
+ scriptError.init(
+ err.message || err.toString(),
+ err.fileName || err.filename || null,
+ null,
+ err.lineNumber || null,
+ null,
+ scriptError.errorFlag,
+ 'component javascript'
+ );
+ Components.classes["@mozilla.org/consoleservice;1"]
+ .getService(Components.interfaces.nsIConsoleService)
+ .logMessage(scriptError);
+ global.debug(err, 1);
+ global.debug(err.stack, 1);
+ }
}}, ms, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
_runningTimers.push(timer);
}
@@ -84,15 +84,15 @@
// TEMP: Only turn on if debug logging enabled?
Promise.longStackTraces();
Promise.onPossiblyUnhandledRejection(function(error) {
- global.debug('===========');
- global.debug(error);
- global.debug(error.stack);
- throw error;
+ global.debug('===========');
+ global.debug(error);
+ global.debug(error.stack);
+ throw error;
});
return;
- "object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Promise=e():"undefined"!=typeof global?global.Promise=e():"undefined"!=typeof self&&(self.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 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){
+ "object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Promise=e():"undefined"!=typeof global?global.Promise=e():"undefined"!=typeof self&&(self.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 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){
/**
* Copyright (c) 2014 Petka Antonov
*
@@ -599,7 +599,7 @@ CapturedTrace.combine = function CapturedTrace$Combine(current, prev) {
for (var i = 0, len = lines.length; i < len; ++i) {
- if ((rignore.test(lines[i]) ||
+ if (((rignore.test(lines[i]) && rtraceline.test(lines[i])) ||
(i > 0 && !rtraceline.test(lines[i])) &&
lines[i] !== "From previous event:")
) {
@@ -967,8 +967,8 @@ function originatesFromRejection(e) {
}
function isError(obj) {
- // Added by Zotero
- return obj.message && obj.stack;
+ // Added by Zotero
+ return obj.message && obj.stack;
return obj instanceof Error;
}
@@ -1458,7 +1458,7 @@ PromiseSpawn.prototype._continue = function PromiseSpawn$_continue(result) {
);
global.debug(e);
global.debug(e.stack);
-
+
this._throw(new TypeError("A value was yielded that could not be treated as a promise"));
return;
}
@@ -1508,11 +1508,6 @@ Promise.coroutine.addYieldHandler = function(fn) {
yieldHandlers.push(fn);
};
-// Added by Zotero to allow yielding arrays of promises in coroutines
-Promise.coroutine.addYieldHandler(function(yieldedValue) {
- if (Array.isArray(yieldedValue)) return Promise.all(yieldedValue);
-});
-
Promise.spawn = function Promise$Spawn(generatorFunction) {
deprecated("Promise.spawn is deprecated. Use Promise.coroutine instead.");
if (typeof generatorFunction !== "function") {
@@ -1919,6 +1914,14 @@ Promise.prototype._progress = function Promise$_progress(progressValue) {
};
+Promise.prototype._clearFirstHandlerData$Base =
+Promise.prototype._clearFirstHandlerData;
+Promise.prototype._clearFirstHandlerData =
+function Promise$_clearFirstHandlerData() {
+ this._clearFirstHandlerData$Base();
+ this._progressHandler0 = void 0;
+};
+
Promise.prototype._progressHandlerAt =
function Promise$_progressHandlerAt(index) {
return index === 0
@@ -2069,11 +2072,24 @@ function Promise(resolver) {
if (resolver !== INTERNAL) this._resolveFromResolver(resolver);
}
+function returnFirstElement(elements) {
+ return elements[0];
+}
+
Promise.prototype.bind = function Promise$bind(thisArg) {
+ var maybePromise = cast(thisArg, void 0);
var ret = new Promise(INTERNAL);
- ret._follow(this);
+ if (maybePromise instanceof Promise) {
+ var binder = maybePromise.then(function(thisArg) {
+ ret._setBoundTo(thisArg);
+ });
+ var p = Promise.all([this, binder]).then(returnFirstElement);
+ ret._follow(p);
+ } else {
+ ret._follow(this);
+ ret._setBoundTo(thisArg);
+ }
ret._propagateFrom(this, 2 | 1);
- ret._setBoundTo(thisArg);
return ret;
};
@@ -2098,8 +2114,7 @@ function Promise$catch(fn) {
+ "or a filter function");
this._attachExtraTrace(catchFilterTypeError);
- async.invoke(this._reject, this, catchFilterTypeError);
- return;
+ return Promise.reject(catchFilterTypeError);
}
}
catchInstances.length = j;
@@ -2232,10 +2247,19 @@ Promise.defer = Promise.pending = function Promise$Defer() {
};
Promise.bind = function Promise$Bind(thisArg) {
+ var maybePromise = cast(thisArg, void 0);
var ret = new Promise(INTERNAL);
ret._setTrace(void 0);
- ret._setFulfilled();
- ret._setBoundTo(thisArg);
+
+ if (maybePromise instanceof Promise) {
+ var p = maybePromise.then(function(thisArg) {
+ ret._setBoundTo(thisArg);
+ });
+ ret._follow(p);
+ } else {
+ ret._setBoundTo(thisArg);
+ ret._setFulfilled();
+ }
return ret;
};
@@ -2535,7 +2559,7 @@ function Promise$_proxyPromiseArray(promiseArray, index) {
Promise.prototype._proxyPromise = function Promise$_proxyPromise(promise) {
promise._setProxied();
- this._setProxyHandlers(promise, -1);
+ this._setProxyHandlers(promise, -15);
};
Promise.prototype._setBoundTo = function Promise$_setBoundTo(obj) {
@@ -2814,7 +2838,7 @@ Promise.prototype._settlePromiseAt = function Promise$_settlePromiseAt(index) {
}
}
- if (index >= 256) {
+ if (index >= 4) {
this._queueGC();
}
};
@@ -2850,14 +2874,23 @@ Promise.prototype._queueGC = function Promise$_queueGC() {
};
Promise.prototype._gc = function Promise$gc() {
- var len = this._length() * 5;
+ var len = this._length() * 5 - 5;
for (var i = 0; i < len; i++) {
delete this[i];
}
+ this._clearFirstHandlerData();
this._setLength(0);
this._unsetGcQueued();
};
+Promise.prototype._clearFirstHandlerData =
+function Promise$_clearFirstHandlerData() {
+ this._fulfillmentHandler0 = void 0;
+ this._rejectionHandler0 = void 0;
+ this._promise0 = void 0;
+ this._receiver0 = void 0;
+};
+
Promise.prototype._queueSettleAt = function Promise$_queueSettleAt(index) {
if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled();
async.invoke(this._settlePromiseAt, this, index);
@@ -3537,26 +3570,26 @@ function makeNodePromisifiedEval(callback, receiver, originalName, fn, suffix) {
var ret;
if (typeof callback === "string") {
ret = " \n\
- this.method(args, fn); \n\
+ this.method({{args}}, fn); \n\
break; \n\
".replace(".method", generatePropertyAccess(callback));
} else if (receiver === THIS) {
ret = " \n\
- callback.call(this, args, fn); \n\
+ callback.call(this, {{args}}, fn); \n\
break; \n\
";
} else if (receiver !== void 0) {
ret = " \n\
- callback.call(receiver, args, fn); \n\
+ callback.call(receiver, {{args}}, fn); \n\
break; \n\
";
} else {
ret = " \n\
- callback(args, fn); \n\
+ callback({{args}}, fn); \n\
break; \n\
";
}
- return ret.replace("args", args).replace(", ", comma);
+ return ret.replace("{{args}}", args).replace(", ", comma);
}
function generateArgumentSwitchCase() {
@@ -4258,7 +4291,7 @@ else if ((typeof MutationObserver !== "undefined" &&
});
return function Promise$_Scheduler(fn) {
queuedFn = fn;
- div.setAttribute("class", "foo");
+ div.classList.toggle("foo");
};
})();
@@ -4747,7 +4780,7 @@ var _setTimeout = function(fn, ms) {
var arg2 = len >= 5 ? arguments[4] : void 0;
setTimeout(function() {
fn(arg0, arg1, arg2);
- }, ms);
+ }, ms|0);
};
module.exports = function(Promise, INTERNAL, cast) {
@@ -4854,13 +4887,23 @@ module.exports = function (Promise, apiRejection, cast) {
setTimeout(function(){throw e;}, 0);
}
+ function castPreservingDisposable(thenable) {
+ var maybePromise = cast(thenable, void 0);
+ if (maybePromise !== thenable &&
+ typeof thenable._isDisposable === "function" &&
+ typeof thenable._getDisposer === "function" &&
+ thenable._isDisposable()) {
+ maybePromise._setDisposable(thenable._getDisposer());
+ }
+ return maybePromise;
+ }
function dispose(resources, inspection) {
var i = 0;
var len = resources.length;
var ret = Promise.defer();
function iterator() {
if (i >= len) return ret.resolve();
- var maybePromise = cast(resources[i++], void 0);
+ var maybePromise = castPreservingDisposable(resources[i++]);
if (maybePromise instanceof Promise &&
maybePromise._isDisposable()) {
try {
@@ -4923,6 +4966,12 @@ module.exports = function (Promise, apiRejection, cast) {
return ret;
};
+ Disposer.isDisposer = function Disposer$isDisposer(d) {
+ return (d != null &&
+ typeof d.resource === "function" &&
+ typeof d.tryDispose === "function");
+ };
+
function FunctionDisposer(fn, promise) {
this.constructor$(fn, promise);
}
@@ -4943,7 +4992,7 @@ module.exports = function (Promise, apiRejection, cast) {
var resources = new Array(len);
for (var i = 0; i < len; ++i) {
var resource = arguments[i];
- if (resource instanceof Disposer) {
+ if (Disposer.isDisposer(resource)) {
var disposer = resource;
resource = resource.promise();
resource._setDisposable(disposer);
@@ -5258,4 +5307,4 @@ module.exports = ret;
},{"./es5.js":12}]},{},[3])
(3)
});
-;
-\ No newline at end of file
+; ;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