From a54d24a1d6265d48635739633f2ca5c4591e05b1 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Tue, 15 Apr 2014 08:15:33 +0000 Subject: [PATCH] Handlify TypedArray setters. R=dslomov@chromium.org Review URL: https://codereview.chromium.org/235923013 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20749 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/objects.cc | 176 +++++++++++++++++---------------------------------------- src/objects.h | 54 ++++++------------ 2 files changed, 70 insertions(+), 160 deletions(-) diff --git a/src/objects.cc b/src/objects.cc index e765aae..256f555 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -14791,11 +14791,14 @@ size_t JSTypedArray::element_size() { } -Object* ExternalUint8ClampedArray::SetValue(uint32_t index, Object* value) { +Handle ExternalUint8ClampedArray::SetValue( + Handle array, + uint32_t index, + Handle value) { uint8_t clamped_value = 0; - if (index < static_cast(length())) { + if (index < static_cast(array->length())) { if (value->IsSmi()) { - int int_value = Smi::cast(value)->value(); + int int_value = Handle::cast(value)->value(); if (int_value < 0) { clamped_value = 0; } else if (int_value > 255) { @@ -14804,7 +14807,7 @@ Object* ExternalUint8ClampedArray::SetValue(uint32_t index, Object* value) { clamped_value = static_cast(int_value); } } else if (value->IsHeapNumber()) { - double double_value = HeapNumber::cast(value)->value(); + double double_value = Handle::cast(value)->value(); if (!(double_value > 0)) { // NaN and less than zero clamp to zero. clamped_value = 0; @@ -14820,32 +14823,25 @@ Object* ExternalUint8ClampedArray::SetValue(uint32_t index, Object* value) { // converted to a number type further up in the call chain. ASSERT(value->IsUndefined()); } - set(index, clamped_value); + array->set(index, clamped_value); } - return Smi::FromInt(clamped_value); + return handle(Smi::FromInt(clamped_value), array->GetIsolate()); } -Handle ExternalUint8ClampedArray::SetValue( - Handle array, +template +static Handle ExternalArrayIntSetter( + Isolate* isolate, + Handle receiver, uint32_t index, Handle value) { - return Handle(array->SetValue(index, *value), array->GetIsolate()); -} - - -template -static MaybeObject* ExternalArrayIntSetter(Heap* heap, - ExternalArrayClass* receiver, - uint32_t index, - Object* value) { ValueType cast_value = 0; if (index < static_cast(receiver->length())) { if (value->IsSmi()) { - int int_value = Smi::cast(value)->value(); + int int_value = Handle::cast(value)->value(); cast_value = static_cast(int_value); } else if (value->IsHeapNumber()) { - double double_value = HeapNumber::cast(value)->value(); + double double_value = Handle::cast(value)->value(); cast_value = static_cast(DoubleToInt32(double_value)); } else { // Clamp undefined to zero (default). All other types have been @@ -14854,88 +14850,47 @@ static MaybeObject* ExternalArrayIntSetter(Heap* heap, } receiver->set(index, cast_value); } - return heap->NumberFromInt32(cast_value); + return isolate->factory()->NewNumberFromInt(cast_value); } Handle ExternalInt8Array::SetValue(Handle array, uint32_t index, Handle value) { - CALL_HEAP_FUNCTION(array->GetIsolate(), - array->SetValue(index, *value), - Object); -} - - -MaybeObject* ExternalInt8Array::SetValue(uint32_t index, Object* value) { - return ExternalArrayIntSetter - (GetHeap(), this, index, value); -} - - -Handle ExternalUint8Array::SetValue( - Handle array, - uint32_t index, - Handle value) { - CALL_HEAP_FUNCTION(array->GetIsolate(), - array->SetValue(index, *value), - Object); -} - - -MaybeObject* ExternalUint8Array::SetValue(uint32_t index, - Object* value) { - return ExternalArrayIntSetter - (GetHeap(), this, index, value); -} - - -Handle ExternalInt16Array::SetValue( - Handle array, - uint32_t index, - Handle value) { - CALL_HEAP_FUNCTION(array->GetIsolate(), - array->SetValue(index, *value), - Object); + return ExternalArrayIntSetter( + array->GetIsolate(), array, index, value); } -MaybeObject* ExternalInt16Array::SetValue(uint32_t index, - Object* value) { - return ExternalArrayIntSetter - (GetHeap(), this, index, value); +Handle ExternalUint8Array::SetValue(Handle array, + uint32_t index, + Handle value) { + return ExternalArrayIntSetter( + array->GetIsolate(), array, index, value); } -Handle ExternalUint16Array::SetValue( - Handle array, - uint32_t index, - Handle value) { - CALL_HEAP_FUNCTION(array->GetIsolate(), - array->SetValue(index, *value), - Object); +Handle ExternalInt16Array::SetValue(Handle array, + uint32_t index, + Handle value) { + return ExternalArrayIntSetter( + array->GetIsolate(), array, index, value); } -MaybeObject* ExternalUint16Array::SetValue(uint32_t index, - Object* value) { - return ExternalArrayIntSetter - (GetHeap(), this, index, value); +Handle ExternalUint16Array::SetValue(Handle array, + uint32_t index, + Handle value) { + return ExternalArrayIntSetter( + array->GetIsolate(), array, index, value); } Handle ExternalInt32Array::SetValue(Handle array, - uint32_t index, - Handle value) { - CALL_HEAP_FUNCTION(array->GetIsolate(), - array->SetValue(index, *value), - Object); -} - - -MaybeObject* ExternalInt32Array::SetValue(uint32_t index, Object* value) { - return ExternalArrayIntSetter - (GetHeap(), this, index, value); + uint32_t index, + Handle value) { + return ExternalArrayIntSetter( + array->GetIsolate(), array, index, value); } @@ -14943,30 +14898,22 @@ Handle ExternalUint32Array::SetValue( Handle array, uint32_t index, Handle value) { - CALL_HEAP_FUNCTION(array->GetIsolate(), - array->SetValue(index, *value), - Object); -} - - -MaybeObject* ExternalUint32Array::SetValue(uint32_t index, Object* value) { uint32_t cast_value = 0; - Heap* heap = GetHeap(); - if (index < static_cast(length())) { + if (index < static_cast(array->length())) { if (value->IsSmi()) { - int int_value = Smi::cast(value)->value(); + int int_value = Handle::cast(value)->value(); cast_value = static_cast(int_value); } else if (value->IsHeapNumber()) { - double double_value = HeapNumber::cast(value)->value(); + double double_value = Handle::cast(value)->value(); cast_value = static_cast(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. ASSERT(value->IsUndefined()); } - set(index, cast_value); + array->set(index, cast_value); } - return heap->NumberFromUint32(cast_value); + return array->GetIsolate()->factory()->NewNumberFromUint(cast_value); } @@ -14974,30 +14921,22 @@ Handle ExternalFloat32Array::SetValue( Handle array, uint32_t index, Handle value) { - CALL_HEAP_FUNCTION(array->GetIsolate(), - array->SetValue(index, *value), - Object); -} - - -MaybeObject* ExternalFloat32Array::SetValue(uint32_t index, Object* value) { float cast_value = static_cast(OS::nan_value()); - Heap* heap = GetHeap(); - if (index < static_cast(length())) { + if (index < static_cast(array->length())) { if (value->IsSmi()) { - int int_value = Smi::cast(value)->value(); + int int_value = Handle::cast(value)->value(); cast_value = static_cast(int_value); } else if (value->IsHeapNumber()) { - double double_value = HeapNumber::cast(value)->value(); + double double_value = Handle::cast(value)->value(); cast_value = static_cast(double_value); } else { // Clamp undefined to NaN (default). All other types have been // converted to a number type further up in the call chain. ASSERT(value->IsUndefined()); } - set(index, cast_value); + array->set(index, cast_value); } - return heap->AllocateHeapNumber(cast_value); + return array->GetIsolate()->factory()->NewNumber(cast_value); } @@ -15005,29 +14944,18 @@ Handle ExternalFloat64Array::SetValue( Handle array, uint32_t index, Handle value) { - CALL_HEAP_FUNCTION(array->GetIsolate(), - array->SetValue(index, *value), - Object); -} - - -MaybeObject* ExternalFloat64Array::SetValue(uint32_t index, Object* value) { double double_value = OS::nan_value(); - Heap* heap = GetHeap(); - if (index < static_cast(length())) { - if (value->IsSmi()) { - int int_value = Smi::cast(value)->value(); - double_value = static_cast(int_value); - } else if (value->IsHeapNumber()) { - double_value = HeapNumber::cast(value)->value(); + if (index < static_cast(array->length())) { + if (value->IsNumber()) { + double_value = value->Number(); } else { // Clamp undefined to NaN (default). All other types have been // converted to a number type further up in the call chain. ASSERT(value->IsUndefined()); } - set(index, double_value); + array->set(index, double_value); } - return heap->AllocateHeapNumber(double_value); + return array->GetIsolate()->factory()->NewNumber(double_value); } diff --git a/src/objects.h b/src/objects.h index fdc6067..d04c94b 100644 --- a/src/objects.h +++ b/src/objects.h @@ -4917,10 +4917,8 @@ class ExternalUint8ClampedArray: public ExternalArray { int index); inline void set(int index, uint8_t value); - // This accessor applies the correct conversion from Smi, HeapNumber and - // undefined and clamps the converted value between 0 and 255. - Object* SetValue(uint32_t index, Object* value); - + // This accessor applies the correct conversion from Smi, HeapNumber + // and undefined and clamps the converted value between 0 and 255. static Handle SetValue(Handle array, uint32_t index, Handle value); @@ -4945,14 +4943,12 @@ class ExternalInt8Array: public ExternalArray { static inline Handle get(Handle array, int index); inline void set(int index, int8_t value); + // This accessor applies the correct conversion from Smi, HeapNumber + // and undefined. static Handle SetValue(Handle array, uint32_t index, Handle value); - // This accessor applies the correct conversion from Smi, HeapNumber - // and undefined. - MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); - // Casting. static inline ExternalInt8Array* cast(Object* obj); @@ -4973,14 +4969,12 @@ class ExternalUint8Array: public ExternalArray { static inline Handle get(Handle array, int index); inline void set(int index, uint8_t value); + // This accessor applies the correct conversion from Smi, HeapNumber + // and undefined. static Handle SetValue(Handle array, uint32_t index, Handle value); - // This accessor applies the correct conversion from Smi, HeapNumber - // and undefined. - MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); - // Casting. static inline ExternalUint8Array* cast(Object* obj); @@ -5001,14 +4995,12 @@ class ExternalInt16Array: public ExternalArray { static inline Handle get(Handle array, int index); inline void set(int index, int16_t value); + // This accessor applies the correct conversion from Smi, HeapNumber + // and undefined. static Handle SetValue(Handle array, uint32_t index, Handle value); - // This accessor applies the correct conversion from Smi, HeapNumber - // and undefined. - MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); - // Casting. static inline ExternalInt16Array* cast(Object* obj); @@ -5030,14 +5022,12 @@ class ExternalUint16Array: public ExternalArray { int index); inline void set(int index, uint16_t value); + // This accessor applies the correct conversion from Smi, HeapNumber + // and undefined. static Handle SetValue(Handle array, uint32_t index, Handle value); - // This accessor applies the correct conversion from Smi, HeapNumber - // and undefined. - MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); - // Casting. static inline ExternalUint16Array* cast(Object* obj); @@ -5058,14 +5048,12 @@ class ExternalInt32Array: public ExternalArray { static inline Handle get(Handle array, int index); inline void set(int index, int32_t value); + // This accessor applies the correct conversion from Smi, HeapNumber + // and undefined. static Handle SetValue(Handle array, uint32_t index, Handle value); - // This accessor applies the correct conversion from Smi, HeapNumber - // and undefined. - MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); - // Casting. static inline ExternalInt32Array* cast(Object* obj); @@ -5087,14 +5075,12 @@ class ExternalUint32Array: public ExternalArray { int index); inline void set(int index, uint32_t value); + // This accessor applies the correct conversion from Smi, HeapNumber + // and undefined. static Handle SetValue(Handle array, uint32_t index, Handle value); - // This accessor applies the correct conversion from Smi, HeapNumber - // and undefined. - MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); - // Casting. static inline ExternalUint32Array* cast(Object* obj); @@ -5116,14 +5102,12 @@ class ExternalFloat32Array: public ExternalArray { int index); inline void set(int index, float value); + // This accessor applies the correct conversion from Smi, HeapNumber + // and undefined. static Handle SetValue(Handle array, uint32_t index, Handle value); - // This accessor applies the correct conversion from Smi, HeapNumber - // and undefined. - MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); - // Casting. static inline ExternalFloat32Array* cast(Object* obj); @@ -5145,14 +5129,12 @@ class ExternalFloat64Array: public ExternalArray { int index); inline void set(int index, double value); + // This accessor applies the correct conversion from Smi, HeapNumber + // and undefined. static Handle SetValue(Handle array, uint32_t index, Handle value); - // This accessor applies the correct conversion from Smi, HeapNumber - // and undefined. - MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); - // Casting. static inline ExternalFloat64Array* cast(Object* obj); -- 2.7.4