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

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

Issue 1577783004: [v8] don't crash when ArrayBuffer allocation fails (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a little comment explaining the contract 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
« no previous file with comments | « third_party/WebKit/Source/wtf/ArrayBufferContents.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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 ASSERT(!other.m_holder->data()); 90 ASSERT(!other.m_holder->data());
91 other.m_holder = m_holder; 91 other.m_holder = m_holder;
92 } 92 }
93 93
94 void ArrayBufferContents::copyTo(ArrayBufferContents& other) 94 void ArrayBufferContents::copyTo(ArrayBufferContents& other)
95 { 95 {
96 ASSERT(!m_holder->isShared() && !other.m_holder->isShared()); 96 ASSERT(!m_holder->isShared() && !other.m_holder->isShared());
97 m_holder->copyMemoryTo(*other.m_holder); 97 m_holder->copyMemoryTo(*other.m_holder);
98 } 98 }
99 99
100 void ArrayBufferContents::allocateMemoryWithFlags(size_t size, InitializationPol icy policy, int flags, void*& data)
101 {
102 if (s_adjustAmountOfExternalAllocatedMemoryFunction)
103 s_adjustAmountOfExternalAllocatedMemoryFunction(static_cast<int>(size));
104 data = partitionAllocGenericFlags(WTF::Partitions::bufferPartition(), flags, size, WTF_HEAP_PROFILER_TYPE_NAME(ArrayBufferContents));
105 if (policy == ZeroInitialize && data)
106 memset(data, '\0', size);
107 }
108
100 void ArrayBufferContents::allocateMemory(size_t size, InitializationPolicy polic y, void*& data) 109 void ArrayBufferContents::allocateMemory(size_t size, InitializationPolicy polic y, void*& data)
101 { 110 {
102 if (s_adjustAmountOfExternalAllocatedMemoryFunction) 111 allocateMemoryWithFlags(size, policy, 0, data);
103 s_adjustAmountOfExternalAllocatedMemoryFunction(static_cast<int>(size)); 112 }
104 data = partitionAllocGeneric(WTF::Partitions::bufferPartition(), size, WTF_H EAP_PROFILER_TYPE_NAME(ArrayBufferContents)); 113
105 if (policy == ZeroInitialize && data) 114 void ArrayBufferContents::allocateMemoryOrNull(size_t size, InitializationPolicy policy, void*& data)
106 memset(data, '\0', size); 115 {
116 allocateMemoryWithFlags(size, policy, PartitionAllocReturnNull, data);
107 } 117 }
108 118
109 void ArrayBufferContents::freeMemory(void* data, size_t size) 119 void ArrayBufferContents::freeMemory(void* data, size_t size)
110 { 120 {
111 Partitions::bufferFree(data); 121 Partitions::bufferFree(data);
112 if (s_adjustAmountOfExternalAllocatedMemoryFunction) 122 if (s_adjustAmountOfExternalAllocatedMemoryFunction)
113 s_adjustAmountOfExternalAllocatedMemoryFunction(-static_cast<int>(size)) ; 123 s_adjustAmountOfExternalAllocatedMemoryFunction(-static_cast<int>(size)) ;
114 } 124 }
115 125
116 ArrayBufferContents::DataHolder::DataHolder() 126 ArrayBufferContents::DataHolder::DataHolder()
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 ASSERT(!other.m_sizeInBytes); 160 ASSERT(!other.m_sizeInBytes);
151 ArrayBufferContents::freeMemory(other.m_data, other.m_sizeInBytes); 161 ArrayBufferContents::freeMemory(other.m_data, other.m_sizeInBytes);
152 ArrayBufferContents::allocateMemory(m_sizeInBytes, DontInitialize, other.m_d ata); 162 ArrayBufferContents::allocateMemory(m_sizeInBytes, DontInitialize, other.m_d ata);
153 if (!other.m_data) 163 if (!other.m_data)
154 return; 164 return;
155 memcpy(other.m_data, m_data, m_sizeInBytes); 165 memcpy(other.m_data, m_data, m_sizeInBytes);
156 other.m_sizeInBytes = m_sizeInBytes; 166 other.m_sizeInBytes = m_sizeInBytes;
157 } 167 }
158 168
159 } // namespace WTF 169 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/ArrayBufferContents.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698