From 51a56a2aea39ec70413ae0fd852dbbd93a2e8cf3 Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Mon, 15 Jun 2015 15:25:43 +0300 Subject: [PATCH] Support responseType property on XMLHttpRequest. Only default, "" and "text" supported for now. Raising an error otherwise. --- apps/tests/http-tests.ts | 13 +++++++++++++ declarations.d.ts | 1 + http/http.ts | 13 +++++++++++++ 3 files changed, 27 insertions(+) diff --git a/apps/tests/http-tests.ts b/apps/tests/http-tests.ts index 1f3797e0f..58abade52 100644 --- a/apps/tests/http-tests.ts +++ b/apps/tests/http-tests.ts @@ -616,3 +616,16 @@ export function test_raises_onerror_Event(done) { xhr.open("GET", "https://no-such-domain-httpbin.org"); xhr.send(); } + +export function test_responseType(done) { + let xhr = new XMLHttpRequest(); + xhr.responseType = ""; + xhr.responseType = "text"; + + TKUnit.assertThrows( + () => xhr.responseType = "json", + "Didn't raise on unsupported type.", + "Response type of 'json' not supported." + ); + done(null); +} diff --git a/declarations.d.ts b/declarations.d.ts index bcb43448a..d5154095d 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -37,6 +37,7 @@ declare class XMLHttpRequest { overrideMimeType(mime: string): void; readyState: number; responseText: string; + responseType: string; status: number; onload: () => void; diff --git a/http/http.ts b/http/http.ts index da8b385d7..0e9a22ef2 100644 --- a/http/http.ts +++ b/http/http.ts @@ -49,6 +49,7 @@ export class XMLHttpRequest { private _responseText: string = ""; private _headers: any; private _errorFlag: boolean; + private _responseType: string; public onreadystatechange: Function; @@ -163,6 +164,18 @@ export class XMLHttpRequest { return this._readyState; } + public get responseType(): string { + return this._responseType; + } + + public set responseType(value: string) { + if (value === "" || value === "text") { + this._responseType = value; + } else { + throw new Error(`Response type of '${value}' not supported.`); + } + } + private _setReadyState(value: number) { if (this._readyState !== value) { this._readyState = value;