| OLD | NEW |
| 1 <import src="/gen/mojo/public/sky/core.sky" as="core" /> | 1 <import src="/gen/mojo/public/sky/core.sky" as="core" /> |
| 2 <import src="/gen/mojo/public/sky/unicode.sky" as="unicode" /> | 2 <import src="/gen/mojo/public/sky/unicode.sky" as="unicode" /> |
| 3 <import src="/gen/mojo/services/network/public/interfaces/network_service.mojom.
sky" as="net" /> | 3 <import src="/gen/mojo/services/network/public/interfaces/network_service.mojom.
sky" as="net" /> |
| 4 <import src="/gen/mojo/services/network/public/interfaces/url_loader.mojom.sky"
as="loader" /> | 4 <import src="/gen/mojo/services/network/public/interfaces/url_loader.mojom.sky"
as="loader" /> |
| 5 <import src="shell.sky" as="shell" /> | 5 <import src="shell.sky" as="shell" /> |
| 6 <script> | 6 <script> |
| 7 // XHR keeps itself alive. | 7 // XHR keeps itself alive. |
| 8 var outstandingRequests = new Set(); | 8 var outstandingRequests = new Set(); |
| 9 | 9 |
| 10 const kPrivate = Symbol("XMLHttpRequestPrivate"); | 10 const kPrivate = Symbol("XMLHttpRequestPrivate"); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // 'body' is actually an array of body segments. | 94 // 'body' is actually an array of body segments. |
| 95 priv.request.body = [dataPipe.consumerHandle]; | 95 priv.request.body = [dataPipe.consumerHandle]; |
| 96 } | 96 } |
| 97 | 97 |
| 98 var requestHeaders = []; | 98 var requestHeaders = []; |
| 99 priv.headers.forEach(function(value, key) { | 99 priv.headers.forEach(function(value, key) { |
| 100 requestHeaders.push(key + ': ' + value); | 100 requestHeaders.push(key + ': ' + value); |
| 101 }); | 101 }); |
| 102 priv.request.headers = requestHeaders; | 102 priv.request.headers = requestHeaders; |
| 103 | 103 |
| 104 // FIXME: Factor this into the JS bindings. | 104 priv.networkService.createURLLoader(function(urlLoaderProxy) { |
| 105 var pipe = new core.createMessagePipe(); | 105 priv.loader = urlLoaderProxy; |
| 106 priv.networkService.createURLLoader(pipe.handle1); | 106 }); |
| 107 priv.loader = shell.wrapHandle(pipe.handle0, loader.URLLoader); | |
| 108 | 107 |
| 109 var self = this; | 108 var self = this; |
| 110 outstandingRequests.add(this); | 109 outstandingRequests.add(this); |
| 111 priv.loader.start(priv.request).then(function(result) { | 110 priv.loader.start(priv.request).then(function(result) { |
| 112 self.status = result.response.status_code; | 111 self.status = result.response.status_code; |
| 113 self.statusText = result.response.status_line; | 112 self.statusText = result.response.status_line; |
| 114 if (result.response.error) | 113 if (result.response.error) |
| 115 throw new Error(result.response.error.description); | 114 throw new Error(result.response.error.description); |
| 116 return core.drainData(result.response.body).then(function(result) { | 115 return core.drainData(result.response.body).then(function(result) { |
| 117 outstandingRequests.delete(self); | 116 outstandingRequests.delete(self); |
| 118 priv.responseArrayBuffer = result.buffer; | 117 priv.responseArrayBuffer = result.buffer; |
| 119 // Use a setTimeout to avoid exceptions in onload tripping onerror. | 118 // Use a setTimeout to avoid exceptions in onload tripping onerror. |
| 120 window.setTimeout(function() { | 119 window.setTimeout(function() { |
| 121 self.onload(); | 120 self.onload(); |
| 122 }); | 121 }); |
| 123 }); | 122 }); |
| 124 }).catch(function(error) { | 123 }).catch(function(error) { |
| 125 outstandingRequests.delete(self); | 124 outstandingRequests.delete(self); |
| 126 // Technically this should throw a ProgressEvent. | 125 // Technically this should throw a ProgressEvent. |
| 127 self.onerror(error); | 126 self.onerror(error); |
| 128 }); | 127 }); |
| 129 } | 128 } |
| 130 } | 129 } |
| 131 | 130 |
| 132 module.exports = XMLHttpRequest; | 131 module.exports = XMLHttpRequest; |
| 133 </script> | 132 </script> |
| OLD | NEW |