Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: third_party/WebKit/Source/wtf/ArrayBufferView.h

Issue 1875343002: Move WTF classes related to typed arrays to wtf/typed_arrays (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef ArrayBufferView_h
27 #define ArrayBufferView_h
28
29 #include "wtf/ArrayBuffer.h"
30
31 #include "wtf/PassRefPtr.h"
32 #include "wtf/RefCounted.h"
33 #include "wtf/RefPtr.h"
34 #include "wtf/WTFExport.h"
35 #include <limits.h>
36
37 namespace WTF {
38
39 class WTF_EXPORT ArrayBufferView : public RefCounted<ArrayBufferView> {
40 public:
41 enum ViewType {
42 TypeInt8,
43 TypeUint8,
44 TypeUint8Clamped,
45 TypeInt16,
46 TypeUint16,
47 TypeInt32,
48 TypeUint32,
49 TypeFloat32,
50 TypeFloat64,
51 TypeDataView
52 };
53 virtual ViewType type() const = 0;
54 const char* typeName();
55
56 PassRefPtr<ArrayBuffer> buffer() const
57 {
58 return m_buffer;
59 }
60
61 void* baseAddress() const
62 {
63 return m_baseAddress;
64 }
65
66 unsigned byteOffset() const
67 {
68 return m_byteOffset;
69 }
70
71 virtual unsigned byteLength() const = 0;
72
73 void setNeuterable(bool flag) { m_isNeuterable = flag; }
74 bool isNeuterable() const { return m_isNeuterable; }
75 bool isShared() const { return m_buffer ? m_buffer->isShared() : false; }
76
77 virtual ~ArrayBufferView();
78
79 protected:
80 ArrayBufferView(PassRefPtr<ArrayBuffer>, unsigned byteOffset);
81
82 inline bool setImpl(ArrayBufferView*, unsigned byteOffset);
83
84 // Helper to verify that a given sub-range of an ArrayBuffer is
85 // within range.
86 template <typename T>
87 static bool verifySubRange(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffs et, unsigned numElements)
88 {
89 if (!buffer)
90 return false;
91 if (sizeof(T) > 1 && byteOffset % sizeof(T))
92 return false;
93 if (byteOffset > buffer->byteLength())
94 return false;
95 unsigned remainingElements = (buffer->byteLength() - byteOffset) / sizeo f(T);
96 if (numElements > remainingElements)
97 return false;
98 return true;
99 }
100
101 virtual void neuter();
102
103 // This is the address of the ArrayBuffer's storage, plus the byte offset.
104 void* m_baseAddress;
105
106 unsigned m_byteOffset : 31;
107 bool m_isNeuterable : 1;
108
109 private:
110 friend class ArrayBuffer;
111 RefPtr<ArrayBuffer> m_buffer;
112 ArrayBufferView* m_prevView;
113 ArrayBufferView* m_nextView;
114 };
115
116 bool ArrayBufferView::setImpl(ArrayBufferView* array, unsigned byteOffset)
117 {
118 if (byteOffset > byteLength()
119 || byteOffset + array->byteLength() > byteLength()
120 || byteOffset + array->byteLength() < byteOffset) {
121 // Out of range offset or overflow
122 return false;
123 }
124
125 char* base = static_cast<char*>(baseAddress());
126 memmove(base + byteOffset, array->baseAddress(), array->byteLength());
127 return true;
128 }
129
130 } // namespace WTF
131
132 using WTF::ArrayBufferView;
133
134 #endif // ArrayBufferView_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/ArrayBufferContents.cpp ('k') | third_party/WebKit/Source/wtf/ArrayBufferView.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698