1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef DOMArrayBuffer_h
6 #define DOMArrayBuffer_h
8 #include "core/CoreExport.h"
9 #include "core/dom/DOMArrayBufferBase.h"
10 #include "wtf/ArrayBuffer.h"
14 class CORE_EXPORT DOMArrayBuffer final
: public DOMArrayBufferBase
{
15 DEFINE_WRAPPERTYPEINFO();
17 static PassRefPtr
<DOMArrayBuffer
> create(PassRefPtr
<WTF::ArrayBuffer
> buffer
)
19 return adoptRef(new DOMArrayBuffer(buffer
));
21 static PassRefPtr
<DOMArrayBuffer
> create(unsigned numElements
, unsigned elementByteSize
)
23 return create(WTF::ArrayBuffer::create(numElements
, elementByteSize
));
25 static PassRefPtr
<DOMArrayBuffer
> create(const void* source
, unsigned byteLength
)
27 return create(WTF::ArrayBuffer::create(source
, byteLength
));
29 static PassRefPtr
<DOMArrayBuffer
> create(WTF::ArrayBufferContents
& contents
)
31 return create(WTF::ArrayBuffer::create(contents
));
34 // Only for use by XMLHttpRequest::responseArrayBuffer and
35 // Internals::serializeObject.
36 static PassRefPtr
<DOMArrayBuffer
> createUninitialized(unsigned numElements
, unsigned elementByteSize
)
38 return create(WTF::ArrayBuffer::createUninitialized(numElements
, elementByteSize
));
41 PassRefPtr
<DOMArrayBuffer
> slice(int begin
, int end
) const
43 return create(buffer()->slice(begin
, end
));
45 PassRefPtr
<DOMArrayBuffer
> slice(int begin
) const
47 return create(buffer()->slice(begin
));
50 v8::Local
<v8::Object
> wrap(v8::Isolate
*, v8::Local
<v8::Object
> creationContext
) override
;
53 explicit DOMArrayBuffer(PassRefPtr
<WTF::ArrayBuffer
> buffer
)
54 : DOMArrayBufferBase(buffer
)
61 #endif // DOMArrayBuffer_h