Protect SerializedData from copying.

Compiler-generated copy constructor does not generate
correct code for this class, so make it move-only type.

Review-Url: https://codereview.chromium.org/2781993005
Cr-Commit-Position: refs/heads/master@{#44266}
This commit is contained in:
vchigrin 2017-03-30 04:44:14 -07:00 committed by Commit bot
parent d389d473a7
commit b6912850df
3 changed files with 13 additions and 4 deletions

View File

@ -485,7 +485,7 @@ Vector<const uint32_t> SerializedCodeData::CodeStubKeys() const {
SerializedCodeData::SerializedCodeData(ScriptData* data)
: SerializedData(const_cast<byte*>(data->data()), data->length()) {}
const SerializedCodeData SerializedCodeData::FromCachedData(
SerializedCodeData SerializedCodeData::FromCachedData(
Isolate* isolate, ScriptData* cached_data, uint32_t expected_source_hash,
SanityCheckResult* rejection_result) {
DisallowHeapAllocation no_gc;

View File

@ -116,8 +116,9 @@ class SerializedCodeData : public SerializedData {
static const int kHeaderSize = POINTER_SIZE_ALIGN(kUnalignedHeaderSize);
// Used when consuming.
static const SerializedCodeData FromCachedData(
Isolate* isolate, ScriptData* cached_data, uint32_t expected_source_hash,
static SerializedCodeData FromCachedData(Isolate* isolate,
ScriptData* cached_data,
uint32_t expected_source_hash,
SanityCheckResult* rejection_result);
// Used when producing.

View File

@ -239,6 +239,11 @@ class SerializedData {
SerializedData(byte* data, int size)
: data_(data), size_(size), owns_data_(false) {}
SerializedData() : data_(NULL), size_(0), owns_data_(false) {}
SerializedData(SerializedData&& other)
: data_(other.data_), size_(other.size_), owns_data_(other.owns_data_) {
// Ensure |other| will not attempt to destroy our data in destructor.
other.owns_data_ = false;
}
~SerializedData() {
if (owns_data_) DeleteArray<byte>(data_);
@ -295,6 +300,9 @@ class SerializedData {
byte* data_;
int size_;
bool owns_data_;
private:
DISALLOW_COPY_AND_ASSIGN(SerializedData);
};
} // namespace internal