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

Side by Side Diff: test/cctest/test-heap.cc

Issue 418383002: Change Has* and Get*Attributes to return Maybe<*>, indicating possible exceptions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // nan oddball checks 203 // nan oddball checks
204 CHECK(factory->nan_value()->IsNumber()); 204 CHECK(factory->nan_value()->IsNumber());
205 CHECK(std::isnan(factory->nan_value()->Number())); 205 CHECK(std::isnan(factory->nan_value()->Number()));
206 206
207 Handle<String> s = factory->NewStringFromStaticAscii("fisk hest "); 207 Handle<String> s = factory->NewStringFromStaticAscii("fisk hest ");
208 CHECK(s->IsString()); 208 CHECK(s->IsString());
209 CHECK_EQ(10, s->length()); 209 CHECK_EQ(10, s->length());
210 210
211 Handle<String> object_string = Handle<String>::cast(factory->Object_string()); 211 Handle<String> object_string = Handle<String>::cast(factory->Object_string());
212 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object()); 212 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object());
213 CHECK(JSReceiver::HasOwnProperty(global, object_string)); 213 v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, object_string);
214 CHECK(maybe.has_value);
215 CHECK(maybe.value);
214 216
215 // Check ToString for oddballs 217 // Check ToString for oddballs
216 CheckOddball(isolate, heap->true_value(), "true"); 218 CheckOddball(isolate, heap->true_value(), "true");
217 CheckOddball(isolate, heap->false_value(), "false"); 219 CheckOddball(isolate, heap->false_value(), "false");
218 CheckOddball(isolate, heap->null_value(), "null"); 220 CheckOddball(isolate, heap->null_value(), "null");
219 CheckOddball(isolate, heap->undefined_value(), "undefined"); 221 CheckOddball(isolate, heap->undefined_value(), "undefined");
220 222
221 // Check ToString for Smis 223 // Check ToString for Smis
222 CheckSmi(isolate, 0, "0"); 224 CheckSmi(isolate, 0, "0");
223 CheckSmi(isolate, 42, "42"); 225 CheckSmi(isolate, 42, "42");
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 272
271 CHECK_EQ(Smi::FromInt(23), 273 CHECK_EQ(Smi::FromInt(23),
272 *Object::GetProperty(obj, prop_name).ToHandleChecked()); 274 *Object::GetProperty(obj, prop_name).ToHandleChecked());
273 CHECK_EQ(Smi::FromInt(24), 275 CHECK_EQ(Smi::FromInt(24),
274 *Object::GetProperty(obj, prop_namex).ToHandleChecked()); 276 *Object::GetProperty(obj, prop_namex).ToHandleChecked());
275 } 277 }
276 278
277 heap->CollectGarbage(NEW_SPACE); 279 heap->CollectGarbage(NEW_SPACE);
278 280
279 // Function should be alive. 281 // Function should be alive.
280 CHECK(JSReceiver::HasOwnProperty(global, name)); 282 v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, name);
283 CHECK(maybe.has_value);
284 CHECK(maybe.value);
281 // Check function is retained. 285 // Check function is retained.
282 Handle<Object> func_value = 286 Handle<Object> func_value =
283 Object::GetProperty(global, name).ToHandleChecked(); 287 Object::GetProperty(global, name).ToHandleChecked();
284 CHECK(func_value->IsJSFunction()); 288 CHECK(func_value->IsJSFunction());
285 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); 289 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
286 290
287 { 291 {
288 HandleScope inner_scope(isolate); 292 HandleScope inner_scope(isolate);
289 // Allocate another object, make it reachable from global. 293 // Allocate another object, make it reachable from global.
290 Handle<JSObject> obj = factory->NewJSObject(function); 294 Handle<JSObject> obj = factory->NewJSObject(function);
291 JSReceiver::SetProperty(global, obj_name, obj, SLOPPY).Check(); 295 JSReceiver::SetProperty(global, obj_name, obj, SLOPPY).Check();
292 JSReceiver::SetProperty(obj, prop_name, twenty_three, SLOPPY).Check(); 296 JSReceiver::SetProperty(obj, prop_name, twenty_three, SLOPPY).Check();
293 } 297 }
294 298
295 // After gc, it should survive. 299 // After gc, it should survive.
296 heap->CollectGarbage(NEW_SPACE); 300 heap->CollectGarbage(NEW_SPACE);
297 301
298 CHECK(JSReceiver::HasOwnProperty(global, obj_name)); 302 maybe = JSReceiver::HasOwnProperty(global, obj_name);
303 CHECK(maybe.has_value);
304 CHECK(maybe.value);
299 Handle<Object> obj = 305 Handle<Object> obj =
300 Object::GetProperty(global, obj_name).ToHandleChecked(); 306 Object::GetProperty(global, obj_name).ToHandleChecked();
301 CHECK(obj->IsJSObject()); 307 CHECK(obj->IsJSObject());
302 CHECK_EQ(Smi::FromInt(23), 308 CHECK_EQ(Smi::FromInt(23),
303 *Object::GetProperty(obj, prop_name).ToHandleChecked()); 309 *Object::GetProperty(obj, prop_name).ToHandleChecked());
304 } 310 }
305 311
306 312
307 static void VerifyStringAllocation(Isolate* isolate, const char* string) { 313 static void VerifyStringAllocation(Isolate* isolate, const char* string) {
308 HandleScope scope(isolate); 314 HandleScope scope(isolate);
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 CcTest::i_isolate()->global_object(), object_string).ToHandleChecked(); 651 CcTest::i_isolate()->global_object(), object_string).ToHandleChecked();
646 Handle<JSFunction> constructor = Handle<JSFunction>::cast(object); 652 Handle<JSFunction> constructor = Handle<JSFunction>::cast(object);
647 Handle<JSObject> obj = factory->NewJSObject(constructor); 653 Handle<JSObject> obj = factory->NewJSObject(constructor);
648 Handle<String> first = factory->InternalizeUtf8String("first"); 654 Handle<String> first = factory->InternalizeUtf8String("first");
649 Handle<String> second = factory->InternalizeUtf8String("second"); 655 Handle<String> second = factory->InternalizeUtf8String("second");
650 656
651 Handle<Smi> one(Smi::FromInt(1), isolate); 657 Handle<Smi> one(Smi::FromInt(1), isolate);
652 Handle<Smi> two(Smi::FromInt(2), isolate); 658 Handle<Smi> two(Smi::FromInt(2), isolate);
653 659
654 // check for empty 660 // check for empty
655 CHECK(!JSReceiver::HasOwnProperty(obj, first)); 661 v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(obj, first);
662 CHECK(maybe.has_value);
663 CHECK(!maybe.value);
656 664
657 // add first 665 // add first
658 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check(); 666 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
659 CHECK(JSReceiver::HasOwnProperty(obj, first)); 667 maybe = JSReceiver::HasOwnProperty(obj, first);
668 CHECK(maybe.has_value);
669 CHECK(maybe.value);
660 670
661 // delete first 671 // delete first
662 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION).Check(); 672 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION).Check();
663 CHECK(!JSReceiver::HasOwnProperty(obj, first)); 673 maybe = JSReceiver::HasOwnProperty(obj, first);
674 CHECK(maybe.has_value);
675 CHECK(!maybe.value);
664 676
665 // add first and then second 677 // add first and then second
666 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check(); 678 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
667 JSReceiver::SetProperty(obj, second, two, SLOPPY).Check(); 679 JSReceiver::SetProperty(obj, second, two, SLOPPY).Check();
668 CHECK(JSReceiver::HasOwnProperty(obj, first)); 680 maybe = JSReceiver::HasOwnProperty(obj, first);
669 CHECK(JSReceiver::HasOwnProperty(obj, second)); 681 CHECK(maybe.has_value);
682 CHECK(maybe.value);
683 maybe = JSReceiver::HasOwnProperty(obj, second);
684 CHECK(maybe.has_value);
685 CHECK(maybe.value);
670 686
671 // delete first and then second 687 // delete first and then second
672 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION).Check(); 688 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION).Check();
673 CHECK(JSReceiver::HasOwnProperty(obj, second)); 689 maybe = JSReceiver::HasOwnProperty(obj, second);
690 CHECK(maybe.has_value);
691 CHECK(maybe.value);
674 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION).Check(); 692 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION).Check();
675 CHECK(!JSReceiver::HasOwnProperty(obj, first)); 693 maybe = JSReceiver::HasOwnProperty(obj, first);
676 CHECK(!JSReceiver::HasOwnProperty(obj, second)); 694 CHECK(maybe.has_value);
695 CHECK(!maybe.value);
696 maybe = JSReceiver::HasOwnProperty(obj, second);
697 CHECK(maybe.has_value);
698 CHECK(!maybe.value);
677 699
678 // add first and then second 700 // add first and then second
679 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check(); 701 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
680 JSReceiver::SetProperty(obj, second, two, SLOPPY).Check(); 702 JSReceiver::SetProperty(obj, second, two, SLOPPY).Check();
681 CHECK(JSReceiver::HasOwnProperty(obj, first)); 703 maybe = JSReceiver::HasOwnProperty(obj, first);
682 CHECK(JSReceiver::HasOwnProperty(obj, second)); 704 CHECK(maybe.has_value);
705 CHECK(maybe.value);
706 maybe = JSReceiver::HasOwnProperty(obj, second);
707 CHECK(maybe.has_value);
708 CHECK(maybe.value);
683 709
684 // delete second and then first 710 // delete second and then first
685 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION).Check(); 711 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION).Check();
686 CHECK(JSReceiver::HasOwnProperty(obj, first)); 712 maybe = JSReceiver::HasOwnProperty(obj, first);
713 CHECK(maybe.has_value);
714 CHECK(maybe.value);
687 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION).Check(); 715 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION).Check();
688 CHECK(!JSReceiver::HasOwnProperty(obj, first)); 716 maybe = JSReceiver::HasOwnProperty(obj, first);
689 CHECK(!JSReceiver::HasOwnProperty(obj, second)); 717 CHECK(maybe.has_value);
718 CHECK(!maybe.value);
719 maybe = JSReceiver::HasOwnProperty(obj, second);
720 CHECK(maybe.has_value);
721 CHECK(!maybe.value);
690 722
691 // check string and internalized string match 723 // check string and internalized string match
692 const char* string1 = "fisk"; 724 const char* string1 = "fisk";
693 Handle<String> s1 = factory->NewStringFromAsciiChecked(string1); 725 Handle<String> s1 = factory->NewStringFromAsciiChecked(string1);
694 JSReceiver::SetProperty(obj, s1, one, SLOPPY).Check(); 726 JSReceiver::SetProperty(obj, s1, one, SLOPPY).Check();
695 Handle<String> s1_string = factory->InternalizeUtf8String(string1); 727 Handle<String> s1_string = factory->InternalizeUtf8String(string1);
696 CHECK(JSReceiver::HasOwnProperty(obj, s1_string)); 728 maybe = JSReceiver::HasOwnProperty(obj, s1_string);
729 CHECK(maybe.has_value);
730 CHECK(maybe.value);
697 731
698 // check internalized string and string match 732 // check internalized string and string match
699 const char* string2 = "fugl"; 733 const char* string2 = "fugl";
700 Handle<String> s2_string = factory->InternalizeUtf8String(string2); 734 Handle<String> s2_string = factory->InternalizeUtf8String(string2);
701 JSReceiver::SetProperty(obj, s2_string, one, SLOPPY).Check(); 735 JSReceiver::SetProperty(obj, s2_string, one, SLOPPY).Check();
702 Handle<String> s2 = factory->NewStringFromAsciiChecked(string2); 736 Handle<String> s2 = factory->NewStringFromAsciiChecked(string2);
703 CHECK(JSReceiver::HasOwnProperty(obj, s2)); 737 maybe = JSReceiver::HasOwnProperty(obj, s2);
738 CHECK(maybe.has_value);
739 CHECK(maybe.value);
704 } 740 }
705 741
706 742
707 TEST(JSObjectMaps) { 743 TEST(JSObjectMaps) {
708 CcTest::InitializeVM(); 744 CcTest::InitializeVM();
709 Isolate* isolate = CcTest::i_isolate(); 745 Isolate* isolate = CcTest::i_isolate();
710 Factory* factory = isolate->factory(); 746 Factory* factory = isolate->factory();
711 747
712 v8::HandleScope sc(CcTest::isolate()); 748 v8::HandleScope sc(CcTest::isolate());
713 Handle<String> name = factory->InternalizeUtf8String("theFunction"); 749 Handle<String> name = factory->InternalizeUtf8String("theFunction");
(...skipping 3694 matching lines...) Expand 10 before | Expand all | Expand 10 after
4408 #ifdef DEBUG 4444 #ifdef DEBUG
4409 TEST(PathTracer) { 4445 TEST(PathTracer) {
4410 CcTest::InitializeVM(); 4446 CcTest::InitializeVM();
4411 v8::HandleScope scope(CcTest::isolate()); 4447 v8::HandleScope scope(CcTest::isolate());
4412 4448
4413 v8::Local<v8::Value> result = CompileRun("'abc'"); 4449 v8::Local<v8::Value> result = CompileRun("'abc'");
4414 Handle<Object> o = v8::Utils::OpenHandle(*result); 4450 Handle<Object> o = v8::Utils::OpenHandle(*result);
4415 CcTest::i_isolate()->heap()->TracePathToObject(*o); 4451 CcTest::i_isolate()->heap()->TracePathToObject(*o);
4416 } 4452 }
4417 #endif // DEBUG 4453 #endif // DEBUG
OLDNEW
« src/objects-inl.h ('K') | « src/runtime.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698