Skip to content

Commit

Permalink
proposed fix for facebook#18223
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Humphreys committed Jun 5, 2018
1 parent 30320f1 commit 988c618
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
27 changes: 16 additions & 11 deletions Libraries/Network/XMLHttpRequest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
Expand Down Expand Up @@ -181,7 +182,7 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {
if (this._sent) {
throw new Error(
"Failed to set the 'responseType' property on 'XMLHttpRequest': The " +
'response type cannot be set after the request has been sent.',
'response type cannot be set after the request has been sent.',
);
}
if (!SUPPORTED_RESPONSE_TYPES.hasOwnProperty(responseType)) {
Expand Down Expand Up @@ -211,7 +212,7 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {
if (this._responseType !== '' && this._responseType !== 'text') {
throw new Error(
"The 'responseText' property is only available if 'responseType' " +
`is set to '' or 'text', but it is '${this._responseType}'.`,
`is set to '' or 'text', but it is '${this._responseType}'.`,
);
}
if (this.readyState < LOADING) {
Expand All @@ -221,7 +222,7 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {
}

get response(): Response {
const {responseType} = this;
const { responseType } = this;
if (responseType === '' || responseType === 'text') {
return this.readyState < LOADING || this._hasError ? '' : this._response;
}
Expand All @@ -247,7 +248,11 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {
if (typeof this._response === 'object' && this._response) {
this._cachedResponse = BlobManager.createFromOptions(this._response);
} else {
throw new Error(`Invalid response for blob: ${this._response}`);
if (this._response === '') {
this._cachedResponse = null;
} else {
throw new Error(`Invalid response for blob: ${this._response}`);
}
}
break;

Expand Down Expand Up @@ -565,20 +570,20 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {

setReadyState(newState: number): void {
this.readyState = newState;
this.dispatchEvent({type: 'readystatechange'});
this.dispatchEvent({ type: 'readystatechange' });
if (newState === this.DONE) {
if (this._aborted) {
this.dispatchEvent({type: 'abort'});
this.dispatchEvent({ type: 'abort' });
} else if (this._hasError) {
if (this._timedOut) {
this.dispatchEvent({type: 'timeout'});
this.dispatchEvent({ type: 'timeout' });
} else {
this.dispatchEvent({type: 'error'});
this.dispatchEvent({ type: 'error' });
}
} else {
this.dispatchEvent({type: 'load'});
this.dispatchEvent({ type: 'load' });
}
this.dispatchEvent({type: 'loadend'});
this.dispatchEvent({ type: 'loadend' });
}
}

Expand All @@ -595,4 +600,4 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) {
}
}

module.exports = XMLHttpRequest;
module.exports = XMLHttpRequest;
19 changes: 19 additions & 0 deletions Libraries/Network/nano.exe.stackdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Stack trace:
Frame Function Args
00180000000 0018005E0DE (00180230639, 00180230C39, 001802412F0, 000FFFFAD40)
00180000000 001800468F9 (C0C0C000008080, FF000000808080, FFFF000000FF00, 0000041D2A0)
00180000000 00180046932 (00180230616, 000000001E7, 001802412F0, 80808000C0C0C0)
00180000000 00180043543 (0006C32DB7C, 00180000000, 7FF8594D88FE, 001800004EC)
00180000000 0018006BF01 (C0C0C000008080, FF000000808080, FFFF000000FF00, FF00FF000000FF)
00180000000 0018006CD8E (00180320DF8, 00000000000, 00000000000, 00000000002)
00180000000 0018006ED24 (0018015D98A, 00000000033, 00600078A10, 00000000000)
00000000000 00180137221 (0060007B860, 00000000033, 006000E3430, 00600078A10)
00000000000 0018011DDBB (0060007B860, 00000000033, 006000E3430, 00600078A10)
00000000000 0006C31E376 (0006C33267A, 00000000007, 00000000007, 00000000000)
00000000000 0006C2FE21E (00000000000, 00000000004, 00000000020, 00000000000)
00000000000 0006C30F194 (0006C33B520, 0010044B230, 0010044B250, 0010044B0E0)
00000002000 0006C300226 (00000000000, 00000000001, 0006C33B520, 000FFFFC440)
00000002000 00100420704 (00000008000, 00000000017, 00000000002, 000B2C679B7)
000FFFFC440 00100406734 (0006C316EAD, 00000000001, 00000000000, 00000000000)
0010044B208 00100406D6C (0006C779190, 00000010002, 00000000003, 00000000000)
End of stack trace (more stack frames may be present)

0 comments on commit 988c618

Please sign in to comment.