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

Unified Diff: sky/framework/xmlhttprequest.sky

Issue 753473002: Hide XMLHttpRequest's private state using Symbol (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 ca7461c13e534bd3846285d934fc9663f544c43c..7018d084f2096e132d87cb441c94df0b7bc8089b 100644
--- a/sky/framework/xmlhttprequest.sky
+++ b/sky/framework/xmlhttprequest.sky
@@ -7,15 +7,22 @@
// XHR keeps itself alive.
var outstandingRequests = new Set();
+const kPrivate = Symbol("XMLHttpRequestPrivate");
+
+class Private {
+ constructor() {
+ this.networkService = shell.connectToService(
+ "mojo:network_service", net.NetworkService);
+ this.request = null;
+ this.loader = null;
+ this.headers = new Map();
+ }
+}
+
class XMLHttpRequest {
constructor() {
+ this[kPrivate] = new Private;
this.responseText = null;
-
- this.networkService_ = shell.connectToService(
- "mojo:network_service", net.NetworkService);
- this.request_ = null;
- this.loader_ = null;
- this.headers_ = new Map();
}
onload() {
@@ -25,32 +32,36 @@ class XMLHttpRequest {
}
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();
+ var request = new loader.URLRequest();
+ request.url = new URL(url, document.URL);
+ request.method = method;
+ request.auto_follow_redirects = true;
+
+ var priv = this[kPrivate];
+ priv.request = request;
+ priv.headers.clear();
}
setRequestHeader(header, value) {
- this.headers_.set(header, value);
+ this[kPrivate].headers.set(header, value);
}
send() {
+ var priv = this[kPrivate];
var requestHeaders = [];
- this.headers_.forEach(function(value, key) {
+ priv.headers.forEach(function(value, key) {
requestHeaders.push(key + ': ' + value);
});
- this.request_.headers = requestHeaders;
+ priv.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);
+ priv.networkService.createURLLoader(pipe.handle1);
+ priv.loader = shell.wrapHandle(pipe.handle0, loader.URLLoader);
var self = this;
outstandingRequests.add(this);
- this.loader_.start(this.request_).then(function(result) {
+ priv.loader.start(priv.request).then(function(result) {
return core.drainData(result.response.body).then(function(result) {
outstandingRequests.delete(self);
self.responseText = unicode.decodeUtf8String(new Uint8Array(result.buffer));
« 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