Commit 9a71bc72 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Remove further unhandlified call sites of number allocations.

R=dslomov@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20785 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 7ffbbbef
......@@ -591,11 +591,11 @@ class ElementsAccessorBase : public ElementsAccessor {
return ElementsTraits::Kind;
}
static void ValidateContents(JSObject* holder, int length) {
static void ValidateContents(Handle<JSObject> holder, int length) {
}
static void ValidateImpl(JSObject* holder) {
FixedArrayBase* fixed_array_base = holder->elements();
static void ValidateImpl(Handle<JSObject> holder) {
Handle<FixedArrayBase> fixed_array_base(holder->elements());
// When objects are first allocated, its elements are Failures.
if (fixed_array_base->IsFailure()) return;
if (!fixed_array_base->IsHeapObject()) return;
......@@ -603,7 +603,7 @@ class ElementsAccessorBase : public ElementsAccessor {
if (fixed_array_base->IsFiller()) return;
int length = 0;
if (holder->IsJSArray()) {
Object* length_obj = JSArray::cast(holder)->length();
Object* length_obj = Handle<JSArray>::cast(holder)->length();
if (length_obj->IsSmi()) {
length = Smi::cast(length_obj)->value();
}
......@@ -615,7 +615,7 @@ class ElementsAccessorBase : public ElementsAccessor {
virtual void Validate(Handle<JSObject> holder) V8_FINAL V8_OVERRIDE {
DisallowHeapAllocation no_gc;
ElementsAccessorSubclass::ValidateImpl(*holder);
ElementsAccessorSubclass::ValidateImpl(holder);
}
static bool HasElementImpl(Handle<Object> receiver,
......@@ -1063,21 +1063,24 @@ class FastElementsAccessor
return !Handle<BackingStore>::cast(backing_store)->is_the_hole(key);
}
static void ValidateContents(JSObject* holder, int length) {
static void ValidateContents(Handle<JSObject> holder, int length) {
#if DEBUG
FixedArrayBase* elements = holder->elements();
Heap* heap = elements->GetHeap();
Isolate* isolate = holder->GetIsolate();
HandleScope scope(isolate);
Handle<FixedArrayBase> elements(holder->elements(), isolate);
Map* map = elements->map();
ASSERT((IsFastSmiOrObjectElementsKind(KindTraits::Kind) &&
(map == heap->fixed_array_map() ||
map == heap->fixed_cow_array_map())) ||
(map == isolate->heap()->fixed_array_map() ||
map == isolate->heap()->fixed_cow_array_map())) ||
(IsFastDoubleElementsKind(KindTraits::Kind) ==
((map == heap->fixed_array_map() && length == 0) ||
map == heap->fixed_double_array_map())));
((map == isolate->heap()->fixed_array_map() && length == 0) ||
map == isolate->heap()->fixed_double_array_map())));
DisallowHeapAllocation no_gc;
for (int i = 0; i < length; i++) {
BackingStore* backing_store = BackingStore::cast(elements);
HandleScope scope(isolate);
Handle<BackingStore> backing_store = Handle<BackingStore>::cast(elements);
ASSERT((!IsFastSmiElementsKind(KindTraits::Kind) ||
static_cast<Object*>(backing_store->get(i))->IsSmi()) ||
BackingStore::get(backing_store, i)->IsSmi()) ||
(IsFastHoleyElementsKind(KindTraits::Kind) ==
backing_store->is_the_hole(i)));
}
......
......@@ -2222,14 +2222,6 @@ int64_t FixedDoubleArray::get_representation(int index) {
return READ_INT64_FIELD(this, kHeaderSize + index * kDoubleSize);
}
MaybeObject* FixedDoubleArray::get(int index) {
if (is_the_hole(index)) {
return GetHeap()->the_hole_value();
} else {
return GetHeap()->NumberFromDouble(get_scalar(index));
}
}
Handle<Object> FixedDoubleArray::get(Handle<FixedDoubleArray> array,
int index) {
......@@ -3636,15 +3628,11 @@ uint8_t ExternalUint8ClampedArray::get_scalar(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());
return Handle<Smi>(Smi::FromInt(array->get_scalar(index)),
array->GetIsolate());
}
......@@ -3674,14 +3662,10 @@ int8_t ExternalInt8Array::get_scalar(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());
return Handle<Smi>(Smi::FromInt(array->get_scalar(index)),
array->GetIsolate());
}
......@@ -3699,14 +3683,10 @@ uint8_t ExternalUint8Array::get_scalar(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());
return Handle<Smi>(Smi::FromInt(array->get_scalar(index)),
array->GetIsolate());
}
......@@ -3724,14 +3704,10 @@ int16_t ExternalInt16Array::get_scalar(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());
return Handle<Smi>(Smi::FromInt(array->get_scalar(index)),
array->GetIsolate());
}
......@@ -3749,14 +3725,10 @@ uint16_t ExternalUint16Array::get_scalar(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());
return Handle<Smi>(Smi::FromInt(array->get_scalar(index)),
array->GetIsolate());
}
......@@ -3774,11 +3746,6 @@ int32_t ExternalInt32Array::get_scalar(int index) {
}
MaybeObject* ExternalInt32Array::get(int index) {
return GetHeap()->NumberFromInt32(get_scalar(index));
}
Handle<Object> ExternalInt32Array::get(Handle<ExternalInt32Array> array,
int index) {
return array->GetIsolate()->factory()->
......@@ -3800,11 +3767,6 @@ uint32_t ExternalUint32Array::get_scalar(int index) {
}
MaybeObject* ExternalUint32Array::get(int index) {
return GetHeap()->NumberFromUint32(get_scalar(index));
}
Handle<Object> ExternalUint32Array::get(Handle<ExternalUint32Array> array,
int index) {
return array->GetIsolate()->factory()->
......@@ -3826,11 +3788,6 @@ float ExternalFloat32Array::get_scalar(int index) {
}
MaybeObject* ExternalFloat32Array::get(int 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));
......@@ -3851,11 +3808,6 @@ double ExternalFloat64Array::get_scalar(int index) {
}
MaybeObject* ExternalFloat64Array::get(int index) {
return GetHeap()->NumberFromDouble(get_scalar(index));
}
Handle<Object> ExternalFloat64Array::get(Handle<ExternalFloat64Array> array,
int index) {
return array->GetIsolate()->factory()->NewNumber(array->get_scalar(index));
......@@ -4002,11 +3954,6 @@ double FixedTypedArray<Float64ArrayTraits>::from_double(double value) {
}
template <class Traits>
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,
......@@ -4014,39 +3961,28 @@ Handle<Object> FixedTypedArray<Traits>::get(
return Traits::ToHandle(array->GetIsolate(), array->get_scalar(index));
}
template <class Traits>
MaybeObject* FixedTypedArray<Traits>::SetValue(uint32_t index, Object* value) {
Handle<Object> FixedTypedArray<Traits>::SetValue(
Handle<FixedTypedArray<Traits> > array,
uint32_t index,
Handle<Object> value) {
ElementType cast_value = Traits::defaultValue();
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 = from_int(int_value);
} else if (value->IsHeapNumber()) {
double double_value = HeapNumber::cast(value)->value();
double double_value = Handle<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.
ASSERT(value->IsUndefined());
}
set(index, cast_value);
array->set(index, cast_value);
}
return Traits::ToObject(GetHeap(), cast_value);
}
template <class Traits>
Handle<Object> FixedTypedArray<Traits>::SetValue(
Handle<FixedTypedArray<Traits> > array,
uint32_t index,
Handle<Object> value) {
CALL_HEAP_FUNCTION(array->GetIsolate(),
array->SetValue(index, *value),
Object);
}
MaybeObject* Uint8ArrayTraits::ToObject(Heap*, uint8_t scalar) {
return Smi::FromInt(scalar);
return Traits::ToHandle(array->GetIsolate(), cast_value);
}
......@@ -4055,82 +3991,42 @@ Handle<Object> Uint8ArrayTraits::ToHandle(Isolate* isolate, uint8_t scalar) {
}
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);
}
......
......@@ -3170,7 +3170,6 @@ class FixedDoubleArray: public FixedArrayBase {
// Setter and getter for elements.
inline double get_scalar(int index);
inline int64_t get_representation(int index);
MUST_USE_RESULT inline MaybeObject* get(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);
......@@ -4924,7 +4923,6 @@ class ExternalUint8ClampedArray: public ExternalArray {
// Setter and getter.
inline uint8_t get_scalar(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);
......@@ -4951,7 +4949,6 @@ class ExternalInt8Array: public ExternalArray {
public:
// Setter and getter.
inline int8_t get_scalar(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);
......@@ -4977,7 +4974,6 @@ class ExternalUint8Array: public ExternalArray {
public:
// Setter and getter.
inline uint8_t get_scalar(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);
......@@ -5003,7 +4999,6 @@ class ExternalInt16Array: public ExternalArray {
public:
// Setter and getter.
inline int16_t get_scalar(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);
......@@ -5029,7 +5024,6 @@ class ExternalUint16Array: public ExternalArray {
public:
// Setter and getter.
inline uint16_t get_scalar(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);
......@@ -5056,7 +5050,6 @@ class ExternalInt32Array: public ExternalArray {
public:
// 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);
......@@ -5082,7 +5075,6 @@ class ExternalUint32Array: public ExternalArray {
public:
// 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);
......@@ -5109,7 +5101,6 @@ class ExternalFloat32Array: public ExternalArray {
public:
// 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);
......@@ -5136,7 +5127,6 @@ class ExternalFloat64Array: public ExternalArray {
public:
// 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);
......@@ -5196,7 +5186,6 @@ 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);
......@@ -5205,8 +5194,6 @@ class FixedTypedArray: public FixedTypedArrayBase {
// This accessor applies the correct conversion from Smi, HeapNumber
// and undefined.
MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
static Handle<Object> SetValue(Handle<FixedTypedArray<Traits> > array,
uint32_t index,
Handle<Object> value);
......@@ -5224,7 +5211,6 @@ class FixedTypedArray: public FixedTypedArrayBase {
typedef elementType ElementType; \
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(); \
......
......@@ -99,12 +99,11 @@ static void CheckSmi(Isolate* isolate, int value, const char* string) {
static void CheckNumber(Isolate* isolate, double value, const char* string) {
Object* obj = CcTest::heap()->NumberFromDouble(value)->ToObjectChecked();
CHECK(obj->IsNumber());
Handle<Object> handle(obj, isolate);
Object* print_string =
*Execution::ToString(isolate, handle).ToHandleChecked();
CHECK(String::cast(print_string)->IsUtf8EqualTo(CStrVector(string)));
Handle<Object> number = isolate->factory()->NewNumber(value);
CHECK(number->IsNumber());
Handle<Object> print_string =
Execution::ToString(isolate, number).ToHandleChecked();
CHECK(String::cast(*print_string)->IsUtf8EqualTo(CStrVector(string)));
}
......@@ -162,57 +161,54 @@ TEST(HeapObjects) {
Heap* heap = isolate->heap();
HandleScope sc(isolate);
Object* value = heap->NumberFromDouble(1.000123)->ToObjectChecked();
Handle<Object> value = factory->NewNumber(1.000123);
CHECK(value->IsHeapNumber());
CHECK(value->IsNumber());
CHECK_EQ(1.000123, value->Number());
value = heap->NumberFromDouble(1.0)->ToObjectChecked();
value = factory->NewNumber(1.0);
CHECK(value->IsSmi());
CHECK(value->IsNumber());
CHECK_EQ(1.0, value->Number());
value = heap->NumberFromInt32(1024)->ToObjectChecked();
value = factory->NewNumberFromInt(1024);
CHECK(value->IsSmi());
CHECK(value->IsNumber());
CHECK_EQ(1024.0, value->Number());
value = heap->NumberFromInt32(Smi::kMinValue)->ToObjectChecked();
value = factory->NewNumberFromInt(Smi::kMinValue);
CHECK(value->IsSmi());
CHECK(value->IsNumber());
CHECK_EQ(Smi::kMinValue, Smi::cast(value)->value());
CHECK_EQ(Smi::kMinValue, Handle<Smi>::cast(value)->value());
value = heap->NumberFromInt32(Smi::kMaxValue)->ToObjectChecked();
value = factory->NewNumberFromInt(Smi::kMaxValue);
CHECK(value->IsSmi());
CHECK(value->IsNumber());
CHECK_EQ(Smi::kMaxValue, Smi::cast(value)->value());
CHECK_EQ(Smi::kMaxValue, Handle<Smi>::cast(value)->value());
#if !defined(V8_TARGET_ARCH_X64) && !defined(V8_TARGET_ARCH_ARM64)
// TODO(lrn): We need a NumberFromIntptr function in order to test this.
value = heap->NumberFromInt32(Smi::kMinValue - 1)->ToObjectChecked();
value = factory->NewNumberFromInt(Smi::kMinValue - 1);
CHECK(value->IsHeapNumber());
CHECK(value->IsNumber());
CHECK_EQ(static_cast<double>(Smi::kMinValue - 1), value->Number());
#endif
MaybeObject* maybe_value =
heap->NumberFromUint32(static_cast<uint32_t>(Smi::kMaxValue) + 1);
value = maybe_value->ToObjectChecked();
value = factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
CHECK(value->IsHeapNumber());
CHECK(value->IsNumber());
CHECK_EQ(static_cast<double>(static_cast<uint32_t>(Smi::kMaxValue) + 1),
value->Number());
maybe_value = heap->NumberFromUint32(static_cast<uint32_t>(1) << 31);
value = maybe_value->ToObjectChecked();
value = factory->NewNumberFromUint(static_cast<uint32_t>(1) << 31);
CHECK(value->IsHeapNumber());
CHECK(value->IsNumber());
CHECK_EQ(static_cast<double>(static_cast<uint32_t>(1) << 31),
value->Number());
// nan oddball checks
CHECK(heap->nan_value()->IsNumber());
CHECK(std::isnan(heap->nan_value()->Number()));
CHECK(factory->nan_value()->IsNumber());
CHECK(std::isnan(factory->nan_value()->Number()));
Handle<String> s = factory->NewStringFromAscii(CStrVector("fisk hest "));
CHECK(s->IsString());
......
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