OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "wtf/typed_arrays/ArrayPiece.h" | |
6 | |
7 #include "wtf/Assertions.h" | |
8 #include "wtf/typed_arrays/ArrayBuffer.h" | |
9 #include "wtf/typed_arrays/ArrayBufferView.h" | |
10 | |
11 namespace WTF { | |
12 | |
13 ArrayPiece::ArrayPiece() { | |
14 initNull(); | |
15 } | |
16 | |
17 ArrayPiece::ArrayPiece(void* data, unsigned byteLength) { | |
18 initWithData(data, byteLength); | |
19 } | |
20 | |
21 ArrayPiece::ArrayPiece(ArrayBuffer* buffer) { | |
22 if (buffer) { | |
23 initWithData(buffer->data(), buffer->byteLength()); | |
24 } else { | |
25 initNull(); | |
26 } | |
27 } | |
28 | |
29 ArrayPiece::ArrayPiece(ArrayBufferView* buffer) { | |
30 if (buffer) { | |
31 initWithData(buffer->baseAddress(), buffer->byteLength()); | |
32 } else { | |
33 initNull(); | |
34 } | |
35 } | |
36 | |
37 bool ArrayPiece::isNull() const { | |
38 return m_isNull; | |
39 } | |
40 | |
41 void* ArrayPiece::data() const { | |
42 DCHECK(!isNull()); | |
43 return m_data; | |
44 } | |
45 | |
46 unsigned char* ArrayPiece::bytes() const { | |
47 return static_cast<unsigned char*>(data()); | |
48 } | |
49 | |
50 unsigned ArrayPiece::byteLength() const { | |
51 DCHECK(!isNull()); | |
52 return m_byteLength; | |
53 } | |
54 | |
55 void ArrayPiece::initWithData(void* data, unsigned byteLength) { | |
56 m_byteLength = byteLength; | |
57 m_data = data; | |
58 m_isNull = false; | |
59 } | |
60 | |
61 void ArrayPiece::initNull() { | |
62 m_byteLength = 0; | |
63 m_data = 0; | |
64 m_isNull = true; | |
65 } | |
66 | |
67 } // namespace WTF | |
OLD | NEW |