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

Side by Side Diff: src/objects.cc

Issue 1337943005: Fix initialization order (setup) for JSArrayBuffer objects. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix DCHECK for bytelength and compilation Created 5 years, 3 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 | « no previous file | 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 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/objects.h" 5 #include "src/objects.h"
6 6
7 #include <iomanip> 7 #include <iomanip>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 16114 matching lines...) Expand 10 before | Expand all | Expand 10 after
16125 16125
16126 16126
16127 void JSArrayBuffer::Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate, 16127 void JSArrayBuffer::Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate,
16128 bool is_external, void* data, size_t allocated_length, 16128 bool is_external, void* data, size_t allocated_length,
16129 SharedFlag shared) { 16129 SharedFlag shared) {
16130 DCHECK(array_buffer->GetInternalFieldCount() == 16130 DCHECK(array_buffer->GetInternalFieldCount() ==
16131 v8::ArrayBuffer::kInternalFieldCount); 16131 v8::ArrayBuffer::kInternalFieldCount);
16132 for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) { 16132 for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) {
16133 array_buffer->SetInternalField(i, Smi::FromInt(0)); 16133 array_buffer->SetInternalField(i, Smi::FromInt(0));
16134 } 16134 }
16135 array_buffer->set_backing_store(data);
16136 array_buffer->set_bit_field(0); 16135 array_buffer->set_bit_field(0);
16137 array_buffer->set_is_external(is_external); 16136 array_buffer->set_is_external(is_external);
16138 array_buffer->set_is_neuterable(shared == SharedFlag::kNotShared); 16137 array_buffer->set_is_neuterable(shared == SharedFlag::kNotShared);
16139 array_buffer->set_is_shared(shared == SharedFlag::kShared); 16138 array_buffer->set_is_shared(shared == SharedFlag::kShared);
16140 16139
16141 Handle<Object> byte_length = 16140 Handle<Object> byte_length =
16142 isolate->factory()->NewNumberFromSize(allocated_length); 16141 isolate->factory()->NewNumberFromSize(allocated_length);
16143 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber()); 16142 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber());
16144 array_buffer->set_byte_length(*byte_length); 16143 array_buffer->set_byte_length(*byte_length);
16144 // Initialize backing store at last to avoid handling of |JSArrayBuffers| that
16145 // are currently being constructed in the |ArrayBufferTracker|. The
16146 // registration method below handles the case of registering a buffer that has
16147 // already been promoted.
16148 array_buffer->set_backing_store(data);
16145 16149
16146 if (data && !is_external) { 16150 if (data && !is_external) {
16147 isolate->heap()->RegisterNewArrayBuffer(*array_buffer); 16151 isolate->heap()->RegisterNewArrayBuffer(*array_buffer);
16148 } 16152 }
16149 } 16153 }
16150 16154
16151 16155
16152 bool JSArrayBuffer::SetupAllocatingData(Handle<JSArrayBuffer> array_buffer, 16156 bool JSArrayBuffer::SetupAllocatingData(Handle<JSArrayBuffer> array_buffer,
16153 Isolate* isolate, 16157 Isolate* isolate,
16154 size_t allocated_length, 16158 size_t allocated_length,
(...skipping 29 matching lines...) Expand all
16184 DCHECK(IsFixedTypedArrayElementsKind(map->elements_kind())); 16188 DCHECK(IsFixedTypedArrayElementsKind(map->elements_kind()));
16185 16189
16186 Handle<FixedTypedArrayBase> fixed_typed_array( 16190 Handle<FixedTypedArrayBase> fixed_typed_array(
16187 FixedTypedArrayBase::cast(typed_array->elements())); 16191 FixedTypedArrayBase::cast(typed_array->elements()));
16188 16192
16189 Handle<JSArrayBuffer> buffer(JSArrayBuffer::cast(typed_array->buffer()), 16193 Handle<JSArrayBuffer> buffer(JSArrayBuffer::cast(typed_array->buffer()),
16190 isolate); 16194 isolate);
16191 void* backing_store = 16195 void* backing_store =
16192 isolate->array_buffer_allocator()->AllocateUninitialized( 16196 isolate->array_buffer_allocator()->AllocateUninitialized(
16193 fixed_typed_array->DataSize()); 16197 fixed_typed_array->DataSize());
16198 buffer->set_is_external(false);
16199 DCHECK(buffer->byte_length()->IsSmi() ||
16200 buffer->byte_length()->IsHeapNumber());
16201 DCHECK(NumberToInt32(buffer->byte_length()) == fixed_typed_array->DataSize());
16202 // Initialize backing store at last to avoid handling of |JSArrayBuffers| that
16203 // are currently being constructed in the |ArrayBufferTracker|. The
16204 // registration method below handles the case of registering a buffer that has
16205 // already been promoted.
16194 buffer->set_backing_store(backing_store); 16206 buffer->set_backing_store(backing_store);
16195 buffer->set_is_external(false);
16196 isolate->heap()->RegisterNewArrayBuffer(*buffer); 16207 isolate->heap()->RegisterNewArrayBuffer(*buffer);
16197 memcpy(buffer->backing_store(), 16208 memcpy(buffer->backing_store(),
16198 fixed_typed_array->DataPtr(), 16209 fixed_typed_array->DataPtr(),
16199 fixed_typed_array->DataSize()); 16210 fixed_typed_array->DataSize());
16200 Handle<FixedTypedArrayBase> new_elements = 16211 Handle<FixedTypedArrayBase> new_elements =
16201 isolate->factory()->NewFixedTypedArrayWithExternalPointer( 16212 isolate->factory()->NewFixedTypedArrayWithExternalPointer(
16202 fixed_typed_array->length(), typed_array->type(), 16213 fixed_typed_array->length(), typed_array->type(),
16203 static_cast<uint8_t*>(buffer->backing_store())); 16214 static_cast<uint8_t*>(buffer->backing_store()));
16204 16215
16205 typed_array->set_elements(*new_elements); 16216 typed_array->set_elements(*new_elements);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
16352 if (cell->value() != *new_value) { 16363 if (cell->value() != *new_value) {
16353 cell->set_value(*new_value); 16364 cell->set_value(*new_value);
16354 Isolate* isolate = cell->GetIsolate(); 16365 Isolate* isolate = cell->GetIsolate();
16355 cell->dependent_code()->DeoptimizeDependentCodeGroup( 16366 cell->dependent_code()->DeoptimizeDependentCodeGroup(
16356 isolate, DependentCode::kPropertyCellChangedGroup); 16367 isolate, DependentCode::kPropertyCellChangedGroup);
16357 } 16368 }
16358 } 16369 }
16359 16370
16360 } // namespace internal 16371 } // namespace internal
16361 } // namespace v8 16372 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698