| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/value-serializer.h" | 5 #include "src/value-serializer.h" |
| 6 | 6 |
| 7 #include <type_traits> | 7 #include <type_traits> |
| 8 | 8 |
| 9 #include "src/base/logging.h" | 9 #include "src/base/logging.h" |
| 10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 } | 777 } |
| 778 | 778 |
| 779 ValueDeserializer::ValueDeserializer(Isolate* isolate, | 779 ValueDeserializer::ValueDeserializer(Isolate* isolate, |
| 780 Vector<const uint8_t> data, | 780 Vector<const uint8_t> data, |
| 781 v8::ValueDeserializer::Delegate* delegate) | 781 v8::ValueDeserializer::Delegate* delegate) |
| 782 : isolate_(isolate), | 782 : isolate_(isolate), |
| 783 delegate_(delegate), | 783 delegate_(delegate), |
| 784 position_(data.start()), | 784 position_(data.start()), |
| 785 end_(data.start() + data.length()), | 785 end_(data.start() + data.length()), |
| 786 pretenure_(data.length() > kPretenureThreshold ? TENURED : NOT_TENURED), | 786 pretenure_(data.length() > kPretenureThreshold ? TENURED : NOT_TENURED), |
| 787 id_map_(Handle<SeededNumberDictionary>::cast( | 787 id_map_(Handle<FixedArray>::cast(isolate->global_handles()->Create( |
| 788 isolate->global_handles()->Create( | 788 isolate_->heap()->empty_fixed_array()))) {} |
| 789 *SeededNumberDictionary::New(isolate, 0)))) {} | |
| 790 | 789 |
| 791 ValueDeserializer::~ValueDeserializer() { | 790 ValueDeserializer::~ValueDeserializer() { |
| 792 GlobalHandles::Destroy(Handle<Object>::cast(id_map_).location()); | 791 GlobalHandles::Destroy(Handle<Object>::cast(id_map_).location()); |
| 793 | 792 |
| 794 Handle<Object> transfer_map_handle; | 793 Handle<Object> transfer_map_handle; |
| 795 if (array_buffer_transfer_map_.ToHandle(&transfer_map_handle)) { | 794 if (array_buffer_transfer_map_.ToHandle(&transfer_map_handle)) { |
| 796 GlobalHandles::Destroy(transfer_map_handle.location()); | 795 GlobalHandles::Destroy(transfer_map_handle.location()); |
| 797 } | 796 } |
| 798 } | 797 } |
| 799 | 798 |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1568 isolate_, object, key, &success, LookupIterator::OWN); | 1567 isolate_, object, key, &success, LookupIterator::OWN); |
| 1569 if (!success || | 1568 if (!success || |
| 1570 JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, NONE) | 1569 JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, NONE) |
| 1571 .is_null()) { | 1570 .is_null()) { |
| 1572 return Nothing<uint32_t>(); | 1571 return Nothing<uint32_t>(); |
| 1573 } | 1572 } |
| 1574 } | 1573 } |
| 1575 } | 1574 } |
| 1576 | 1575 |
| 1577 bool ValueDeserializer::HasObjectWithID(uint32_t id) { | 1576 bool ValueDeserializer::HasObjectWithID(uint32_t id) { |
| 1578 return id_map_->Has(isolate_, id); | 1577 return id < static_cast<unsigned>(id_map_->length()) && |
| 1578 !id_map_->get(id)->IsTheHole(isolate_); |
| 1579 } | 1579 } |
| 1580 | 1580 |
| 1581 MaybeHandle<JSReceiver> ValueDeserializer::GetObjectWithID(uint32_t id) { | 1581 MaybeHandle<JSReceiver> ValueDeserializer::GetObjectWithID(uint32_t id) { |
| 1582 int index = id_map_->FindEntry(isolate_, id); | 1582 if (id >= static_cast<unsigned>(id_map_->length())) { |
| 1583 if (index == SeededNumberDictionary::kNotFound) { | |
| 1584 return MaybeHandle<JSReceiver>(); | 1583 return MaybeHandle<JSReceiver>(); |
| 1585 } | 1584 } |
| 1586 Object* value = id_map_->ValueAt(index); | 1585 Object* value = id_map_->get(id); |
| 1586 if (value->IsTheHole(isolate_)) return MaybeHandle<JSReceiver>(); |
| 1587 DCHECK(value->IsJSReceiver()); | 1587 DCHECK(value->IsJSReceiver()); |
| 1588 return Handle<JSReceiver>(JSReceiver::cast(value), isolate_); | 1588 return Handle<JSReceiver>(JSReceiver::cast(value), isolate_); |
| 1589 } | 1589 } |
| 1590 | 1590 |
| 1591 void ValueDeserializer::AddObjectWithID(uint32_t id, | 1591 void ValueDeserializer::AddObjectWithID(uint32_t id, |
| 1592 Handle<JSReceiver> object) { | 1592 Handle<JSReceiver> object) { |
| 1593 DCHECK(!HasObjectWithID(id)); | 1593 DCHECK(!HasObjectWithID(id)); |
| 1594 const bool used_as_prototype = false; | 1594 Handle<FixedArray> new_array = FixedArray::SetAndGrow(id_map_, id, object); |
| 1595 Handle<SeededNumberDictionary> new_dictionary = | |
| 1596 SeededNumberDictionary::AtNumberPut(id_map_, id, object, | |
| 1597 used_as_prototype); | |
| 1598 | 1595 |
| 1599 // If the dictionary was reallocated, update the global handle. | 1596 // If the dictionary was reallocated, update the global handle. |
| 1600 if (!new_dictionary.is_identical_to(id_map_)) { | 1597 if (!new_array.is_identical_to(id_map_)) { |
| 1601 GlobalHandles::Destroy(Handle<Object>::cast(id_map_).location()); | 1598 GlobalHandles::Destroy(Handle<Object>::cast(id_map_).location()); |
| 1602 id_map_ = Handle<SeededNumberDictionary>::cast( | 1599 id_map_ = Handle<FixedArray>::cast( |
| 1603 isolate_->global_handles()->Create(*new_dictionary)); | 1600 isolate_->global_handles()->Create(*new_array)); |
| 1604 } | 1601 } |
| 1605 } | 1602 } |
| 1606 | 1603 |
| 1607 static Maybe<bool> SetPropertiesFromKeyValuePairs(Isolate* isolate, | 1604 static Maybe<bool> SetPropertiesFromKeyValuePairs(Isolate* isolate, |
| 1608 Handle<JSObject> object, | 1605 Handle<JSObject> object, |
| 1609 Handle<Object>* data, | 1606 Handle<Object>* data, |
| 1610 uint32_t num_properties) { | 1607 uint32_t num_properties) { |
| 1611 for (unsigned i = 0; i < 2 * num_properties; i += 2) { | 1608 for (unsigned i = 0; i < 2 * num_properties; i += 2) { |
| 1612 Handle<Object> key = data[i]; | 1609 Handle<Object> key = data[i]; |
| 1613 Handle<Object> value = data[i + 1]; | 1610 Handle<Object> value = data[i + 1]; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 if (stack.size() != 1) { | 1709 if (stack.size() != 1) { |
| 1713 isolate_->Throw(*isolate_->factory()->NewError( | 1710 isolate_->Throw(*isolate_->factory()->NewError( |
| 1714 MessageTemplate::kDataCloneDeserializationError)); | 1711 MessageTemplate::kDataCloneDeserializationError)); |
| 1715 return MaybeHandle<Object>(); | 1712 return MaybeHandle<Object>(); |
| 1716 } | 1713 } |
| 1717 return scope.CloseAndEscape(stack[0]); | 1714 return scope.CloseAndEscape(stack[0]); |
| 1718 } | 1715 } |
| 1719 | 1716 |
| 1720 } // namespace internal | 1717 } // namespace internal |
| 1721 } // namespace v8 | 1718 } // namespace v8 |
| OLD | NEW |