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

Unified Diff: src/objects-inl.h

Issue 7527001: Encapsulate element handling into a class keyed on ElementsKind (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: merge with tot Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 6870ce06dd53c00f224a6be9c582aee55b1e61fb..3fafcb51db33b5053408797118dd5518401726d2 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -35,6 +35,7 @@
#ifndef V8_OBJECTS_INL_H_
#define V8_OBJECTS_INL_H_
+#include "elements.h"
#include "objects.h"
#include "contexts.h"
#include "conversions-inl.h"
@@ -1635,7 +1636,7 @@ inline double FixedDoubleArray::canonical_not_the_hole_nan_as_double() {
}
-double FixedDoubleArray::get(int index) {
+double FixedDoubleArray::get_scalar(int index) {
ASSERT(map() != HEAP->fixed_cow_array_map() &&
map() != HEAP->fixed_array_map());
ASSERT(index >= 0 && index < this->length());
@@ -1645,6 +1646,15 @@ double FixedDoubleArray::get(int index) {
}
+MaybeObject* FixedDoubleArray::get(int index) {
+ if (is_the_hole(index)) {
+ return GetHeap()->the_hole_value();
+ } else {
+ return GetHeap()->NumberFromDouble(get_scalar(index));
+ }
+}
+
+
void FixedDoubleArray::set(int index, double value) {
ASSERT(map() != HEAP->fixed_cow_array_map() &&
map() != HEAP->fixed_array_map());
@@ -2369,13 +2379,18 @@ uint8_t* ExternalPixelArray::external_pixel_pointer() {
}
-uint8_t ExternalPixelArray::get(int index) {
+uint8_t ExternalPixelArray::get_scalar(int index) {
ASSERT((index >= 0) && (index < this->length()));
uint8_t* ptr = external_pixel_pointer();
return ptr[index];
}
+MaybeObject* ExternalPixelArray::get(int index) {
+ return Smi::FromInt(static_cast<int>(get_scalar(index)));
+}
+
+
void ExternalPixelArray::set(int index, uint8_t value) {
ASSERT((index >= 0) && (index < this->length()));
uint8_t* ptr = external_pixel_pointer();
@@ -2395,13 +2410,18 @@ void ExternalArray::set_external_pointer(void* value, WriteBarrierMode mode) {
}
-int8_t ExternalByteArray::get(int index) {
+int8_t ExternalByteArray::get_scalar(int index) {
ASSERT((index >= 0) && (index < this->length()));
int8_t* ptr = static_cast<int8_t*>(external_pointer());
return ptr[index];
}
+MaybeObject* ExternalByteArray::get(int index) {
+ return Smi::FromInt(static_cast<int>(get_scalar(index)));
+}
+
+
void ExternalByteArray::set(int index, int8_t value) {
ASSERT((index >= 0) && (index < this->length()));
int8_t* ptr = static_cast<int8_t*>(external_pointer());
@@ -2409,13 +2429,18 @@ void ExternalByteArray::set(int index, int8_t value) {
}
-uint8_t ExternalUnsignedByteArray::get(int index) {
+uint8_t ExternalUnsignedByteArray::get_scalar(int index) {
ASSERT((index >= 0) && (index < this->length()));
uint8_t* ptr = static_cast<uint8_t*>(external_pointer());
return ptr[index];
}
+MaybeObject* ExternalUnsignedByteArray::get(int index) {
+ return Smi::FromInt(static_cast<int>(get_scalar(index)));
+}
+
+
void ExternalUnsignedByteArray::set(int index, uint8_t value) {
ASSERT((index >= 0) && (index < this->length()));
uint8_t* ptr = static_cast<uint8_t*>(external_pointer());
@@ -2423,13 +2448,18 @@ void ExternalUnsignedByteArray::set(int index, uint8_t value) {
}
-int16_t ExternalShortArray::get(int index) {
+int16_t ExternalShortArray::get_scalar(int index) {
ASSERT((index >= 0) && (index < this->length()));
int16_t* ptr = static_cast<int16_t*>(external_pointer());
return ptr[index];
}
+MaybeObject* ExternalShortArray::get(int index) {
+ return Smi::FromInt(static_cast<int>(get_scalar(index)));
+}
+
+
void ExternalShortArray::set(int index, int16_t value) {
ASSERT((index >= 0) && (index < this->length()));
int16_t* ptr = static_cast<int16_t*>(external_pointer());
@@ -2437,13 +2467,18 @@ void ExternalShortArray::set(int index, int16_t value) {
}
-uint16_t ExternalUnsignedShortArray::get(int index) {
+uint16_t ExternalUnsignedShortArray::get_scalar(int index) {
ASSERT((index >= 0) && (index < this->length()));
uint16_t* ptr = static_cast<uint16_t*>(external_pointer());
return ptr[index];
}
+MaybeObject* ExternalUnsignedShortArray::get(int index) {
+ return Smi::FromInt(static_cast<int>(get_scalar(index)));
+}
+
+
void ExternalUnsignedShortArray::set(int index, uint16_t value) {
ASSERT((index >= 0) && (index < this->length()));
uint16_t* ptr = static_cast<uint16_t*>(external_pointer());
@@ -2451,13 +2486,18 @@ void ExternalUnsignedShortArray::set(int index, uint16_t value) {
}
-int32_t ExternalIntArray::get(int index) {
+int32_t ExternalIntArray::get_scalar(int index) {
ASSERT((index >= 0) && (index < this->length()));
int32_t* ptr = static_cast<int32_t*>(external_pointer());
return ptr[index];
}
+MaybeObject* ExternalIntArray::get(int index) {
+ return GetHeap()->NumberFromInt32(get_scalar(index));
+}
+
+
void ExternalIntArray::set(int index, int32_t value) {
ASSERT((index >= 0) && (index < this->length()));
int32_t* ptr = static_cast<int32_t*>(external_pointer());
@@ -2465,13 +2505,18 @@ void ExternalIntArray::set(int index, int32_t value) {
}
-uint32_t ExternalUnsignedIntArray::get(int index) {
+uint32_t ExternalUnsignedIntArray::get_scalar(int index) {
ASSERT((index >= 0) && (index < this->length()));
uint32_t* ptr = static_cast<uint32_t*>(external_pointer());
return ptr[index];
}
+MaybeObject* ExternalUnsignedIntArray::get(int index) {
+ return GetHeap()->NumberFromUint32(get_scalar(index));
+}
+
+
void ExternalUnsignedIntArray::set(int index, uint32_t value) {
ASSERT((index >= 0) && (index < this->length()));
uint32_t* ptr = static_cast<uint32_t*>(external_pointer());
@@ -2479,13 +2524,18 @@ void ExternalUnsignedIntArray::set(int index, uint32_t value) {
}
-float ExternalFloatArray::get(int index) {
+float ExternalFloatArray::get_scalar(int index) {
ASSERT((index >= 0) && (index < this->length()));
float* ptr = static_cast<float*>(external_pointer());
return ptr[index];
}
+MaybeObject* ExternalFloatArray::get(int index) {
+ return GetHeap()->NumberFromDouble(get_scalar(index));
+}
+
+
void ExternalFloatArray::set(int index, float value) {
ASSERT((index >= 0) && (index < this->length()));
float* ptr = static_cast<float*>(external_pointer());
@@ -2493,13 +2543,18 @@ void ExternalFloatArray::set(int index, float value) {
}
-double ExternalDoubleArray::get(int index) {
+double ExternalDoubleArray::get_scalar(int index) {
ASSERT((index >= 0) && (index < this->length()));
double* ptr = static_cast<double*>(external_pointer());
return ptr[index];
}
+MaybeObject* ExternalDoubleArray::get(int index) {
+ return GetHeap()->NumberFromDouble(get_scalar(index));
+}
+
+
void ExternalDoubleArray::set(int index, double value) {
ASSERT((index >= 0) && (index < this->length()));
double* ptr = static_cast<double*>(external_pointer());
@@ -3981,6 +4036,11 @@ JSObject::ElementsKind JSObject::GetElementsKind() {
}
+ElementsAccessor* JSObject::GetElementsAccessor() {
+ return ElementsAccessor::ForKind(GetElementsKind());
+}
+
+
bool JSObject::HasFastElements() {
return GetElementsKind() == FAST_ELEMENTS;
}
« src/objects.cc ('K') | « src/objects-debug.cc ('k') | src/objects-printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698