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

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 solution which doesn't modify behaviour of existing code, apart from JS TypedArrays 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 * 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 void ArrayBufferContents::allocateMemory(size_t size, InitializationPolicy polic y, void*& data) 100 void ArrayBufferContents::allocateMemory(size_t size, InitializationPolicy polic y, void*& data)
101 { 101 {
102 if (s_adjustAmountOfExternalAllocatedMemoryFunction) 102 if (s_adjustAmountOfExternalAllocatedMemoryFunction)
103 s_adjustAmountOfExternalAllocatedMemoryFunction(static_cast<int>(size)); 103 s_adjustAmountOfExternalAllocatedMemoryFunction(static_cast<int>(size));
104 data = partitionAllocGeneric(WTF::Partitions::bufferPartition(), size, WTF_H EAP_PROFILER_TYPE_NAME(ArrayBufferContents)); 104 data = partitionAllocGeneric(WTF::Partitions::bufferPartition(), size, WTF_H EAP_PROFILER_TYPE_NAME(ArrayBufferContents));
105 if (policy == ZeroInitialize && data) 105 if (policy == ZeroInitialize && data)
106 memset(data, '\0', size); 106 memset(data, '\0', size);
107 } 107 }
108 108
109 void ArrayBufferContents::allocateMemoryOrNull(size_t size, InitializationPolicy policy, void*& data)
110 {
111 if (s_adjustAmountOfExternalAllocatedMemoryFunction)
112 s_adjustAmountOfExternalAllocatedMemoryFunction(static_cast<int>(size));
113 data = partitionAllocGenericFlags(WTF::Partitions::bufferPartition(), Partit ionAllocReturnNull, size, WTF_HEAP_PROFILER_TYPE_NAME(ArrayBufferContents));
114 if (policy == ZeroInitialize && data)
115 memset(data, '\0', size);
116 }
Dan Ehrenberg 2016/01/13 22:55:14 Any way you could reduce the duplication here with
caitp (gmail) 2016/01/13 23:41:10 done
117
109 void ArrayBufferContents::freeMemory(void* data, size_t size) 118 void ArrayBufferContents::freeMemory(void* data, size_t size)
110 { 119 {
111 Partitions::bufferFree(data); 120 Partitions::bufferFree(data);
112 if (s_adjustAmountOfExternalAllocatedMemoryFunction) 121 if (s_adjustAmountOfExternalAllocatedMemoryFunction)
113 s_adjustAmountOfExternalAllocatedMemoryFunction(-static_cast<int>(size)) ; 122 s_adjustAmountOfExternalAllocatedMemoryFunction(-static_cast<int>(size)) ;
114 } 123 }
115 124
116 ArrayBufferContents::DataHolder::DataHolder() 125 ArrayBufferContents::DataHolder::DataHolder()
117 : m_data(nullptr) 126 : m_data(nullptr)
118 , m_sizeInBytes(0) 127 , m_sizeInBytes(0)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 ASSERT(!other.m_sizeInBytes); 159 ASSERT(!other.m_sizeInBytes);
151 ArrayBufferContents::freeMemory(other.m_data, other.m_sizeInBytes); 160 ArrayBufferContents::freeMemory(other.m_data, other.m_sizeInBytes);
152 ArrayBufferContents::allocateMemory(m_sizeInBytes, DontInitialize, other.m_d ata); 161 ArrayBufferContents::allocateMemory(m_sizeInBytes, DontInitialize, other.m_d ata);
153 if (!other.m_data) 162 if (!other.m_data)
154 return; 163 return;
155 memcpy(other.m_data, m_data, m_sizeInBytes); 164 memcpy(other.m_data, m_data, m_sizeInBytes);
156 other.m_sizeInBytes = m_sizeInBytes; 165 other.m_sizeInBytes = m_sizeInBytes;
157 } 166 }
158 167
159 } // namespace WTF 168 } // namespace WTF
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698