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

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

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 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
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 19 matching lines...) Expand all
30 30
31 #include "wtf/PassRefPtr.h" 31 #include "wtf/PassRefPtr.h"
32 #include "wtf/RefCounted.h" 32 #include "wtf/RefCounted.h"
33 #include "wtf/RefPtr.h" 33 #include "wtf/RefPtr.h"
34 #include "wtf/WTFExport.h" 34 #include "wtf/WTFExport.h"
35 #include <limits.h> 35 #include <limits.h>
36 36
37 namespace WTF { 37 namespace WTF {
38 38
39 class WTF_EXPORT ArrayBufferView : public RefCounted<ArrayBufferView> { 39 class WTF_EXPORT ArrayBufferView : public RefCounted<ArrayBufferView> {
40 public: 40 public:
41 enum ViewType { 41 enum ViewType {
42 TypeInt8, 42 TypeInt8,
43 TypeUint8, 43 TypeUint8,
44 TypeUint8Clamped, 44 TypeUint8Clamped,
45 TypeInt16, 45 TypeInt16,
46 TypeUint16, 46 TypeUint16,
47 TypeInt32, 47 TypeInt32,
48 TypeUint32, 48 TypeUint32,
49 TypeFloat32, 49 TypeFloat32,
50 TypeFloat64, 50 TypeFloat64,
51 TypeDataView 51 TypeDataView
52 }; 52 };
53 virtual ViewType type() const = 0; 53 virtual ViewType type() const = 0;
54 const char* typeName(); 54 const char* typeName();
55 55
56 PassRefPtr<ArrayBuffer> buffer() const 56 PassRefPtr<ArrayBuffer> buffer() const { return m_buffer; }
57 {
58 return m_buffer;
59 }
60 57
61 void* baseAddress() const 58 void* baseAddress() const { return m_baseAddress; }
62 {
63 return m_baseAddress;
64 }
65 59
66 unsigned byteOffset() const 60 unsigned byteOffset() const { return m_byteOffset; }
67 {
68 return m_byteOffset;
69 }
70 61
71 virtual unsigned byteLength() const = 0; 62 virtual unsigned byteLength() const = 0;
72 63
73 void setNeuterable(bool flag) { m_isNeuterable = flag; } 64 void setNeuterable(bool flag) { m_isNeuterable = flag; }
74 bool isNeuterable() const { return m_isNeuterable; } 65 bool isNeuterable() const { return m_isNeuterable; }
75 bool isShared() const { return m_buffer ? m_buffer->isShared() : false; } 66 bool isShared() const { return m_buffer ? m_buffer->isShared() : false; }
76 67
77 virtual ~ArrayBufferView(); 68 virtual ~ArrayBufferView();
78 69
79 protected: 70 protected:
80 ArrayBufferView(PassRefPtr<ArrayBuffer>, unsigned byteOffset); 71 ArrayBufferView(PassRefPtr<ArrayBuffer>, unsigned byteOffset);
81 72
82 inline bool setImpl(ArrayBufferView*, unsigned byteOffset); 73 inline bool setImpl(ArrayBufferView*, unsigned byteOffset);
83 74
84 // Helper to verify that a given sub-range of an ArrayBuffer is 75 // Helper to verify that a given sub-range of an ArrayBuffer is
85 // within range. 76 // within range.
86 template <typename T> 77 template <typename T>
87 static bool verifySubRange(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffs et, unsigned numElements) 78 static bool verifySubRange(PassRefPtr<ArrayBuffer> buffer,
88 { 79 unsigned byteOffset,
89 if (!buffer) 80 unsigned numElements) {
90 return false; 81 if (!buffer)
91 if (sizeof(T) > 1 && byteOffset % sizeof(T)) 82 return false;
92 return false; 83 if (sizeof(T) > 1 && byteOffset % sizeof(T))
93 if (byteOffset > buffer->byteLength()) 84 return false;
94 return false; 85 if (byteOffset > buffer->byteLength())
95 unsigned remainingElements = (buffer->byteLength() - byteOffset) / sizeo f(T); 86 return false;
96 if (numElements > remainingElements) 87 unsigned remainingElements =
97 return false; 88 (buffer->byteLength() - byteOffset) / sizeof(T);
98 return true; 89 if (numElements > remainingElements)
99 } 90 return false;
91 return true;
92 }
100 93
101 virtual void neuter(); 94 virtual void neuter();
102 95
103 // This is the address of the ArrayBuffer's storage, plus the byte offset. 96 // This is the address of the ArrayBuffer's storage, plus the byte offset.
104 void* m_baseAddress; 97 void* m_baseAddress;
105 98
106 unsigned m_byteOffset : 31; 99 unsigned m_byteOffset : 31;
107 bool m_isNeuterable : 1; 100 bool m_isNeuterable : 1;
108 101
109 private: 102 private:
110 friend class ArrayBuffer; 103 friend class ArrayBuffer;
111 RefPtr<ArrayBuffer> m_buffer; 104 RefPtr<ArrayBuffer> m_buffer;
112 ArrayBufferView* m_prevView; 105 ArrayBufferView* m_prevView;
113 ArrayBufferView* m_nextView; 106 ArrayBufferView* m_nextView;
114 }; 107 };
115 108
116 bool ArrayBufferView::setImpl(ArrayBufferView* array, unsigned byteOffset) 109 bool ArrayBufferView::setImpl(ArrayBufferView* array, unsigned byteOffset) {
117 { 110 if (byteOffset > byteLength() ||
118 if (byteOffset > byteLength() 111 byteOffset + array->byteLength() > byteLength() ||
119 || byteOffset + array->byteLength() > byteLength() 112 byteOffset + array->byteLength() < byteOffset) {
120 || byteOffset + array->byteLength() < byteOffset) { 113 // Out of range offset or overflow
121 // Out of range offset or overflow 114 return false;
122 return false; 115 }
123 }
124 116
125 char* base = static_cast<char*>(baseAddress()); 117 char* base = static_cast<char*>(baseAddress());
126 memmove(base + byteOffset, array->baseAddress(), array->byteLength()); 118 memmove(base + byteOffset, array->baseAddress(), array->byteLength());
127 return true; 119 return true;
128 } 120 }
129 121
130 } // namespace WTF 122 } // namespace WTF
131 123
132 using WTF::ArrayBufferView; 124 using WTF::ArrayBufferView;
133 125
134 #endif // ArrayBufferView_h 126 #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