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

Unified Diff: test/cctest/test-heap.cc

Issue 3970005: Make Failure inherit from MaybeObject instead of Object. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 2 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
« no previous file with comments | « test/cctest/test-disasm-ia32.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-heap.cc
===================================================================
--- test/cctest/test-heap.cc (revision 5696)
+++ test/cctest/test-heap.cc (working copy)
@@ -58,7 +58,7 @@
static void CheckNumber(double value, const char* string) {
- Object* obj = Heap::NumberFromDouble(value);
+ Object* obj = Heap::NumberFromDouble(value)->ToObjectChecked();
CHECK(obj->IsNumber());
bool exc;
Object* print_string = *Execution::ToString(Handle<Object>(obj), &exc);
@@ -76,9 +76,10 @@
CodeDesc desc;
assm.GetCode(&desc);
- Object* code = Heap::CreateCode(desc,
- Code::ComputeFlags(Code::STUB),
- Handle<Object>(Heap::undefined_value()));
+ Object* code = Heap::CreateCode(
+ desc,
+ Code::ComputeFlags(Code::STUB),
+ Handle<Object>(Heap::undefined_value()))->ToObjectChecked();
CHECK(code->IsCode());
HeapObject* obj = HeapObject::cast(code);
@@ -89,9 +90,10 @@
CHECK_EQ(code, found);
}
- Object* copy = Heap::CreateCode(desc,
- Code::ComputeFlags(Code::STUB),
- Handle<Object>(Heap::undefined_value()));
+ Object* copy = Heap::CreateCode(
+ desc,
+ Code::ComputeFlags(Code::STUB),
+ Handle<Object>(Heap::undefined_value()))->ToObjectChecked();
CHECK(copy->IsCode());
HeapObject* obj_copy = HeapObject::cast(copy);
Object* not_right = Heap::FindCodeObject(obj_copy->address() +
@@ -104,40 +106,42 @@
InitializeVM();
v8::HandleScope sc;
- Object* value = Heap::NumberFromDouble(1.000123);
+ Object* value = Heap::NumberFromDouble(1.000123)->ToObjectChecked();
CHECK(value->IsHeapNumber());
CHECK(value->IsNumber());
CHECK_EQ(1.000123, value->Number());
- value = Heap::NumberFromDouble(1.0);
+ value = Heap::NumberFromDouble(1.0)->ToObjectChecked();
CHECK(value->IsSmi());
CHECK(value->IsNumber());
CHECK_EQ(1.0, value->Number());
- value = Heap::NumberFromInt32(1024);
+ value = Heap::NumberFromInt32(1024)->ToObjectChecked();
CHECK(value->IsSmi());
CHECK(value->IsNumber());
CHECK_EQ(1024.0, value->Number());
- value = Heap::NumberFromInt32(Smi::kMinValue);
+ value = Heap::NumberFromInt32(Smi::kMinValue)->ToObjectChecked();
CHECK(value->IsSmi());
CHECK(value->IsNumber());
CHECK_EQ(Smi::kMinValue, Smi::cast(value)->value());
- value = Heap::NumberFromInt32(Smi::kMaxValue);
+ value = Heap::NumberFromInt32(Smi::kMaxValue)->ToObjectChecked();
CHECK(value->IsSmi());
CHECK(value->IsNumber());
CHECK_EQ(Smi::kMaxValue, Smi::cast(value)->value());
#ifndef V8_TARGET_ARCH_X64
// TODO(lrn): We need a NumberFromIntptr function in order to test this.
- value = Heap::NumberFromInt32(Smi::kMinValue - 1);
+ value = Heap::NumberFromInt32(Smi::kMinValue - 1)->ToObjectChecked();
CHECK(value->IsHeapNumber());
CHECK(value->IsNumber());
CHECK_EQ(static_cast<double>(Smi::kMinValue - 1), value->Number());
#endif
- value = Heap::NumberFromUint32(static_cast<uint32_t>(Smi::kMaxValue) + 1);
+ MaybeObject* maybe_value =
+ Heap::NumberFromUint32(static_cast<uint32_t>(Smi::kMaxValue) + 1);
+ value = maybe_value->ToObjectChecked();
CHECK(value->IsHeapNumber());
CHECK(value->IsNumber());
CHECK_EQ(static_cast<double>(static_cast<uint32_t>(Smi::kMaxValue) + 1),
@@ -208,11 +212,13 @@
Handle<Map> initial_map =
Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
function->set_initial_map(*initial_map);
- Top::context()->global()->SetProperty(*name, *function, NONE);
+ Top::context()->global()->SetProperty(*name,
+ *function,
+ NONE)->ToObjectChecked();
// Allocate an object. Unrooted after leaving the scope.
Handle<JSObject> obj = Factory::NewJSObject(function);
- obj->SetProperty(*prop_name, Smi::FromInt(23), NONE);
- obj->SetProperty(*prop_namex, Smi::FromInt(24), NONE);
+ obj->SetProperty(*prop_name, Smi::FromInt(23), NONE)->ToObjectChecked();
+ obj->SetProperty(*prop_namex, Smi::FromInt(24), NONE)->ToObjectChecked();
CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex));
@@ -223,7 +229,8 @@
// Function should be alive.
CHECK(Top::context()->global()->HasLocalProperty(*name));
// Check function is retained.
- Object* func_value = Top::context()->global()->GetProperty(*name);
+ Object* func_value =
+ Top::context()->global()->GetProperty(*name)->ToObjectChecked();
CHECK(func_value->IsJSFunction());
Handle<JSFunction> function(JSFunction::cast(func_value));
@@ -231,18 +238,22 @@
HandleScope inner_scope;
// Allocate another object, make it reachable from global.
Handle<JSObject> obj = Factory::NewJSObject(function);
- Top::context()->global()->SetProperty(*obj_name, *obj, NONE);
- obj->SetProperty(*prop_name, Smi::FromInt(23), NONE);
+ Top::context()->global()->SetProperty(*obj_name,
+ *obj,
+ NONE)->ToObjectChecked();
+ obj->SetProperty(*prop_name, Smi::FromInt(23), NONE)->ToObjectChecked();
}
// After gc, it should survive.
Heap::CollectGarbage(NEW_SPACE);
CHECK(Top::context()->global()->HasLocalProperty(*obj_name));
- CHECK(Top::context()->global()->GetProperty(*obj_name)->IsJSObject());
- JSObject* obj =
- JSObject::cast(Top::context()->global()->GetProperty(*obj_name));
- CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
+ CHECK(Top::context()->global()->GetProperty(*obj_name)->ToObjectChecked()->
+ IsJSObject());
+ Object* obj =
+ Top::context()->global()->GetProperty(*obj_name)->ToObjectChecked();
+ JSObject* js_obj = JSObject::cast(obj);
+ CHECK_EQ(Smi::FromInt(23), js_obj->GetProperty(*prop_name));
}
@@ -494,12 +505,14 @@
static void CheckSymbols(const char** strings) {
for (const char* string = *strings; *strings != 0; string = *strings++) {
- Object* a = Heap::LookupAsciiSymbol(string);
+ Object* a;
+ MaybeObject* maybe_a = Heap::LookupAsciiSymbol(string);
// LookupAsciiSymbol may return a failure if a GC is needed.
- if (a->IsFailure()) continue;
+ if (!maybe_a->ToObject(&a)) continue;
CHECK(a->IsSymbol());
- Object* b = Heap::LookupAsciiSymbol(string);
- if (b->IsFailure()) continue;
+ Object* b;
+ MaybeObject* maybe_b = Heap::LookupAsciiSymbol(string);
+ if (!maybe_maybe_b->ToObject(&b)) continue;
CHECK_EQ(b, a);
CHECK(String::cast(b)->IsEqualTo(CStrVector(string)));
}
@@ -527,10 +540,12 @@
Handle<String> prop_name = Factory::LookupAsciiSymbol("theSlot");
Handle<JSObject> obj = Factory::NewJSObject(function);
- obj->SetProperty(*prop_name, Smi::FromInt(23), NONE);
+ obj->SetProperty(*prop_name, Smi::FromInt(23), NONE)->ToObjectChecked();
CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
// Check that we can add properties to function objects.
- function->SetProperty(*prop_name, Smi::FromInt(24), NONE);
+ function->SetProperty(*prop_name,
+ Smi::FromInt(24),
+ NONE)->ToObjectChecked();
CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name));
}
@@ -540,8 +555,9 @@
v8::HandleScope sc;
String* object_symbol = String::cast(Heap::Object_symbol());
- JSFunction* object_function =
- JSFunction::cast(Top::context()->global()->GetProperty(object_symbol));
+ Object* raw_object =
+ Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked();
+ JSFunction* object_function = JSFunction::cast(raw_object);
Handle<JSFunction> constructor(object_function);
Handle<JSObject> obj = Factory::NewJSObject(constructor);
Handle<String> first = Factory::LookupAsciiSymbol("first");
@@ -551,7 +567,7 @@
CHECK(!obj->HasLocalProperty(*first));
// add first
- obj->SetProperty(*first, Smi::FromInt(1), NONE);
+ obj->SetProperty(*first, Smi::FromInt(1), NONE)->ToObjectChecked();
CHECK(obj->HasLocalProperty(*first));
// delete first
@@ -559,8 +575,8 @@
CHECK(!obj->HasLocalProperty(*first));
// add first and then second
- obj->SetProperty(*first, Smi::FromInt(1), NONE);
- obj->SetProperty(*second, Smi::FromInt(2), NONE);
+ obj->SetProperty(*first, Smi::FromInt(1), NONE)->ToObjectChecked();
+ obj->SetProperty(*second, Smi::FromInt(2), NONE)->ToObjectChecked();
CHECK(obj->HasLocalProperty(*first));
CHECK(obj->HasLocalProperty(*second));
@@ -572,8 +588,8 @@
CHECK(!obj->HasLocalProperty(*second));
// add first and then second
- obj->SetProperty(*first, Smi::FromInt(1), NONE);
- obj->SetProperty(*second, Smi::FromInt(2), NONE);
+ obj->SetProperty(*first, Smi::FromInt(1), NONE)->ToObjectChecked();
+ obj->SetProperty(*second, Smi::FromInt(2), NONE)->ToObjectChecked();
CHECK(obj->HasLocalProperty(*first));
CHECK(obj->HasLocalProperty(*second));
@@ -587,14 +603,14 @@
// check string and symbol match
static const char* string1 = "fisk";
Handle<String> s1 = Factory::NewStringFromAscii(CStrVector(string1));
- obj->SetProperty(*s1, Smi::FromInt(1), NONE);
+ obj->SetProperty(*s1, Smi::FromInt(1), NONE)->ToObjectChecked();
Handle<String> s1_symbol = Factory::LookupAsciiSymbol(string1);
CHECK(obj->HasLocalProperty(*s1_symbol));
// check symbol and string match
static const char* string2 = "fugl";
Handle<String> s2_symbol = Factory::LookupAsciiSymbol(string2);
- obj->SetProperty(*s2_symbol, Smi::FromInt(1), NONE);
+ obj->SetProperty(*s2_symbol, Smi::FromInt(1), NONE)->ToObjectChecked();
Handle<String> s2 = Factory::NewStringFromAscii(CStrVector(string2));
CHECK(obj->HasLocalProperty(*s2));
}
@@ -615,7 +631,7 @@
Handle<JSObject> obj = Factory::NewJSObject(function);
// Set a propery
- obj->SetProperty(*prop_name, Smi::FromInt(23), NONE);
+ obj->SetProperty(*prop_name, Smi::FromInt(23), NONE)->ToObjectChecked();
CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
// Check the map has changed
@@ -628,33 +644,31 @@
v8::HandleScope sc;
Handle<String> name = Factory::LookupAsciiSymbol("Array");
+ Object* raw_object =
+ Top::context()->global()->GetProperty(*name)->ToObjectChecked();
Handle<JSFunction> function = Handle<JSFunction>(
- JSFunction::cast(Top::context()->global()->GetProperty(*name)));
+ JSFunction::cast(raw_object));
// Allocate the object.
Handle<JSObject> object = Factory::NewJSObject(function);
Handle<JSArray> array = Handle<JSArray>::cast(object);
- Object* ok = array->Initialize(0);
// We just initialized the VM, no heap allocation failure yet.
- CHECK(!ok->IsFailure());
+ Object* ok = array->Initialize(0)->ToObjectChecked();
// Set array length to 0.
- ok = array->SetElementsLength(Smi::FromInt(0));
- CHECK(!ok->IsFailure());
+ ok = array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked();
CHECK_EQ(Smi::FromInt(0), array->length());
CHECK(array->HasFastElements()); // Must be in fast mode.
// array[length] = name.
- ok = array->SetElement(0, *name);
- CHECK(!ok->IsFailure());
+ ok = array->SetElement(0, *name)->ToObjectChecked();
CHECK_EQ(Smi::FromInt(1), array->length());
CHECK_EQ(array->GetElement(0), *name);
// Set array length with larger than smi value.
Handle<Object> length =
Factory::NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
- ok = array->SetElementsLength(*length);
- CHECK(!ok->IsFailure());
+ ok = array->SetElementsLength(*length)->ToObjectChecked();
uint32_t int_length = 0;
CHECK(length->ToArrayIndex(&int_length));
@@ -662,8 +676,7 @@
CHECK(array->HasDictionaryElements()); // Must be in slow mode.
// array[length] = name.
- ok = array->SetElement(int_length, *name);
- CHECK(!ok->IsFailure());
+ ok = array->SetElement(int_length, *name)->ToObjectChecked();
uint32_t new_int_length = 0;
CHECK(array->length()->ToArrayIndex(&new_int_length));
CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
@@ -677,21 +690,20 @@
v8::HandleScope sc;
String* object_symbol = String::cast(Heap::Object_symbol());
- JSFunction* object_function =
- JSFunction::cast(Top::context()->global()->GetProperty(object_symbol));
+ Object* raw_object =
+ Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked();
+ JSFunction* object_function = JSFunction::cast(raw_object);
Handle<JSFunction> constructor(object_function);
Handle<JSObject> obj = Factory::NewJSObject(constructor);
Handle<String> first = Factory::LookupAsciiSymbol("first");
Handle<String> second = Factory::LookupAsciiSymbol("second");
- obj->SetProperty(*first, Smi::FromInt(1), NONE);
- obj->SetProperty(*second, Smi::FromInt(2), NONE);
+ obj->SetProperty(*first, Smi::FromInt(1), NONE)->ToObjectChecked();
+ obj->SetProperty(*second, Smi::FromInt(2), NONE)->ToObjectChecked();
- Object* ok = obj->SetElement(0, *first);
- CHECK(!ok->IsFailure());
+ Object* ok = obj->SetElement(0, *first)->ToObjectChecked();
- ok = obj->SetElement(1, *second);
- CHECK(!ok->IsFailure());
+ ok = obj->SetElement(1, *second)->ToObjectChecked();
// Make the clone.
Handle<JSObject> clone = Copy(obj);
@@ -704,13 +716,11 @@
CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second));
// Flip the values.
- clone->SetProperty(*first, Smi::FromInt(2), NONE);
- clone->SetProperty(*second, Smi::FromInt(1), NONE);
+ clone->SetProperty(*first, Smi::FromInt(2), NONE)->ToObjectChecked();
+ clone->SetProperty(*second, Smi::FromInt(1), NONE)->ToObjectChecked();
- ok = clone->SetElement(0, *second);
- CHECK(!ok->IsFailure());
- ok = clone->SetElement(1, *first);
- CHECK(!ok->IsFailure());
+ ok = clone->SetElement(0, *second)->ToObjectChecked();
+ ok = clone->SetElement(1, *first)->ToObjectChecked();
CHECK_EQ(obj->GetElement(1), clone->GetElement(0));
CHECK_EQ(obj->GetElement(0), clone->GetElement(1));
@@ -836,7 +846,7 @@
kPointerSize;
CHECK_EQ(bytes_to_allocate, FixedArray::SizeFor(n_elements));
FixedArray* array = FixedArray::cast(
- Heap::AllocateFixedArray(n_elements));
+ Heap::AllocateFixedArray(n_elements)->ToObjectChecked());
int index = n_elements - 1;
CHECK_EQ(flags_ptr,
@@ -908,8 +918,8 @@
Address* limit_addr = new_space->allocation_limit_address();
while ((*limit_addr - *top_addr) > allocation_amount) {
CHECK(!Heap::always_allocate());
- Object* array = Heap::AllocateFixedArray(allocation_len);
- CHECK(!array->IsFailure());
+ Object* array =
+ Heap::AllocateFixedArray(allocation_len)->ToObjectChecked();
CHECK(new_space->Contains(array));
}
@@ -919,12 +929,11 @@
CHECK(fixed_array_len < FixedArray::kMaxLength);
CHECK(!Heap::always_allocate());
- Object* array = Heap::AllocateFixedArray(fixed_array_len);
- CHECK(!array->IsFailure());
+ Object* array =
+ Heap::AllocateFixedArray(fixed_array_len)->ToObjectChecked();
CHECK(new_space->Contains(array));
- Object* object = Heap::AllocateJSObjectFromMap(*my_map);
- CHECK(!object->IsFailure());
+ Object* object = Heap::AllocateJSObjectFromMap(*my_map)->ToObjectChecked();
CHECK(new_space->Contains(object));
JSObject* jsobject = JSObject::cast(object);
CHECK_EQ(0, FixedArray::cast(jsobject->elements())->length());
@@ -938,8 +947,7 @@
// in old pointer space.
Address old_pointer_space_top = Heap::old_pointer_space()->top();
AlwaysAllocateScope aa_scope;
- Object* clone_obj = Heap::CopyJSObject(jsobject);
- CHECK(!object->IsFailure());
+ Object* clone_obj = Heap::CopyJSObject(jsobject)->ToObjectChecked();
JSObject* clone = JSObject::cast(clone_obj);
if (clone->address() != old_pointer_space_top) {
// Alas, got allocated from free list, we cannot do checks.
@@ -973,7 +981,8 @@
CompileRun(source);
// Check function is compiled.
- Object* func_value = Top::context()->global()->GetProperty(*foo_name);
+ Object* func_value =
+ Top::context()->global()->GetProperty(*foo_name)->ToObjectChecked();
CHECK(func_value->IsJSFunction());
Handle<JSFunction> function(JSFunction::cast(func_value));
CHECK(function->shared()->is_compiled());
« no previous file with comments | « test/cctest/test-disasm-ia32.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698