forked from josephg/node-browserchannel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
closure-terminate-fixes-r2519.patch
92 lines (89 loc) · 2.73 KB
/
closure-terminate-fixes-r2519.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Index: goog/net/tmpnetwork.js
===================================================================
--- goog/net/tmpnetwork.js (revision 2519)
+++ goog/net/tmpnetwork.js (working copy)
@@ -103,44 +103,26 @@
var channelDebug = new goog.net.ChannelDebug();
channelDebug.debug('TestLoadImage: loading ' + url);
var img = new Image();
- img.onload = function() {
- try {
- channelDebug.debug('TestLoadImage: loaded');
- goog.net.tmpnetwork.clearImageCallbacks_(img);
- callback(true);
- } catch (e) {
- channelDebug.dumpException(e);
- }
+ var timer = null;
+ var createHandler = function(result, message) {
+ return function() {
+ try {
+ channelDebug.debug('TestLoadImage: ' + message);
+ goog.net.tmpnetwork.clearImageCallbacks_(img);
+ goog.global.clearTimeout(timer);
+ callback(result);
+ } catch (e) {
+ channelDebug.dumpException(e);
+ }
+ };
};
- img.onerror = function() {
- try {
- channelDebug.debug('TestLoadImage: error');
- goog.net.tmpnetwork.clearImageCallbacks_(img);
- callback(false);
- } catch (e) {
- channelDebug.dumpException(e);
- }
- };
- img.onabort = function() {
- try {
- channelDebug.debug('TestLoadImage: abort');
- goog.net.tmpnetwork.clearImageCallbacks_(img);
- callback(false);
- } catch (e) {
- channelDebug.dumpException(e);
- }
- };
- img.ontimeout = function() {
- try {
- channelDebug.debug('TestLoadImage: timeout');
- goog.net.tmpnetwork.clearImageCallbacks_(img);
- callback(false);
- } catch (e) {
- channelDebug.dumpException(e);
- }
- };
- goog.global.setTimeout(function() {
+ img.onload = createHandler(true, 'loaded');
+ img.onerror = createHandler(false, 'error');
+ img.onabort = createHandler(false, 'abort');
+ img.ontimeout = createHandler(false, 'timeout');
+
+ timer = goog.global.setTimeout(function() {
if (img.ontimeout) {
img.ontimeout();
}
Index: goog/net/channelrequest.js
===================================================================
--- goog/net/channelrequest.js (revision 2519)
+++ goog/net/channelrequest.js (working copy)
@@ -1037,10 +1037,20 @@
goog.net.ChannelRequest.prototype.imgTagGet_ = function() {
var eltImg = new Image();
eltImg.src = this.baseUri_;
+ eltImg.onload = eltImg.onerror = goog.bind(this.imgTagComplete_, this);
this.requestStartTime_ = goog.now();
this.ensureWatchDogTimer_();
};
+/**
+ * Callback when the image request is complete
+ *
+ * @private
+ */
+goog.net.ChannelRequest.prototype.imgTagComplete_ = function() {
+ this.cancelWatchDogTimer_();
+ this.channel_.onRequestComplete(this);
+}
/**
* Cancels the request no matter what the underlying transport is.