Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(905)

Unified Diff: sky/framework/xmlhttprequest.sky

Issue 753453002: Convert xmlhttprequest.sky to use classes (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/xmlhttprequest.sky
diff --git a/sky/framework/xmlhttprequest.sky b/sky/framework/xmlhttprequest.sky
index cef3252a82becbd1bc8a0a70a0db073644f68def..548af9c9e76f72e7950e53ba80040c520bf6c044 100644
--- a/sky/framework/xmlhttprequest.sky
+++ b/sky/framework/xmlhttprequest.sky
@@ -7,55 +7,60 @@
// XHR keeps itself alive.
var outstandingRequests = new Set();
-function XMLHttpRequest() {
- this.networkService_ = shell.connectToService(
- "mojo:network_service", net.NetworkService);
- this.request_ = null;
- this.loader_ = null;
- this.responseText = null;
- this.headers_ = new Map();
-};
-
-XMLHttpRequest.prototype.onload = function() { };
-XMLHttpRequest.prototype.onerror = function(error) { };
-
-XMLHttpRequest.prototype.open = function(method, url) {
- this.request_ = new loader.URLRequest();
- this.request_.url = new URL(url, document.URL);
- this.request_.method = method;
- this.request_.auto_follow_redirects = true;
- this.headers_.clear();
-};
-
-XMLHttpRequest.prototype.setRequestHeader = function(header, value) {
- this.headers_.set(header, value);
-};
-
-XMLHttpRequest.prototype.send = function() {
- var requestHeaders = [];
- this.headers_.forEach(function(value, key) {
- requestHeaders.push(key + ': ' + value);
- });
- this.request_.headers = requestHeaders;
-
- // FIXME: Factor this into the JS bindings.
- var pipe = new core.createMessagePipe();
- this.networkService_.createURLLoader(pipe.handle1);
- this.loader_ = shell.wrapHandle(pipe.handle0, loader.URLLoader);
-
- var self = this;
- outstandingRequests.add(this);
- this.loader_.start(this.request_).then(function(result) {
- return core.drainData(result.response.body).then(function(result) {
+class XMLHttpRequest {
+ constructor() {
+ this.networkService_ = shell.connectToService(
+ "mojo:network_service", net.NetworkService);
+ this.request_ = null;
+ this.loader_ = null;
+ this.responseText = null;
esprehn 2014/11/21 07:24:24 It might be nice to put public properties grouped.
+ this.headers_ = new Map();
+ }
+
+ onload() {
+ }
+
+ onerror(error) {
+ }
+
+ open(method, url) {
+ this.request_ = new loader.URLRequest();
+ this.request_.url = new URL(url, document.URL);
+ this.request_.method = method;
+ this.request_.auto_follow_redirects = true;
+ this.headers_.clear();
+ }
+
+ setRequestHeader(header, value) {
+ this.headers_.set(header, value);
+ }
+
+ send() {
+ var requestHeaders = [];
+ this.headers_.forEach(function(value, key) {
+ requestHeaders.push(key + ': ' + value);
+ });
+ this.request_.headers = requestHeaders;
+
+ // FIXME: Factor this into the JS bindings.
+ var pipe = new core.createMessagePipe();
+ this.networkService_.createURLLoader(pipe.handle1);
+ this.loader_ = shell.wrapHandle(pipe.handle0, loader.URLLoader);
+
+ var self = this;
+ outstandingRequests.add(this);
+ this.loader_.start(this.request_).then(function(result) {
+ return core.drainData(result.response.body).then(function(result) {
+ outstandingRequests.delete(self);
+ self.responseText = unicode.decodeUtf8String(new Uint8Array(result.buffer));
+ self.onload();
+ });
+ }).catch(function(error) {
outstandingRequests.delete(self);
- self.responseText = unicode.decodeUtf8String(new Uint8Array(result.buffer));
- self.onload();
+ self.onerror(error);
});
- }).catch(function(error) {
- outstandingRequests.delete(self);
- self.onerror(error);
- });
-};
+ }
+}
module.exports = XMLHttpRequest;
</script>
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698