annotate js/modules/xhr.js @ 93:00d23d6d41b4

made cache module into cache/html5 and a factory function.
author Atul Varma <avarma@mozilla.com>
date Mon, 26 Apr 2010 19:02:23 -0700
parents 0eab9a3ff12f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
1 Require.modules["xhr/queue"] = function(exports, require) {
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
2 function XMLHttpRequestQueue() {
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
3 const EVENTS = ["abort", "error", "load"];
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
4
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
5 var active = null;
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
6 var queue = [];
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
7
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
8 function activateNextInQueue() {
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
9 if (queue.length) {
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
10 var cb = queue.splice(0, 1)[0];
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
11 var xhr = cb();
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
12 if (!xhr)
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
13 throw new Error("enqueued callback did not return xhr");
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
14 EVENTS.forEach(function(name) {
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
15 xhr.addEventListener(name, onDone, false);
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
16 });
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
17 active = xhr;
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
18 }
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
19 }
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
20
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
21 function onDone(event) {
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
22 var xhr = event.target;
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
23 EVENTS.forEach(function(name) {
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
24 xhr.removeEventListener(name, onDone, false);
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
25 });
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
26 if (xhr == active) {
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
27 active = null;
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
28 activateNextInQueue();
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
29 }
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
30 };
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
31
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
32 this.enqueue = function enqueue(cb) {
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
33 queue.push(cb);
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
34 if (!active)
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
35 activateNextInQueue();
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
36 };
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
37
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
38 this.clear = function clear() {
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
39 queue.splice(0);
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
40 if (active) {
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
41 active.abort();
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
42 active = null;
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
43 }
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
44 };
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
45 }
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
46
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
47 exports.create = function create() {
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
48 return new XMLHttpRequestQueue();
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
49 };
0eab9a3ff12f replaced my last commit w/ a serial xhr queue, so that the dashboard requests are serialized but other ones aren't.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
50 };