Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 Cu.import("resource://services-common/async.js");
6 function run_test() {
7 _("Chain a few async methods, making sure the 'this' object is correct.");
9 let methods = {
10 save: function(x, callback) {
11 this.x = x;
12 callback(x);
13 },
14 addX: function(x, callback) {
15 callback(x + this.x);
16 },
17 double: function(x, callback) {
18 callback(x * 2);
19 },
20 neg: function(x, callback) {
21 callback(-x);
22 }
23 };
24 methods.chain = Async.chain;
26 // ((1 + 1 + 1) * (-1) + 1) * 2 + 1 = -3
27 methods.chain(methods.save, methods.addX, methods.addX, methods.neg,
28 methods.addX, methods.double, methods.addX, methods.save)(1);
29 do_check_eq(methods.x, -3);
30 }