Bug 1132924 - XHR should support empty response in workers, r=bkelly. r=bent

This commit is contained in:
Andrea Marchesini 2015-02-14 09:09:06 +01:00
parent 1b6561194e
commit 0a194e5205
5 changed files with 56 additions and 10 deletions

View File

@ -2382,19 +2382,24 @@ XMLHttpRequest::GetResponse(JSContext* /* unused */,
{
if (NS_SUCCEEDED(mStateData.mResponseTextResult) &&
mStateData.mResponse.isUndefined()) {
MOZ_ASSERT(mStateData.mResponseText.Length());
MOZ_ASSERT(NS_SUCCEEDED(mStateData.mResponseResult));
JSString* str =
JS_NewUCStringCopyN(mWorkerPrivate->GetJSContext(),
mStateData.mResponseText.get(),
mStateData.mResponseText.Length());
if (!str) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
if (mStateData.mResponseText.IsEmpty()) {
mStateData.mResponse =
JS_GetEmptyStringValue(mWorkerPrivate->GetJSContext());
} else {
JSString* str =
JS_NewUCStringCopyN(mWorkerPrivate->GetJSContext(),
mStateData.mResponseText.get(),
mStateData.mResponseText.Length());
mStateData.mResponse = STRING_TO_JSVAL(str);
if (!str) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
mStateData.mResponse = STRING_TO_JSVAL(str);
}
}
JS::ExposeValueToActiveJS(mStateData.mResponse);

View File

@ -0,0 +1,10 @@
onmessage = function() {
var a = new XMLHttpRequest();
a.open('GET', 'empty.html', false);
a.onreadystatechange = function() {
if (a.readyState == 4) {
postMessage(a.response);
}
}
a.send(null);
}

View File

View File

@ -99,6 +99,8 @@ support-files =
bug1104064_worker.js
worker_consoleAndBlobs.js
bug1132395_sharedWorker.js
bug1132924_worker.js
empty.html
[test_404.html]
[test_atob.html]
@ -201,3 +203,4 @@ skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s #bug 982828
[test_bug1104064.html]
[test_consoleAndBlobs.html]
[test_bug1132395.html]
[test_bug1132924.html]

View File

@ -0,0 +1,28 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Test for 1132924</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var w = new Worker('bug1132924_worker.js');
w.onmessage = function(event) {
ok(true, "We are still alive.");
SimpleTest.finish();
}
w.postMessage('go');
</script>
</pre>
</body>
</html>