diff --git a/Libraries/Blob/FileReader.js b/Libraries/Blob/FileReader.js index fc769f8a544a72..15a8b44d0bb522 100644 --- a/Libraries/Blob/FileReader.js +++ b/Libraries/Blob/FileReader.js @@ -85,9 +85,15 @@ class FileReader extends (EventTarget(...READER_EVENTS): any) { throw new Error('FileReader.readAsArrayBuffer is not implemented'); } - readAsDataURL(blob: Blob) { + readAsDataURL(blob: ?Blob) { this._aborted = false; + if (blob == null) { + throw new TypeError( + "Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'", + ); + } + NativeFileReaderModule.readAsDataURL(blob.data).then( (text: string) => { if (this._aborted) { @@ -106,9 +112,15 @@ class FileReader extends (EventTarget(...READER_EVENTS): any) { ); } - readAsText(blob: Blob, encoding: string = 'UTF-8') { + readAsText(blob: ?Blob, encoding: string = 'UTF-8') { this._aborted = false; + if (blob == null) { + throw new TypeError( + "Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob'", + ); + } + NativeFileReaderModule.readAsText(blob.data, encoding).then( (text: string) => { if (this._aborted) { diff --git a/Libraries/Network/XMLHttpRequest.js b/Libraries/Network/XMLHttpRequest.js index 3f1ebd357e8eaf..32c158e76eb385 100644 --- a/Libraries/Network/XMLHttpRequest.js +++ b/Libraries/Network/XMLHttpRequest.js @@ -244,7 +244,7 @@ class XMLHttpRequest extends (EventTarget(...XHR_EVENTS): any) { if (typeof this._response === 'object' && this._response) { this._cachedResponse = BlobManager.createFromOptions(this._response); } else if (this._response === '') { - this._cachedResponse = null; + this._cachedResponse = BlobManager.createFromParts([]); } else { throw new Error(`Invalid response for blob: ${this._response}`); }