Commit a54d24a1 authored by yangguo@chromium.org's avatar yangguo@chromium.org

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
parent cf7c8181
......@@ -14791,11 +14791,14 @@ size_t JSTypedArray::element_size() {
}
Object* ExternalUint8ClampedArray::SetValue(uint32_t index, Object* value) {
Handle<Object> ExternalUint8ClampedArray::SetValue(
Handle<ExternalUint8ClampedArray> array,
uint32_t index,
Handle<Object> value) {
uint8_t clamped_value = 0;
if (index < static_cast<uint32_t>(length())) {
if (index < static_cast<uint32_t>(array->length())) {
if (value->IsSmi()) {
int int_value = Smi::cast(value)->value();
int int_value = Handle<Smi>::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<uint8_t>(int_value);
}
} else if (value->IsHeapNumber()) {
double double_value = HeapNumber::cast(value)->value();
double double_value = Handle<HeapNumber>::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<Object> ExternalUint8ClampedArray::SetValue(
Handle<ExternalUint8ClampedArray> array,
template<typename ExternalArrayClass, typename ValueType>
static Handle<Object> ExternalArrayIntSetter(
Isolate* isolate,
Handle<ExternalArrayClass> receiver,
uint32_t index,
Handle<Object> value) {
return Handle<Object>(array->SetValue(index, *value), array->GetIsolate());
}
template<typename ExternalArrayClass, typename ValueType>
static MaybeObject* ExternalArrayIntSetter(Heap* heap,
ExternalArrayClass* receiver,
uint32_t index,
Object* value) {
ValueType cast_value = 0;
if (index < static_cast<uint32_t>(receiver->length())) {
if (value->IsSmi()) {
int int_value = Smi::cast(value)->value();
int int_value = Handle<Smi>::cast(value)->value();
cast_value = static_cast<ValueType>(int_value);
} else if (value->IsHeapNumber()) {
double double_value = HeapNumber::cast(value)->value();
double double_value = Handle<HeapNumber>::cast(value)->value();
cast_value = static_cast<ValueType>(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<Object> ExternalInt8Array::SetValue(Handle<ExternalInt8Array> array,
uint32_t index,
Handle<Object> value) {
CALL_HEAP_FUNCTION(array->GetIsolate(),
array->SetValue(index, *value),
Object);
}
MaybeObject* ExternalInt8Array::SetValue(uint32_t index, Object* value) {
return ExternalArrayIntSetter<ExternalInt8Array, int8_t>
(GetHeap(), this, index, value);
}
Handle<Object> ExternalUint8Array::SetValue(
Handle<ExternalUint8Array> array,
uint32_t index,
Handle<Object> value) {
CALL_HEAP_FUNCTION(array->GetIsolate(),
array->SetValue(index, *value),
Object);
}
MaybeObject* ExternalUint8Array::SetValue(uint32_t index,
Object* value) {
return ExternalArrayIntSetter<ExternalUint8Array, uint8_t>
(GetHeap(), this, index, value);
}
Handle<Object> ExternalInt16Array::SetValue(
Handle<ExternalInt16Array> array,
uint32_t index,
Handle<Object> value) {
CALL_HEAP_FUNCTION(array->GetIsolate(),
array->SetValue(index, *value),
Object);
return ExternalArrayIntSetter<ExternalInt8Array, int8_t>(
array->GetIsolate(), array, index, value);
}
MaybeObject* ExternalInt16Array::SetValue(uint32_t index,
Object* value) {
return ExternalArrayIntSetter<ExternalInt16Array, int16_t>
(GetHeap(), this, index, value);
Handle<Object> ExternalUint8Array::SetValue(Handle<ExternalUint8Array> array,
uint32_t index,
Handle<Object> value) {
return ExternalArrayIntSetter<ExternalUint8Array, uint8_t>(
array->GetIsolate(), array, index, value);
}
Handle<Object> ExternalUint16Array::SetValue(
Handle<ExternalUint16Array> array,
uint32_t index,
Handle<Object> value) {
CALL_HEAP_FUNCTION(array->GetIsolate(),
array->SetValue(index, *value),
Object);
Handle<Object> ExternalInt16Array::SetValue(Handle<ExternalInt16Array> array,
uint32_t index,
Handle<Object> value) {
return ExternalArrayIntSetter<ExternalInt16Array, int16_t>(
array->GetIsolate(), array, index, value);
}
MaybeObject* ExternalUint16Array::SetValue(uint32_t index,
Object* value) {
return ExternalArrayIntSetter<ExternalUint16Array, uint16_t>
(GetHeap(), this, index, value);
Handle<Object> ExternalUint16Array::SetValue(Handle<ExternalUint16Array> array,
uint32_t index,
Handle<Object> value) {
return ExternalArrayIntSetter<ExternalUint16Array, uint16_t>(
array->GetIsolate(), array, index, value);
}
Handle<Object> ExternalInt32Array::SetValue(Handle<ExternalInt32Array> array,
uint32_t index,
Handle<Object> value) {
CALL_HEAP_FUNCTION(array->GetIsolate(),
array->SetValue(index, *value),
Object);
}
MaybeObject* ExternalInt32Array::SetValue(uint32_t index, Object* value) {
return ExternalArrayIntSetter<ExternalInt32Array, int32_t>
(GetHeap(), this, index, value);
uint32_t index,
Handle<Object> value) {
return ExternalArrayIntSetter<ExternalInt32Array, int32_t>(
array->GetIsolate(), array, index, value);
}
......@@ -14943,30 +14898,22 @@ Handle<Object> ExternalUint32Array::SetValue(
Handle<ExternalUint32Array> array,
uint32_t index,
Handle<Object> 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<uint32_t>(length())) {
if (index < static_cast<uint32_t>(array->length())) {
if (value->IsSmi()) {
int int_value = Smi::cast(value)->value();
int int_value = Handle<Smi>::cast(value)->value();
cast_value = static_cast<uint32_t>(int_value);
} else if (value->IsHeapNumber()) {
double double_value = HeapNumber::cast(value)->value();
double double_value = Handle<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.
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<Object> ExternalFloat32Array::SetValue(
Handle<ExternalFloat32Array> array,
uint32_t index,
Handle<Object> value) {
CALL_HEAP_FUNCTION(array->GetIsolate(),
array->SetValue(index, *value),
Object);
}
MaybeObject* ExternalFloat32Array::SetValue(uint32_t index, Object* value) {
float cast_value = static_cast<float>(OS::nan_value());
Heap* heap = GetHeap();
if (index < static_cast<uint32_t>(length())) {
if (index < static_cast<uint32_t>(array->length())) {
if (value->IsSmi()) {
int int_value = Smi::cast(value)->value();
int int_value = Handle<Smi>::cast(value)->value();
cast_value = static_cast<float>(int_value);
} else if (value->IsHeapNumber()) {
double double_value = HeapNumber::cast(value)->value();
double double_value = Handle<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.
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<Object> ExternalFloat64Array::SetValue(
Handle<ExternalFloat64Array> array,
uint32_t index,
Handle<Object> 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<uint32_t>(length())) {
if (value->IsSmi()) {
int int_value = Smi::cast(value)->value();
double_value = static_cast<double>(int_value);
} else if (value->IsHeapNumber()) {
double_value = HeapNumber::cast(value)->value();
if (index < static_cast<uint32_t>(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);
}
......
......@@ -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<Object> SetValue(Handle<ExternalUint8ClampedArray> array,
uint32_t index,
Handle<Object> value);
......@@ -4945,14 +4943,12 @@ class ExternalInt8Array: public ExternalArray {
static inline Handle<Object> get(Handle<ExternalInt8Array> array, int index);
inline void set(int index, int8_t value);
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static Handle<Object> SetValue(Handle<ExternalInt8Array> array,
uint32_t index,
Handle<Object> 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<Object> get(Handle<ExternalUint8Array> array, int index);
inline void set(int index, uint8_t value);
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static Handle<Object> SetValue(Handle<ExternalUint8Array> array,
uint32_t index,
Handle<Object> 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<Object> get(Handle<ExternalInt16Array> array, int index);
inline void set(int index, int16_t value);
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static Handle<Object> SetValue(Handle<ExternalInt16Array> array,
uint32_t index,
Handle<Object> 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<Object> SetValue(Handle<ExternalUint16Array> array,
uint32_t index,
Handle<Object> 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<Object> get(Handle<ExternalInt32Array> array, int index);
inline void set(int index, int32_t value);
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
static Handle<Object> SetValue(Handle<ExternalInt32Array> array,
uint32_t index,
Handle<Object> 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<Object> SetValue(Handle<ExternalUint32Array> array,
uint32_t index,
Handle<Object> 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<Object> SetValue(Handle<ExternalFloat32Array> array,
uint32_t index,
Handle<Object> 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<Object> SetValue(Handle<ExternalFloat64Array> array,
uint32_t index,
Handle<Object> 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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment