From 0b8c9cf3acc7dc446d4abfd635929d1bfaa34207 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Wed, 17 Dec 2014 12:11:42 -0800 Subject: [PATCH] Use existing unicode.sky instead of re-inventing I somehow missed this function the first time. This is already tested by tests/framework/xmlhttprequest/unicode-post.sky R=esprehn@chromium.org BUG= Review URL: https://codereview.chromium.org/806043002 --- framework/xmlhttprequest.sky | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/framework/xmlhttprequest.sky b/framework/xmlhttprequest.sky index eb8aa9efd79..fc9af685479 100644 --- a/framework/xmlhttprequest.sky +++ b/framework/xmlhttprequest.sky @@ -21,17 +21,6 @@ class Private { } } -// Somewhat hacky, but works. -function stringToUTF8Buffer(string) { - var string = unescape(encodeURIComponent(string)); - var charList = string.split(''); - var uintArray = []; - for (var i = 0; i < charList.length; i++) { - uintArray.push(charList[i].charCodeAt(0)); - } - return new Uint8Array(uintArray); -} - // https://xhr.spec.whatwg.org class XMLHttpRequest { constructor() { @@ -89,7 +78,8 @@ class XMLHttpRequest { var bodyAsBufferView = null; if (typeof(body) === "string") { this.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); - bodyAsBufferView = stringToUTF8Buffer(body); + var bodyAsBufferView = new Uint8Array(unicode.utf8Length(body)); + unicode.encodeUtf8String(body, bodyAsBufferView); } else { bodyAsBufferView = new Uint8Array(body); }