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

Side by Side Diff: src/objects-inl.h

Issue 1107843002: Reland "Remove the weak list of views from array buffers" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: use bounds check Created 5 years, 7 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 | « src/objects-debug.cc ('k') | src/runtime/runtime-typedarray.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 // Review notes: 5 // Review notes:
6 // 6 //
7 // - The use of macros in these inline functions may seem superfluous 7 // - The use of macros in these inline functions may seem superfluous
8 // but it is absolutely needed to make sure gcc generates optimal 8 // but it is absolutely needed to make sure gcc generates optimal
9 // code. gcc is not happy when attempting to inline too deep. 9 // code. gcc is not happy when attempting to inline too deep.
10 // 10 //
(...skipping 4359 matching lines...) Expand 10 before | Expand all | Expand 10 after
4370 template <class Traits> 4370 template <class Traits>
4371 Handle<Object> FixedTypedArray<Traits>::get( 4371 Handle<Object> FixedTypedArray<Traits>::get(
4372 Handle<FixedTypedArray<Traits> > array, 4372 Handle<FixedTypedArray<Traits> > array,
4373 int index) { 4373 int index) {
4374 return Traits::ToHandle(array->GetIsolate(), array->get_scalar(index)); 4374 return Traits::ToHandle(array->GetIsolate(), array->get_scalar(index));
4375 } 4375 }
4376 4376
4377 4377
4378 template <class Traits> 4378 template <class Traits>
4379 Handle<Object> FixedTypedArray<Traits>::SetValue( 4379 Handle<Object> FixedTypedArray<Traits>::SetValue(
4380 Handle<FixedTypedArray<Traits> > array, 4380 Handle<JSObject> holder, Handle<FixedTypedArray<Traits> > array,
4381 uint32_t index, 4381 uint32_t index, Handle<Object> value) {
4382 Handle<Object> value) {
4383 ElementType cast_value = Traits::defaultValue(); 4382 ElementType cast_value = Traits::defaultValue();
4384 if (index < static_cast<uint32_t>(array->length())) { 4383 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder);
4385 if (value->IsSmi()) { 4384 if (!view->WasNeutered()) {
4386 int int_value = Handle<Smi>::cast(value)->value(); 4385 if (index < static_cast<uint32_t>(array->length())) {
4387 cast_value = from_int(int_value); 4386 if (value->IsSmi()) {
4388 } else if (value->IsHeapNumber()) { 4387 int int_value = Handle<Smi>::cast(value)->value();
4389 double double_value = Handle<HeapNumber>::cast(value)->value(); 4388 cast_value = from_int(int_value);
4390 cast_value = from_double(double_value); 4389 } else if (value->IsHeapNumber()) {
4391 } else { 4390 double double_value = Handle<HeapNumber>::cast(value)->value();
4392 // Clamp undefined to the default value. All other types have been 4391 cast_value = from_double(double_value);
4393 // converted to a number type further up in the call chain. 4392 } else {
4394 DCHECK(value->IsUndefined()); 4393 // Clamp undefined to the default value. All other types have been
4394 // converted to a number type further up in the call chain.
4395 DCHECK(value->IsUndefined());
4396 }
4397 array->set(index, cast_value);
4395 } 4398 }
4396 array->set(index, cast_value);
4397 } 4399 }
4398 return Traits::ToHandle(array->GetIsolate(), cast_value); 4400 return Traits::ToHandle(array->GetIsolate(), cast_value);
4399 } 4401 }
4400 4402
4401 4403
4402 Handle<Object> Uint8ArrayTraits::ToHandle(Isolate* isolate, uint8_t scalar) { 4404 Handle<Object> Uint8ArrayTraits::ToHandle(Isolate* isolate, uint8_t scalar) {
4403 return handle(Smi::FromInt(scalar), isolate); 4405 return handle(Smi::FromInt(scalar), isolate);
4404 } 4406 }
4405 4407
4406 4408
(...skipping 2041 matching lines...) Expand 10 before | Expand all | Expand 10 after
6448 bool JSArrayBuffer::is_neuterable() { 6450 bool JSArrayBuffer::is_neuterable() {
6449 return BooleanBit::get(flag(), kIsNeuterableBit); 6451 return BooleanBit::get(flag(), kIsNeuterableBit);
6450 } 6452 }
6451 6453
6452 6454
6453 void JSArrayBuffer::set_is_neuterable(bool value) { 6455 void JSArrayBuffer::set_is_neuterable(bool value) {
6454 set_flag(BooleanBit::set(flag(), kIsNeuterableBit, value)); 6456 set_flag(BooleanBit::set(flag(), kIsNeuterableBit, value));
6455 } 6457 }
6456 6458
6457 6459
6460 bool JSArrayBuffer::was_neutered() {
6461 return BooleanBit::get(flag(), kWasNeuteredBit);
6462 }
6463
6464
6465 void JSArrayBuffer::set_was_neutered(bool value) {
6466 set_flag(BooleanBit::set(flag(), kWasNeuteredBit, value));
6467 }
6468
6469
6458 ACCESSORS(JSArrayBuffer, weak_next, Object, kWeakNextOffset) 6470 ACCESSORS(JSArrayBuffer, weak_next, Object, kWeakNextOffset)
6459 ACCESSORS(JSArrayBuffer, weak_first_view, Object, kWeakFirstViewOffset) 6471
6472
6473 Object* JSArrayBufferView::byte_offset() const {
6474 if (WasNeutered()) return Smi::FromInt(0);
6475 return Object::cast(READ_FIELD(this, kByteOffsetOffset));
6476 }
6477
6478
6479 void JSArrayBufferView::set_byte_offset(Object* value, WriteBarrierMode mode) {
6480 WRITE_FIELD(this, kByteOffsetOffset, value);
6481 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kByteOffsetOffset, value, mode);
6482 }
6483
6484
6485 Object* JSArrayBufferView::byte_length() const {
6486 if (WasNeutered()) return Smi::FromInt(0);
6487 return Object::cast(READ_FIELD(this, kByteLengthOffset));
6488 }
6489
6490
6491 void JSArrayBufferView::set_byte_length(Object* value, WriteBarrierMode mode) {
6492 WRITE_FIELD(this, kByteLengthOffset, value);
6493 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kByteLengthOffset, value, mode);
6494 }
6460 6495
6461 6496
6462 ACCESSORS(JSArrayBufferView, buffer, Object, kBufferOffset) 6497 ACCESSORS(JSArrayBufferView, buffer, Object, kBufferOffset)
6463 ACCESSORS(JSArrayBufferView, byte_offset, Object, kByteOffsetOffset) 6498 #ifdef VERIFY_HEAP
6464 ACCESSORS(JSArrayBufferView, byte_length, Object, kByteLengthOffset) 6499 ACCESSORS(JSArrayBufferView, raw_byte_offset, Object, kByteOffsetOffset)
6465 ACCESSORS(JSArrayBufferView, weak_next, Object, kWeakNextOffset) 6500 ACCESSORS(JSArrayBufferView, raw_byte_length, Object, kByteLengthOffset)
6466 ACCESSORS(JSTypedArray, length, Object, kLengthOffset) 6501 #endif
6502
6503
6504 bool JSArrayBufferView::WasNeutered() const {
6505 return !buffer()->IsSmi() && JSArrayBuffer::cast(buffer())->was_neutered();
6506 }
6507
6508
6509 Object* JSTypedArray::length() const {
6510 if (WasNeutered()) return Smi::FromInt(0);
6511 return Object::cast(READ_FIELD(this, kLengthOffset));
6512 }
6513
6514
6515 void JSTypedArray::set_length(Object* value, WriteBarrierMode mode) {
6516 WRITE_FIELD(this, kLengthOffset, value);
6517 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kLengthOffset, value, mode);
6518 }
6519
6520
6521 #ifdef VERIFY_HEAP
6522 ACCESSORS(JSTypedArray, raw_length, Object, kLengthOffset)
6523 #endif
6524
6467 6525
6468 ACCESSORS(JSRegExp, data, Object, kDataOffset) 6526 ACCESSORS(JSRegExp, data, Object, kDataOffset)
6469 6527
6470 6528
6471 JSRegExp::Type JSRegExp::TypeTag() { 6529 JSRegExp::Type JSRegExp::TypeTag() {
6472 Object* data = this->data(); 6530 Object* data = this->data();
6473 if (data->IsUndefined()) return JSRegExp::NOT_COMPILED; 6531 if (data->IsUndefined()) return JSRegExp::NOT_COMPILED;
6474 Smi* smi = Smi::cast(FixedArray::cast(data)->get(kTagIndex)); 6532 Smi* smi = Smi::cast(FixedArray::cast(data)->get(kTagIndex));
6475 return static_cast<JSRegExp::Type>(smi->value()); 6533 return static_cast<JSRegExp::Type>(smi->value());
6476 } 6534 }
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
7544 #undef READ_SHORT_FIELD 7602 #undef READ_SHORT_FIELD
7545 #undef WRITE_SHORT_FIELD 7603 #undef WRITE_SHORT_FIELD
7546 #undef READ_BYTE_FIELD 7604 #undef READ_BYTE_FIELD
7547 #undef WRITE_BYTE_FIELD 7605 #undef WRITE_BYTE_FIELD
7548 #undef NOBARRIER_READ_BYTE_FIELD 7606 #undef NOBARRIER_READ_BYTE_FIELD
7549 #undef NOBARRIER_WRITE_BYTE_FIELD 7607 #undef NOBARRIER_WRITE_BYTE_FIELD
7550 7608
7551 } } // namespace v8::internal 7609 } } // namespace v8::internal
7552 7610
7553 #endif // V8_OBJECTS_INL_H_ 7611 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « src/objects-debug.cc ('k') | src/runtime/runtime-typedarray.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698