Remove handles from ElementsAccessor::Set and friends

BUG=v8:4137
LOG=n

Review URL: https://codereview.chromium.org/1196543003

Cr-Commit-Position: refs/heads/master@{#29139}
This commit is contained in:
verwaest 2015-06-19 02:25:16 -07:00 committed by Commit bot
parent e73328f9b1
commit 0f1522f4c2
6 changed files with 66 additions and 98 deletions

View File

@ -613,15 +613,14 @@ class ElementsAccessorBase : public ElementsAccessor {
}
}
virtual void Set(Handle<FixedArrayBase> backing_store, uint32_t key,
Handle<Object> value) final {
virtual void Set(FixedArrayBase* backing_store, uint32_t key,
Object* value) final {
ElementsAccessorSubclass::SetImpl(backing_store, key, value);
}
static void SetImpl(Handle<FixedArrayBase> backing_store, uint32_t key,
Handle<Object> value) {
BackingStore::SetValue(Handle<BackingStore>::cast(backing_store), key,
value);
static void SetImpl(FixedArrayBase* backing_store, uint32_t key,
Object* value) {
BackingStore::cast(backing_store)->SetValue(key, value);
}
virtual MaybeHandle<AccessorPair> GetAccessorPair(
@ -1443,13 +1442,11 @@ class DictionaryElementsAccessor
return isolate->factory()->the_hole_value();
}
static void SetImpl(Handle<FixedArrayBase> store, uint32_t key,
Handle<Object> value) {
Handle<SeededNumberDictionary> backing_store =
Handle<SeededNumberDictionary>::cast(store);
static void SetImpl(FixedArrayBase* store, uint32_t key, Object* value) {
SeededNumberDictionary* backing_store = SeededNumberDictionary::cast(store);
int entry = backing_store->FindEntry(key);
DCHECK_NE(SeededNumberDictionary::kNotFound, entry);
backing_store->ValueAtPut(entry, *value);
backing_store->ValueAtPut(entry, value);
}
static MaybeHandle<AccessorPair> GetAccessorPairImpl(
@ -1540,17 +1537,16 @@ class SloppyArgumentsElementsAccessor : public ElementsAccessorBase<
}
}
static void SetImpl(Handle<FixedArrayBase> store, uint32_t key,
Handle<Object> value) {
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(store);
Object* probe = GetParameterMapArg(*parameter_map, key);
static void SetImpl(FixedArrayBase* store, uint32_t key, Object* value) {
FixedArray* parameter_map = FixedArray::cast(store);
Object* probe = GetParameterMapArg(parameter_map, key);
if (!probe->IsTheHole()) {
Context* context = Context::cast(parameter_map->get(0));
int context_index = Smi::cast(probe)->value();
DCHECK(!context->get(context_index)->IsTheHole());
context->set(context_index, *value);
context->set(context_index, value);
} else {
Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
ElementsAccessor::ForArray(arguments)->Set(arguments, key, value);
}
}

View File

@ -175,8 +175,8 @@ class ElementsAccessor {
uint32_t index) = 0;
virtual bool HasIndex(FixedArrayBase* backing_store, uint32_t key) = 0;
virtual void Set(Handle<FixedArrayBase> backing_store, uint32_t key,
Handle<Object> value) = 0;
virtual void Set(FixedArrayBase* backing_store, uint32_t key,
Object* value) = 0;
private:
static ElementsAccessor** elements_accessors_;

View File

@ -420,15 +420,14 @@ void LookupIterator::WriteDataValue(Handle<Object> value) {
Handle<JSObject> holder = GetHolder<JSObject>();
if (IsElement()) {
ElementsAccessor* accessor = holder->GetElementsAccessor();
accessor->Set(handle(holder->elements()), index_, value);
accessor->Set(holder->elements(), index_, *value);
} else if (holder->IsGlobalObject()) {
Handle<GlobalDictionary> property_dictionary =
handle(holder->global_dictionary());
PropertyCell::UpdateCell(property_dictionary, dictionary_entry(), value,
property_details_);
} else if (holder_map_->is_dictionary_map()) {
Handle<NameDictionary> property_dictionary =
handle(holder->property_dictionary());
NameDictionary* property_dictionary = holder->property_dictionary();
property_dictionary->ValueAtPut(dictionary_entry(), *value);
} else if (property_details_.type() == v8::internal::DATA) {
holder->WriteToField(descriptor_number(), *value);

View File

@ -4002,21 +4002,20 @@ Handle<Object> FixedTypedArray<Traits>::get(
template <class Traits>
void FixedTypedArray<Traits>::SetValue(Handle<FixedTypedArray<Traits> > array,
uint32_t index, Handle<Object> value) {
void FixedTypedArray<Traits>::SetValue(uint32_t index, Object* value) {
ElementType cast_value = Traits::defaultValue();
if (value->IsSmi()) {
int int_value = Handle<Smi>::cast(value)->value();
int int_value = Smi::cast(value)->value();
cast_value = from_int(int_value);
} else if (value->IsHeapNumber()) {
double double_value = Handle<HeapNumber>::cast(value)->value();
double double_value = HeapNumber::cast(value)->value();
cast_value = from_double(double_value);
} else {
// Clamp undefined to the default value. All other types have been
// converted to a number type further up in the call chain.
DCHECK(value->IsUndefined());
}
array->set(index, cast_value);
set(index, cast_value);
}

View File

@ -14715,24 +14715,18 @@ size_t JSTypedArray::element_size() {
}
void FixedArray::SetValue(Handle<FixedArray> array, uint32_t index,
Handle<Object> value) {
array->set(index, *value);
void FixedArray::SetValue(uint32_t index, Object* value) { set(index, value); }
void FixedDoubleArray::SetValue(uint32_t index, Object* value) {
set(index, value->Number());
}
void FixedDoubleArray::SetValue(Handle<FixedDoubleArray> array, uint32_t index,
Handle<Object> value) {
array->set(index, value->Number());
}
void ExternalUint8ClampedArray::SetValue(
Handle<ExternalUint8ClampedArray> array, uint32_t index,
Handle<Object> value) {
void ExternalUint8ClampedArray::SetValue(uint32_t index, Object* value) {
uint8_t clamped_value = 0;
if (value->IsSmi()) {
int int_value = Handle<Smi>::cast(value)->value();
int int_value = Smi::cast(value)->value();
if (int_value < 0) {
clamped_value = 0;
} else if (int_value > 255) {
@ -14741,7 +14735,7 @@ void ExternalUint8ClampedArray::SetValue(
clamped_value = static_cast<uint8_t>(int_value);
}
} else if (value->IsHeapNumber()) {
double double_value = Handle<HeapNumber>::cast(value)->value();
double double_value = HeapNumber::cast(value)->value();
if (!(double_value > 0)) {
// NaN and less than zero clamp to zero.
clamped_value = 0;
@ -14757,19 +14751,19 @@ void ExternalUint8ClampedArray::SetValue(
// converted to a number type further up in the call chain.
DCHECK(value->IsUndefined());
}
array->set(index, clamped_value);
set(index, clamped_value);
}
template <typename ExternalArrayClass, typename ValueType>
static void ExternalArrayIntSetter(Handle<ExternalArrayClass> receiver,
uint32_t index, Handle<Object> value) {
static void ExternalArrayIntSetter(ExternalArrayClass* receiver, uint32_t index,
Object* value) {
ValueType cast_value = 0;
if (value->IsSmi()) {
int int_value = Handle<Smi>::cast(value)->value();
int int_value = Smi::cast(value)->value();
cast_value = static_cast<ValueType>(int_value);
} else if (value->IsHeapNumber()) {
double double_value = Handle<HeapNumber>::cast(value)->value();
double double_value = HeapNumber::cast(value)->value();
cast_value = static_cast<ValueType>(DoubleToInt32(double_value));
} else {
// Clamp undefined to zero (default). All other types have been
@ -14780,74 +14774,66 @@ static void ExternalArrayIntSetter(Handle<ExternalArrayClass> receiver,
}
void ExternalInt8Array::SetValue(Handle<ExternalInt8Array> array,
uint32_t index, Handle<Object> value) {
ExternalArrayIntSetter<ExternalInt8Array, int8_t>(array, index, value);
void ExternalInt8Array::SetValue(uint32_t index, Object* value) {
ExternalArrayIntSetter<ExternalInt8Array, int8_t>(this, index, value);
}
void ExternalUint8Array::SetValue(Handle<ExternalUint8Array> array,
uint32_t index, Handle<Object> value) {
ExternalArrayIntSetter<ExternalUint8Array, uint8_t>(array, index, value);
void ExternalUint8Array::SetValue(uint32_t index, Object* value) {
ExternalArrayIntSetter<ExternalUint8Array, uint8_t>(this, index, value);
}
void ExternalInt16Array::SetValue(Handle<ExternalInt16Array> array,
uint32_t index, Handle<Object> value) {
ExternalArrayIntSetter<ExternalInt16Array, int16_t>(array, index, value);
void ExternalInt16Array::SetValue(uint32_t index, Object* value) {
ExternalArrayIntSetter<ExternalInt16Array, int16_t>(this, index, value);
}
void ExternalUint16Array::SetValue(Handle<ExternalUint16Array> array,
uint32_t index, Handle<Object> value) {
ExternalArrayIntSetter<ExternalUint16Array, uint16_t>(array, index, value);
void ExternalUint16Array::SetValue(uint32_t index, Object* value) {
ExternalArrayIntSetter<ExternalUint16Array, uint16_t>(this, index, value);
}
void ExternalInt32Array::SetValue(Handle<ExternalInt32Array> array,
uint32_t index, Handle<Object> value) {
ExternalArrayIntSetter<ExternalInt32Array, int32_t>(array, index, value);
void ExternalInt32Array::SetValue(uint32_t index, Object* value) {
ExternalArrayIntSetter<ExternalInt32Array, int32_t>(this, index, value);
}
void ExternalUint32Array::SetValue(Handle<ExternalUint32Array> array,
uint32_t index, Handle<Object> value) {
void ExternalUint32Array::SetValue(uint32_t index, Object* value) {
uint32_t cast_value = 0;
if (value->IsSmi()) {
int int_value = Handle<Smi>::cast(value)->value();
int int_value = Smi::cast(value)->value();
cast_value = static_cast<uint32_t>(int_value);
} else if (value->IsHeapNumber()) {
double double_value = Handle<HeapNumber>::cast(value)->value();
double double_value = HeapNumber::cast(value)->value();
cast_value = static_cast<uint32_t>(DoubleToUint32(double_value));
} else {
// Clamp undefined to zero (default). All other types have been
// converted to a number type further up in the call chain.
DCHECK(value->IsUndefined());
}
array->set(index, cast_value);
set(index, cast_value);
}
void ExternalFloat32Array::SetValue(Handle<ExternalFloat32Array> array,
uint32_t index, Handle<Object> value) {
void ExternalFloat32Array::SetValue(uint32_t index, Object* value) {
float cast_value = std::numeric_limits<float>::quiet_NaN();
if (value->IsSmi()) {
int int_value = Handle<Smi>::cast(value)->value();
int int_value = Smi::cast(value)->value();
cast_value = static_cast<float>(int_value);
} else if (value->IsHeapNumber()) {
double double_value = Handle<HeapNumber>::cast(value)->value();
double double_value = HeapNumber::cast(value)->value();
cast_value = static_cast<float>(double_value);
} else {
// Clamp undefined to NaN (default). All other types have been
// converted to a number type further up in the call chain.
DCHECK(value->IsUndefined());
}
array->set(index, cast_value);
set(index, cast_value);
}
void ExternalFloat64Array::SetValue(Handle<ExternalFloat64Array> array,
uint32_t index, Handle<Object> value) {
void ExternalFloat64Array::SetValue(uint32_t index, Object* value) {
double double_value = std::numeric_limits<double>::quiet_NaN();
if (value->IsNumber()) {
double_value = value->Number();
@ -14856,7 +14842,7 @@ void ExternalFloat64Array::SetValue(Handle<ExternalFloat64Array> array,
// converted to a number type further up in the call chain.
DCHECK(value->IsUndefined());
}
array->set(index, double_value);
set(index, double_value);
}

View File

@ -2439,8 +2439,7 @@ class FixedArray: public FixedArrayBase {
public:
// Setter and getter for elements.
inline Object* get(int index) const;
static void SetValue(Handle<FixedArray> array, uint32_t index,
Handle<Object> value);
void SetValue(uint32_t index, Object* value);
static inline Handle<Object> get(Handle<FixedArray> array, int index);
// Setter that uses write barrier.
inline void set(int index, Object* value);
@ -2563,8 +2562,7 @@ class FixedDoubleArray: public FixedArrayBase {
inline uint64_t get_representation(int index);
static inline Handle<Object> get(Handle<FixedDoubleArray> array, int index);
// This accessor has to get a Number as |value|.
static void SetValue(Handle<FixedDoubleArray> array, uint32_t index,
Handle<Object> value);
void SetValue(uint32_t index, Object* value);
inline void set(int index, double value);
inline void set_the_hole(int index);
@ -4399,8 +4397,7 @@ class ExternalUint8ClampedArray: public ExternalArray {
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined and clamps the converted value between 0 and 255.
static void SetValue(Handle<ExternalUint8ClampedArray> array, uint32_t index,
Handle<Object> value);
void SetValue(uint32_t index, Object* value);
DECLARE_CAST(ExternalUint8ClampedArray)
@ -4422,8 +4419,7 @@ class ExternalInt8Array: public ExternalArray {
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static void SetValue(Handle<ExternalInt8Array> array, uint32_t index,
Handle<Object> value);
void SetValue(uint32_t index, Object* value);
DECLARE_CAST(ExternalInt8Array)
@ -4445,8 +4441,7 @@ class ExternalUint8Array: public ExternalArray {
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static void SetValue(Handle<ExternalUint8Array> array, uint32_t index,
Handle<Object> value);
void SetValue(uint32_t index, Object* value);
DECLARE_CAST(ExternalUint8Array)
@ -4468,8 +4463,7 @@ class ExternalInt16Array: public ExternalArray {
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static void SetValue(Handle<ExternalInt16Array> array, uint32_t index,
Handle<Object> value);
void SetValue(uint32_t index, Object* value);
DECLARE_CAST(ExternalInt16Array)
@ -4492,8 +4486,7 @@ class ExternalUint16Array: public ExternalArray {
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static void SetValue(Handle<ExternalUint16Array> array, uint32_t index,
Handle<Object> value);
void SetValue(uint32_t index, Object* value);
DECLARE_CAST(ExternalUint16Array)
@ -4515,8 +4508,7 @@ class ExternalInt32Array: public ExternalArray {
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static void SetValue(Handle<ExternalInt32Array> array, uint32_t index,
Handle<Object> value);
void SetValue(uint32_t index, Object* value);
DECLARE_CAST(ExternalInt32Array)
@ -4539,8 +4531,7 @@ class ExternalUint32Array: public ExternalArray {
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static void SetValue(Handle<ExternalUint32Array> array, uint32_t index,
Handle<Object> value);
void SetValue(uint32_t index, Object* value);
DECLARE_CAST(ExternalUint32Array)
@ -4563,8 +4554,7 @@ class ExternalFloat32Array: public ExternalArray {
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static void SetValue(Handle<ExternalFloat32Array> array, uint32_t index,
Handle<Object> value);
void SetValue(uint32_t index, Object* value);
DECLARE_CAST(ExternalFloat32Array)
@ -4587,8 +4577,7 @@ class ExternalFloat64Array: public ExternalArray {
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static void SetValue(Handle<ExternalFloat64Array> array, uint32_t index,
Handle<Object> value);
void SetValue(uint32_t index, Object* value);
DECLARE_CAST(ExternalFloat64Array)
@ -4656,8 +4645,7 @@ class FixedTypedArray: public FixedTypedArrayBase {
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static void SetValue(Handle<FixedTypedArray<Traits> > array, uint32_t index,
Handle<Object> value);
void SetValue(uint32_t index, Object* value);
DECLARE_PRINTER(FixedTypedArray)
DECLARE_VERIFIER(FixedTypedArray)