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

Side by Side Diff: Source/wtf/ArrayBufferContents.cpp

Issue 1302193002: Set ArrayBufferContents size to 0 on allocation failure (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « Source/wtf/ArrayBuffer.h ('k') | no next file » | 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) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 m_sizeInBytes = 0; 127 m_sizeInBytes = 0;
128 m_isShared = NotShared; 128 m_isShared = NotShared;
129 } 129 }
130 130
131 void ArrayBufferContents::DataHolder::allocateNew(unsigned sizeInBytes, SharingT ype isShared, InitializationPolicy policy) 131 void ArrayBufferContents::DataHolder::allocateNew(unsigned sizeInBytes, SharingT ype isShared, InitializationPolicy policy)
132 { 132 {
133 ASSERT(!m_data); 133 ASSERT(!m_data);
134 void* data = nullptr; 134 void* data = nullptr;
135 allocateMemory(sizeInBytes, policy, data); 135 allocateMemory(sizeInBytes, policy, data);
136 m_data = data; 136 m_data = data;
137 m_sizeInBytes = sizeInBytes; 137 m_sizeInBytes = data ? sizeInBytes : 0;
138 m_isShared = isShared; 138 m_isShared = isShared;
139 } 139 }
140 140
141 void ArrayBufferContents::DataHolder::adopt(void* data, unsigned sizeInBytes, Sh aringType isShared) 141 void ArrayBufferContents::DataHolder::adopt(void* data, unsigned sizeInBytes, Sh aringType isShared)
142 { 142 {
143 ASSERT(!m_data); 143 ASSERT(!m_data);
144 m_data = data; 144 m_data = data;
145 m_sizeInBytes = sizeInBytes; 145 m_sizeInBytes = sizeInBytes;
146 m_isShared = isShared; 146 m_isShared = isShared;
147 } 147 }
148 148
149 void ArrayBufferContents::DataHolder::copyMemoryTo(DataHolder& other) 149 void ArrayBufferContents::DataHolder::copyMemoryTo(DataHolder& other)
150 { 150 {
151 ASSERT(!other.m_sizeInBytes); 151 ASSERT(!other.m_sizeInBytes);
152 ArrayBufferContents::freeMemory(other.m_data, other.m_sizeInBytes); 152 ArrayBufferContents::freeMemory(other.m_data, other.m_sizeInBytes);
153 ArrayBufferContents::allocateMemory(m_sizeInBytes, DontInitialize, other.m_d ata); 153 ArrayBufferContents::allocateMemory(m_sizeInBytes, DontInitialize, other.m_d ata);
154 if (!other.m_data) 154 if (!other.m_data)
155 return; 155 return;
156 memcpy(other.m_data, m_data, m_sizeInBytes); 156 memcpy(other.m_data, m_data, m_sizeInBytes);
157 other.m_sizeInBytes = m_sizeInBytes; 157 other.m_sizeInBytes = m_sizeInBytes;
158 } 158 }
159 159
160 } // namespace WTF 160 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/ArrayBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698