| OLD | NEW |
| 1 <import src="/mojo/public/sky/core.sky" as="core" /> | 1 <import src="/mojo/public/sky/core.sky" as="core" /> |
| 2 <import src="/mojo/public/sky/unicode.sky" as="unicode" /> | 2 <import src="/mojo/public/sky/unicode.sky" as="unicode" /> |
| 3 <import src="/mojo/services/public/interfaces/network/network_service.mojom.sky"
as="net" /> | 3 <import src="/mojo/services/public/interfaces/network/network_service.mojom.sky"
as="net" /> |
| 4 <import src="/mojo/services/public/interfaces/network/url_loader.mojom.sky" as="
loader" /> | 4 <import src="/mojo/services/public/interfaces/network/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 function XMLHttpRequest() { | 7 function XMLHttpRequest() { |
| 8 this.networkService_ = shell.connectToService( | 8 this.networkService_ = shell.connectToService( |
| 9 "mojo://network_service/", net.NetworkService); | 9 "mojo://network_service/", net.NetworkService); |
| 10 this.request_ = null; | 10 this.request_ = null; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 }); | 35 }); |
| 36 this.request_.headers = requestHeaders; | 36 this.request_.headers = requestHeaders; |
| 37 | 37 |
| 38 // FIXME: Factor this into the JS bindings. | 38 // FIXME: Factor this into the JS bindings. |
| 39 var pipe = new core.createMessagePipe(); | 39 var pipe = new core.createMessagePipe(); |
| 40 this.networkService_.createURLLoader(pipe.handle1); | 40 this.networkService_.createURLLoader(pipe.handle1); |
| 41 this.loader_ = shell.wrapHandle(pipe.handle0, loader.URLLoader); | 41 this.loader_ = shell.wrapHandle(pipe.handle0, loader.URLLoader); |
| 42 | 42 |
| 43 var self = this; | 43 var self = this; |
| 44 this.loader_.start(this.request_).then(function(result) { | 44 this.loader_.start(this.request_).then(function(result) { |
| 45 core.drainData(result.response.body).then(function(result) { | 45 return core.drainData(result.response.body).then(function(result) { |
| 46 self.responseText = unicode.decodeUtf8String(new Uint8Array(result.buffer)
); | 46 self.responseText = unicode.decodeUtf8String(new Uint8Array(result.buffer)
); |
| 47 self.onload(); | 47 self.onload(); |
| 48 }).catch(function(error) { | |
| 49 self.onerror(error); | |
| 50 }); | 48 }); |
| 51 }).catch(function(error) { | 49 }).catch(function(error) { |
| 52 self.onerror(error); | 50 self.onerror(error); |
| 53 }); | 51 }); |
| 54 }; | 52 }; |
| 55 | 53 |
| 56 module.exports = XMLHttpRequest; | 54 module.exports = XMLHttpRequest; |
| 57 </script> | 55 </script> |
| OLD | NEW |