Commit 5a4d8e88 authored by dmurph@chromium.org's avatar dmurph@chromium.org

Adding ArrayBufferView as a constructor type to Response

BUG=412027

Review URL: https://codereview.chromium.org/558793002

git-svn-id: svn://svn.chromium.org/blink/trunk@181762 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent bd8429d0
......@@ -28,4 +28,38 @@ promise_test(function() {
'Response body ArrayBuffer should match ArrayBuffer ' +
'it was constructed with.');
});
}, 'Behavior of Response with arraybuffer content.');
\ No newline at end of file
}, 'Behavior of Response with ArrayBuffer content.');
promise_test(function() {
var intView = new Int32Array([0, 1, 2, 3, 4, 55, 6, 7, 8, 9]);
var response = new Response(intView);
assert_false(response.headers.has('Content-Type'),
'A Response constructed with ArrayBufferView ' +
'should not have a content type.');
return response.body.asArrayBuffer()
.then(function(buffer) {
var resultIntView = new Int32Array(buffer);
assert_array_equals(
resultIntView, [0, 1, 2, 3, 4, 55, 6, 7, 8, 9],
'Response body ArrayBuffer should match ArrayBufferView ' +
'it was constructed with.');
});
}, 'Behavior of Response with ArrayBufferView content without a slice.');
promise_test(function() {
var intView = new Int32Array([0, 1, 2, 3, 4, 55, 6, 7, 8, 9]);
var slice = intView.subarray(1, 4); // Should be [1, 2, 3]
var response = new Response(slice);
assert_false(response.headers.has('Content-Type'),
'A Response constructed with ArrayBufferView ' +
'should not have a content type.');
return response.body.asArrayBuffer()
.then(function(buffer) {
var resultIntView = new Int32Array(buffer);
assert_array_equals(
resultIntView, [1, 2, 3],
'Response body ArrayBuffer should match ArrayBufferView ' +
'slice it was constructed with.');
});
}, 'Behavior of Response with ArrayBufferView content with a slice.');
......@@ -12,6 +12,8 @@
#include "modules/serviceworkers/ResponseInit.h"
#include "public/platform/WebServiceWorkerResponse.h"
#include "wtf/ArrayBuffer.h"
#include "wtf/ArrayBufferView.h"
#include "wtf/RefPtr.h"
namespace blink {
......@@ -70,6 +72,15 @@ Response* Response::create(const ArrayBuffer* body, const Dictionary& responseIn
return create(blob.get(), ResponseInit(responseInit), exceptionState);
}
Response* Response::create(const ArrayBufferView* body, const Dictionary& responseInit, ExceptionState& exceptionState)
{
OwnPtr<BlobData> blobData = BlobData::create();
blobData->appendArrayBufferView(body);
const long long length = blobData->length();
RefPtrWillBeRawPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData.release(), length));
return create(blob.get(), ResponseInit(responseInit), exceptionState);
}
Response* Response::create(Blob* body, const ResponseInit& responseInit, ExceptionState& exceptionState)
{
// "1. If |init|'s status member is not in the range 200 to 599, throw a
......
......@@ -12,8 +12,7 @@
#include "modules/serviceworkers/Headers.h"
#include "platform/blob/BlobData.h"
#include "platform/heap/Handle.h"
#include "wtf/RefPtr.h"
#include "wtf/text/WTFString.h"
#include "wtf/Forward.h"
namespace blink {
......@@ -28,6 +27,7 @@ public:
static Response* create(Blob*, const Dictionary&, ExceptionState&);
static Response* create(const String&, const Dictionary&, ExceptionState&);
static Response* create(const ArrayBuffer*, const Dictionary&, ExceptionState&);
static Response* create(const ArrayBufferView*, const Dictionary&, ExceptionState&);
static Response* create(Blob*, const ResponseInit&, ExceptionState&);
static Response* create(FetchResponseData*);
static Response* create(const WebServiceWorkerResponse&);
......
......@@ -7,11 +7,11 @@
enum ResponseType { "basic", "cors", "default", "error", "opaque" };
[
// FIXME: Add ctors for ArrayBufferView, FormData and URLSearchParams
// response bodies.
// FIXME: Add ctors for FormData and URLSearchParams response bodies.
Constructor(ScalarValueString body, optional Dictionary responseInitDict),
Constructor(Blob? body, optional Dictionary responseInitDict),
Constructor(ArrayBuffer input, optional Dictionary requestInitDict),
Constructor(ArrayBufferView input, optional Dictionary requestInitDict),
RuntimeEnabled=ServiceWorker,
Exposed=ServiceWorker,
RaisesException=Constructor,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment