Commit df4ee493 authored by ishell@chromium.org's avatar ishell@chromium.org

Further ElementsAccessor handlification (Get(), AddElementsToFixedArray() and HasElement()).

R=verwaest@chromium.org, yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20581 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e93599c5
This diff is collapsed.
......@@ -253,12 +253,6 @@ class ElementsAccessor {
// TODO(ishell): Non-handlified versions, used only by accessors'
// implementations. To be removed once elements.cc is handlified.
MUST_USE_RESULT virtual MaybeObject* Get(
Object* receiver,
JSObject* holder,
uint32_t key,
FixedArrayBase* backing_store) = 0;
MUST_USE_RESULT virtual PropertyAttributes GetAttributes(
Object* receiver,
JSObject* holder,
......@@ -278,7 +272,7 @@ class ElementsAccessor {
DISALLOW_COPY_AND_ASSIGN(ElementsAccessor);
};
void CheckArrayAbuse(JSObject* obj, const char* op, uint32_t key,
void CheckArrayAbuse(Handle<JSObject> obj, const char* op, uint32_t key,
bool allow_appending = false);
Handle<Object> ArrayConstructInitializeElements(Handle<JSArray> array,
......
......@@ -2175,6 +2175,11 @@ Object* FixedArray::get(int index) {
}
Handle<Object> FixedArray::get(Handle<FixedArray> array, int index) {
return handle(array->get(index), array->GetIsolate());
}
bool FixedArray::is_the_hole(int index) {
return get(index) == GetHeap()->the_hole_value();
}
......@@ -2240,11 +2245,12 @@ MaybeObject* FixedDoubleArray::get(int index) {
}
Handle<Object> FixedDoubleArray::get_as_handle(int index) {
if (is_the_hole(index)) {
return GetIsolate()->factory()->the_hole_value();
Handle<Object> FixedDoubleArray::get(Handle<FixedDoubleArray> array,
int index) {
if (array->is_the_hole(index)) {
return array->GetIsolate()->factory()->the_hole_value();
} else {
return GetIsolate()->factory()->NewNumber(get_scalar(index));
return array->GetIsolate()->factory()->NewNumber(array->get_scalar(index));
}
}
......@@ -3612,11 +3618,18 @@ uint8_t ExternalUint8ClampedArray::get_scalar(int index) {
}
MaybeObject* ExternalUint8ClampedArray::get(int index) {
Object* ExternalUint8ClampedArray::get(int index) {
return Smi::FromInt(static_cast<int>(get_scalar(index)));
}
Handle<Object> ExternalUint8ClampedArray::get(
Handle<ExternalUint8ClampedArray> array,
int index) {
return handle(array->get(index), array->GetIsolate());
}
void ExternalUint8ClampedArray::set(int index, uint8_t value) {
ASSERT((index >= 0) && (index < this->length()));
uint8_t* ptr = external_uint8_clamped_pointer();
......@@ -3643,11 +3656,17 @@ int8_t ExternalInt8Array::get_scalar(int index) {
}
MaybeObject* ExternalInt8Array::get(int index) {
Object* ExternalInt8Array::get(int index) {
return Smi::FromInt(static_cast<int>(get_scalar(index)));
}
Handle<Object> ExternalInt8Array::get(Handle<ExternalInt8Array> array,
int index) {
return handle(array->get(index), array->GetIsolate());
}
void ExternalInt8Array::set(int index, int8_t value) {
ASSERT((index >= 0) && (index < this->length()));
int8_t* ptr = static_cast<int8_t*>(external_pointer());
......@@ -3662,11 +3681,17 @@ uint8_t ExternalUint8Array::get_scalar(int index) {
}
MaybeObject* ExternalUint8Array::get(int index) {
Object* ExternalUint8Array::get(int index) {
return Smi::FromInt(static_cast<int>(get_scalar(index)));
}
Handle<Object> ExternalUint8Array::get(Handle<ExternalUint8Array> array,
int index) {
return handle(array->get(index), array->GetIsolate());
}
void ExternalUint8Array::set(int index, uint8_t value) {
ASSERT((index >= 0) && (index < this->length()));
uint8_t* ptr = static_cast<uint8_t*>(external_pointer());
......@@ -3681,11 +3706,17 @@ int16_t ExternalInt16Array::get_scalar(int index) {
}
MaybeObject* ExternalInt16Array::get(int index) {
Object* ExternalInt16Array::get(int index) {
return Smi::FromInt(static_cast<int>(get_scalar(index)));
}
Handle<Object> ExternalInt16Array::get(Handle<ExternalInt16Array> array,
int index) {
return handle(array->get(index), array->GetIsolate());
}
void ExternalInt16Array::set(int index, int16_t value) {
ASSERT((index >= 0) && (index < this->length()));
int16_t* ptr = static_cast<int16_t*>(external_pointer());
......@@ -3700,11 +3731,17 @@ uint16_t ExternalUint16Array::get_scalar(int index) {
}
MaybeObject* ExternalUint16Array::get(int index) {
Object* ExternalUint16Array::get(int index) {
return Smi::FromInt(static_cast<int>(get_scalar(index)));
}
Handle<Object> ExternalUint16Array::get(Handle<ExternalUint16Array> array,
int index) {
return handle(array->get(index), array->GetIsolate());
}
void ExternalUint16Array::set(int index, uint16_t value) {
ASSERT((index >= 0) && (index < this->length()));
uint16_t* ptr = static_cast<uint16_t*>(external_pointer());
......@@ -3720,7 +3757,14 @@ int32_t ExternalInt32Array::get_scalar(int index) {
MaybeObject* ExternalInt32Array::get(int index) {
return GetHeap()->NumberFromInt32(get_scalar(index));
return GetHeap()->NumberFromInt32(get_scalar(index));
}
Handle<Object> ExternalInt32Array::get(Handle<ExternalInt32Array> array,
int index) {
return array->GetIsolate()->factory()->
NewNumberFromInt(array->get_scalar(index));
}
......@@ -3739,7 +3783,14 @@ uint32_t ExternalUint32Array::get_scalar(int index) {
MaybeObject* ExternalUint32Array::get(int index) {
return GetHeap()->NumberFromUint32(get_scalar(index));
return GetHeap()->NumberFromUint32(get_scalar(index));
}
Handle<Object> ExternalUint32Array::get(Handle<ExternalUint32Array> array,
int index) {
return array->GetIsolate()->factory()->
NewNumberFromUint(array->get_scalar(index));
}
......@@ -3758,7 +3809,13 @@ float ExternalFloat32Array::get_scalar(int index) {
MaybeObject* ExternalFloat32Array::get(int index) {
return GetHeap()->NumberFromDouble(get_scalar(index));
return GetHeap()->NumberFromDouble(get_scalar(index));
}
Handle<Object> ExternalFloat32Array::get(Handle<ExternalFloat32Array> array,
int index) {
return array->GetIsolate()->factory()->NewNumber(array->get_scalar(index));
}
......@@ -3781,6 +3838,12 @@ MaybeObject* ExternalFloat64Array::get(int index) {
}
Handle<Object> ExternalFloat64Array::get(Handle<ExternalFloat64Array> array,
int index) {
return array->GetIsolate()->factory()->NewNumber(array->get_scalar(index));
}
void ExternalFloat64Array::set(int index, double value) {
ASSERT((index >= 0) && (index < this->length()));
double* ptr = static_cast<double*>(external_pointer());
......@@ -3926,6 +3989,13 @@ MaybeObject* FixedTypedArray<Traits>::get(int index) {
return Traits::ToObject(GetHeap(), get_scalar(index));
}
template <class Traits>
Handle<Object> FixedTypedArray<Traits>::get(
Handle<FixedTypedArray<Traits> > array,
int index) {
return Traits::ToHandle(array->GetIsolate(), array->get_scalar(index));
}
template <class Traits>
MaybeObject* FixedTypedArray<Traits>::SetValue(uint32_t index, Object* value) {
ElementType cast_value = Traits::defaultValue();
......@@ -3962,46 +4032,92 @@ MaybeObject* Uint8ArrayTraits::ToObject(Heap*, uint8_t scalar) {
}
Handle<Object> Uint8ArrayTraits::ToHandle(Isolate* isolate, uint8_t scalar) {
return handle(Smi::FromInt(scalar), isolate);
}
MaybeObject* Uint8ClampedArrayTraits::ToObject(Heap*, uint8_t scalar) {
return Smi::FromInt(scalar);
}
Handle<Object> Uint8ClampedArrayTraits::ToHandle(Isolate* isolate,
uint8_t scalar) {
return handle(Smi::FromInt(scalar), isolate);
}
MaybeObject* Int8ArrayTraits::ToObject(Heap*, int8_t scalar) {
return Smi::FromInt(scalar);
}
Handle<Object> Int8ArrayTraits::ToHandle(Isolate* isolate, int8_t scalar) {
return handle(Smi::FromInt(scalar), isolate);
}
MaybeObject* Uint16ArrayTraits::ToObject(Heap*, uint16_t scalar) {
return Smi::FromInt(scalar);
}
Handle<Object> Uint16ArrayTraits::ToHandle(Isolate* isolate, uint16_t scalar) {
return handle(Smi::FromInt(scalar), isolate);
}
MaybeObject* Int16ArrayTraits::ToObject(Heap*, int16_t scalar) {
return Smi::FromInt(scalar);
}
Handle<Object> Int16ArrayTraits::ToHandle(Isolate* isolate, int16_t scalar) {
return handle(Smi::FromInt(scalar), isolate);
}
MaybeObject* Uint32ArrayTraits::ToObject(Heap* heap, uint32_t scalar) {
return heap->NumberFromUint32(scalar);
}
Handle<Object> Uint32ArrayTraits::ToHandle(Isolate* isolate, uint32_t scalar) {
return isolate->factory()->NewNumberFromUint(scalar);
}
MaybeObject* Int32ArrayTraits::ToObject(Heap* heap, int32_t scalar) {
return heap->NumberFromInt32(scalar);
}
Handle<Object> Int32ArrayTraits::ToHandle(Isolate* isolate, int32_t scalar) {
return isolate->factory()->NewNumberFromInt(scalar);
}
MaybeObject* Float32ArrayTraits::ToObject(Heap* heap, float scalar) {
return heap->NumberFromDouble(scalar);
}
Handle<Object> Float32ArrayTraits::ToHandle(Isolate* isolate, float scalar) {
return isolate->factory()->NewNumber(scalar);
}
MaybeObject* Float64ArrayTraits::ToObject(Heap* heap, double scalar) {
return heap->NumberFromDouble(scalar);
}
Handle<Object> Float64ArrayTraits::ToHandle(Isolate* isolate, double scalar) {
return isolate->factory()->NewNumber(scalar);
}
int Map::visitor_id() {
return READ_BYTE_FIELD(this, kVisitorIdOffset);
}
......
......@@ -11989,6 +11989,20 @@ MaybeHandle<Object> JSObject::SetElementWithInterceptor(
}
// TODO(ishell): Temporary wrapper until handlified.
Handle<Object> JSObject::GetElementWithCallback(
Handle<JSObject> object,
Handle<Object> receiver,
Handle<Object> structure,
uint32_t index,
Handle<Object> holder) {
CALL_HEAP_FUNCTION(object->GetIsolate(),
object->GetElementWithCallback(
*receiver, *structure, index, *holder),
Object);
}
MaybeObject* JSObject::GetElementWithCallback(Object* receiver,
Object* structure,
uint32_t index,
......@@ -12673,12 +12687,12 @@ MaybeHandle<Object> JSObject::SetElementWithoutInterceptor(
Isolate* isolate = object->GetIsolate();
if (FLAG_trace_external_array_abuse &&
IsExternalArrayElementsKind(object->GetElementsKind())) {
CheckArrayAbuse(*object, "external elements write", index);
CheckArrayAbuse(object, "external elements write", index);
}
if (FLAG_trace_js_array_abuse &&
!IsExternalArrayElementsKind(object->GetElementsKind())) {
if (object->IsJSArray()) {
CheckArrayAbuse(*object, "elements write", index, true);
CheckArrayAbuse(object, "elements write", index, true);
}
}
switch (object->GetElementsKind()) {
......
......@@ -2797,6 +2797,13 @@ class JSObject: public JSReceiver {
Handle<Name> name,
PropertyAttributes* attributes);
MUST_USE_RESULT static Handle<Object> GetElementWithCallback(
Handle<JSObject> object,
Handle<Object> receiver,
Handle<Object> structure,
uint32_t index,
Handle<Object> holder);
MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver,
Object* structure,
uint32_t index,
......@@ -3043,6 +3050,7 @@ class FixedArray: public FixedArrayBase {
public:
// Setter and getter for elements.
inline Object* get(int index);
static inline Handle<Object> get(Handle<FixedArray> array, int index);
// Setter that uses write barrier.
inline void set(int index, Object* value);
inline bool is_the_hole(int index);
......@@ -3159,8 +3167,7 @@ class FixedDoubleArray: public FixedArrayBase {
inline double get_scalar(int index);
inline int64_t get_representation(int index);
MUST_USE_RESULT inline MaybeObject* get(int index);
// TODO(ishell): Rename as get() once all usages handlified.
inline Handle<Object> get_as_handle(int index);
static inline Handle<Object> get(Handle<FixedDoubleArray> array, int index);
inline void set(int index, double value);
inline void set_the_hole(int index);
......@@ -4908,7 +4915,9 @@ class ExternalUint8ClampedArray: public ExternalArray {
// Setter and getter.
inline uint8_t get_scalar(int index);
MUST_USE_RESULT inline MaybeObject* get(int index);
MUST_USE_RESULT inline Object* get(int index);
static inline Handle<Object> get(Handle<ExternalUint8ClampedArray> array,
int index);
inline void set(int index, uint8_t value);
// This accessor applies the correct conversion from Smi, HeapNumber and
......@@ -4935,7 +4944,8 @@ class ExternalInt8Array: public ExternalArray {
public:
// Setter and getter.
inline int8_t get_scalar(int index);
MUST_USE_RESULT inline MaybeObject* get(int index);
MUST_USE_RESULT inline Object* get(int index);
static inline Handle<Object> get(Handle<ExternalInt8Array> array, int index);
inline void set(int index, int8_t value);
static Handle<Object> SetValue(Handle<ExternalInt8Array> array,
......@@ -4962,7 +4972,8 @@ class ExternalUint8Array: public ExternalArray {
public:
// Setter and getter.
inline uint8_t get_scalar(int index);
MUST_USE_RESULT inline MaybeObject* get(int index);
MUST_USE_RESULT inline Object* get(int index);
static inline Handle<Object> get(Handle<ExternalUint8Array> array, int index);
inline void set(int index, uint8_t value);
static Handle<Object> SetValue(Handle<ExternalUint8Array> array,
......@@ -4989,7 +5000,8 @@ class ExternalInt16Array: public ExternalArray {
public:
// Setter and getter.
inline int16_t get_scalar(int index);
MUST_USE_RESULT inline MaybeObject* get(int index);
MUST_USE_RESULT inline Object* get(int index);
static inline Handle<Object> get(Handle<ExternalInt16Array> array, int index);
inline void set(int index, int16_t value);
static Handle<Object> SetValue(Handle<ExternalInt16Array> array,
......@@ -5016,7 +5028,9 @@ class ExternalUint16Array: public ExternalArray {
public:
// Setter and getter.
inline uint16_t get_scalar(int index);
MUST_USE_RESULT inline MaybeObject* get(int index);
MUST_USE_RESULT inline Object* get(int index);
static inline Handle<Object> get(Handle<ExternalUint16Array> array,
int index);
inline void set(int index, uint16_t value);
static Handle<Object> SetValue(Handle<ExternalUint16Array> array,
......@@ -5044,6 +5058,7 @@ class ExternalInt32Array: public ExternalArray {
// Setter and getter.
inline int32_t get_scalar(int index);
MUST_USE_RESULT inline MaybeObject* get(int index);
static inline Handle<Object> get(Handle<ExternalInt32Array> array, int index);
inline void set(int index, int32_t value);
static Handle<Object> SetValue(Handle<ExternalInt32Array> array,
......@@ -5071,6 +5086,8 @@ class ExternalUint32Array: public ExternalArray {
// Setter and getter.
inline uint32_t get_scalar(int index);
MUST_USE_RESULT inline MaybeObject* get(int index);
static inline Handle<Object> get(Handle<ExternalUint32Array> array,
int index);
inline void set(int index, uint32_t value);
static Handle<Object> SetValue(Handle<ExternalUint32Array> array,
......@@ -5098,6 +5115,8 @@ class ExternalFloat32Array: public ExternalArray {
// Setter and getter.
inline float get_scalar(int index);
MUST_USE_RESULT inline MaybeObject* get(int index);
static inline Handle<Object> get(Handle<ExternalFloat32Array> array,
int index);
inline void set(int index, float value);
static Handle<Object> SetValue(Handle<ExternalFloat32Array> array,
......@@ -5125,6 +5144,8 @@ class ExternalFloat64Array: public ExternalArray {
// Setter and getter.
inline double get_scalar(int index);
MUST_USE_RESULT inline MaybeObject* get(int index);
static inline Handle<Object> get(Handle<ExternalFloat64Array> array,
int index);
inline void set(int index, double value);
static Handle<Object> SetValue(Handle<ExternalFloat64Array> array,
......@@ -5185,6 +5206,7 @@ class FixedTypedArray: public FixedTypedArrayBase {
inline ElementType get_scalar(int index);
MUST_USE_RESULT inline MaybeObject* get(int index);
static inline Handle<Object> get(Handle<FixedTypedArray> array, int index);
inline void set(int index, ElementType value);
static inline ElementType from_int(int value);
......@@ -5212,6 +5234,8 @@ class FixedTypedArray: public FixedTypedArrayBase {
static const InstanceType kInstanceType = FIXED_##TYPE##_ARRAY_TYPE; \
static const char* Designator() { return #type " array"; } \
static inline MaybeObject* ToObject(Heap* heap, elementType scalar); \
static inline Handle<Object> ToHandle(Isolate* isolate, \
elementType scalar); \
static inline elementType defaultValue(); \
}; \
\
......
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