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

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

Issue 1414553002: Fix out-of-memory crashes related to ArrayBuffer allocation Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase+more tweaks Created 5 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/wtf/Int8Array.h ('k') | third_party/WebKit/Source/wtf/Uint16Array.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (c) 2010, Google Inc. All rights reserved. 3 * Copyright (c) 2010, Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 66 }
67 67
68 protected: 68 protected:
69 TypedArrayBase(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) 69 TypedArrayBase(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length)
70 : ArrayBufferView(buffer, byteOffset) 70 : ArrayBufferView(buffer, byteOffset)
71 , m_length(length) 71 , m_length(length)
72 { 72 {
73 } 73 }
74 74
75 template <class Subclass> 75 template <class Subclass>
76 static PassRefPtr<Subclass> create(unsigned length) 76 static PassRefPtr<Subclass> createOrNull(unsigned length)
77 { 77 {
78 RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(length, sizeof(T)); 78 RefPtr<ArrayBuffer> buffer = ArrayBuffer::createOrNull(length, sizeof(T) );
79 if (!buffer)
80 return nullptr;
79 return create<Subclass>(buffer.release(), 0, length); 81 return create<Subclass>(buffer.release(), 0, length);
80 } 82 }
81 83
82 template <class Subclass> 84 template <class Subclass>
83 static PassRefPtr<Subclass> create(const T* array, unsigned length) 85 static PassRefPtr<Subclass> createOrNull(const T* array, unsigned length)
84 { 86 {
85 RefPtr<Subclass> a = create<Subclass>(length); 87 RefPtr<Subclass> a = createOrNull<Subclass>(length);
86 if (a) 88 if (a)
87 for (unsigned i = 0; i < length; ++i) 89 for (unsigned i = 0; i < length; ++i)
88 a->set(i, array[i]); 90 a->set(i, array[i]);
89 return a; 91 return a;
90 } 92 }
91 93
92 template <class Subclass> 94 template <class Subclass>
95 static PassRefPtr<Subclass> deprecatedCreateOrCrash(unsigned length)
96 {
97 RefPtr<ArrayBuffer> buffer = ArrayBuffer::deprecatedCreateOrCrash(length , sizeof(T));
98 if (!buffer)
99 return nullptr;
100 return create<Subclass>(buffer.release(), 0, length);
101 }
102
103 template <class Subclass>
104 static PassRefPtr<Subclass> deprecatedCreateOrCrash(const T* array, unsigned length)
105 {
106 RefPtr<Subclass> a = deprecatedCreateOrCrash<Subclass>(length);
107 if (a)
108 for (unsigned i = 0; i < length; ++i)
109 a->set(i, array[i]);
110 return a;
111 }
112
113 template <class Subclass>
93 static PassRefPtr<Subclass> create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length) 114 static PassRefPtr<Subclass> create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length)
94 { 115 {
95 RefPtr<ArrayBuffer> buf(buffer); 116 RefPtr<ArrayBuffer> buf(buffer);
96 RELEASE_ASSERT(verifySubRange<T>(buf, byteOffset, length)); 117 RELEASE_ASSERT(verifySubRange<T>(buf, byteOffset, length));
97 return adoptRef(new Subclass(buf.release(), byteOffset, length)); 118 return adoptRef(new Subclass(buf.release(), byteOffset, length));
98 } 119 }
99 120
100 template <class Subclass>
101 static PassRefPtr<Subclass> createOrNull(unsigned length)
102 {
103 RefPtr<ArrayBuffer> buffer = ArrayBuffer::createOrNull(length, sizeof(T) );
104 if (!buffer)
105 return nullptr;
106 return create<Subclass>(buffer.release(), 0, length);
107 }
108
109 void neuter() final 121 void neuter() final
110 { 122 {
111 ArrayBufferView::neuter(); 123 ArrayBufferView::neuter();
112 m_length = 0; 124 m_length = 0;
113 } 125 }
114 126
115 // We do not want to have to access this via a virtual function in subclasse s, 127 // We do not want to have to access this via a virtual function in subclasse s,
116 // which is why it is protected rather than private. 128 // which is why it is protected rather than private.
117 unsigned m_length; 129 unsigned m_length;
118 }; 130 };
119 131
120 } // namespace WTF 132 } // namespace WTF
121 133
122 using WTF::TypedArrayBase; 134 using WTF::TypedArrayBase;
123 135
124 #endif // TypedArrayBase_h 136 #endif // TypedArrayBase_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/Int8Array.h ('k') | third_party/WebKit/Source/wtf/Uint16Array.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698