[web/data] Support Deferred objects outside XHR

JS tests actually use this. Related to #5533303.

authorRémi Cardona <remi.cardona@logilab.fr>
changeset3540131a8405
branchdefault
phasepublic
hiddenno
parent revision#4ee15441f2eb merge 3.20.8 in 3.21
child revision#22a89d0f4143 [devtools] Serve JS tests over HTTP (closes #5533285)
files modified by this revision
web/data/cubicweb.ajax.js
# HG changeset patch
# User Rémi Cardona <remi.cardona@logilab.fr>
# Date 1431525501 -7200
# Wed May 13 15:58:21 2015 +0200
# Node ID 3540131a84052fc10d4e7b514579aa3563960d5e
# Parent 4ee15441f2eb3f326e10f35b8d4201b902e7b795
[web/data] Support Deferred objects outside XHR

JS tests actually use this. Related to #5533303.

diff --git a/web/data/cubicweb.ajax.js b/web/data/cubicweb.ajax.js
@@ -37,11 +37,11 @@
1          this._result = null;
2          this._error = null;
3      },
4 
5      addCallback: function(callback) {
6 -        if ((this._req.readyState == 4) && this._result) {
7 +        if (this._req && (this._req.readyState == 4) && this._result) {
8              var args = [this._result, this._req];
9              jQuery.merge(args, cw.utils.sliceList(arguments, 1));
10              callback.apply(null, args);
11          }
12          else {
@@ -49,11 +49,11 @@
13          }
14          return this;
15      },
16 
17      addErrback: function(callback) {
18 -        if (this._req.readyState == 4 && this._error) {
19 +        if (this._req && this._req.readyState == 4 && this._error) {
20              callback.apply(null, [this._error, this._req]);
21          }
22          else {
23              this._onFailure.push([callback, cw.utils.sliceList(arguments, 1)]);
24          }