From a2aedc2d68d46fe03708c5d797e9326a5ccf6eb3 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 21 Nov 2014 00:09:50 -0800 Subject: [PATCH] Move XMLHttpRequest#responseText to a getter Moving this property to a getter lets the implementation of the object change the value but prevents clients of the API from changing the value, which is the expected behavior. R=esprehn@chromium.org Review URL: https://codereview.chromium.org/746953002 --- framework/xmlhttprequest.sky | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/framework/xmlhttprequest.sky b/framework/xmlhttprequest.sky index 7018d084f20..75a7a4795a5 100644 --- a/framework/xmlhttprequest.sky +++ b/framework/xmlhttprequest.sky @@ -16,13 +16,13 @@ class Private { this.request = null; this.loader = null; this.headers = new Map(); + this.responseText = ""; } } class XMLHttpRequest { constructor() { this[kPrivate] = new Private; - this.responseText = null; } onload() { @@ -31,6 +31,10 @@ class XMLHttpRequest { onerror(error) { } + get responseText() { + return this[kPrivate].responseText; + } + open(method, url) { var request = new loader.URLRequest(); request.url = new URL(url, document.URL); @@ -64,7 +68,7 @@ class XMLHttpRequest { 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)); + priv.responseText = unicode.decodeUtf8String(new Uint8Array(result.buffer)); self.onload(); }); }).catch(function(error) {