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

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

Issue 958053003: Removed funky Maybe constructor and made fields private. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
33 #include "src/compilation-cache.h" 33 #include "src/compilation-cache.h"
34 #include "src/execution.h" 34 #include "src/execution.h"
35 #include "src/factory.h" 35 #include "src/factory.h"
36 #include "src/global-handles.h" 36 #include "src/global-handles.h"
37 #include "src/ic/ic.h" 37 #include "src/ic/ic.h"
38 #include "src/macro-assembler.h" 38 #include "src/macro-assembler.h"
39 #include "src/snapshot.h" 39 #include "src/snapshot.h"
40 #include "test/cctest/cctest.h" 40 #include "test/cctest/cctest.h"
41 41
42 using namespace v8::internal; 42 using namespace v8::internal;
43 using v8::Just;
43 44
44 static void CheckMap(Map* map, int type, int instance_size) { 45 static void CheckMap(Map* map, int type, int instance_size) {
45 CHECK(map->IsHeapObject()); 46 CHECK(map->IsHeapObject());
46 #ifdef DEBUG 47 #ifdef DEBUG
47 CHECK(CcTest::heap()->Contains(map)); 48 CHECK(CcTest::heap()->Contains(map));
48 #endif 49 #endif
49 CHECK_EQ(CcTest::heap()->meta_map(), map->map()); 50 CHECK_EQ(CcTest::heap()->meta_map(), map->map());
50 CHECK_EQ(type, map->instance_type()); 51 CHECK_EQ(type, map->instance_type());
51 CHECK_EQ(instance_size, map->instance_size()); 52 CHECK_EQ(instance_size, map->instance_size());
52 } 53 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // nan oddball checks 185 // nan oddball checks
185 CHECK(factory->nan_value()->IsNumber()); 186 CHECK(factory->nan_value()->IsNumber());
186 CHECK(std::isnan(factory->nan_value()->Number())); 187 CHECK(std::isnan(factory->nan_value()->Number()));
187 188
188 Handle<String> s = factory->NewStringFromStaticChars("fisk hest "); 189 Handle<String> s = factory->NewStringFromStaticChars("fisk hest ");
189 CHECK(s->IsString()); 190 CHECK(s->IsString());
190 CHECK_EQ(10, s->length()); 191 CHECK_EQ(10, s->length());
191 192
192 Handle<String> object_string = Handle<String>::cast(factory->Object_string()); 193 Handle<String> object_string = Handle<String>::cast(factory->Object_string());
193 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object()); 194 Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object());
194 v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, object_string); 195 CHECK(Just(true) == JSReceiver::HasOwnProperty(global, object_string));
195 CHECK(maybe.has_value);
196 CHECK(maybe.value);
197 196
198 // Check ToString for oddballs 197 // Check ToString for oddballs
199 CheckOddball(isolate, heap->true_value(), "true"); 198 CheckOddball(isolate, heap->true_value(), "true");
200 CheckOddball(isolate, heap->false_value(), "false"); 199 CheckOddball(isolate, heap->false_value(), "false");
201 CheckOddball(isolate, heap->null_value(), "null"); 200 CheckOddball(isolate, heap->null_value(), "null");
202 CheckOddball(isolate, heap->undefined_value(), "undefined"); 201 CheckOddball(isolate, heap->undefined_value(), "undefined");
203 202
204 // Check ToString for Smis 203 // Check ToString for Smis
205 CheckSmi(isolate, 0, "0"); 204 CheckSmi(isolate, 0, "0");
206 CheckSmi(isolate, 42, "42"); 205 CheckSmi(isolate, 42, "42");
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 252
254 CHECK_EQ(Smi::FromInt(23), 253 CHECK_EQ(Smi::FromInt(23),
255 *Object::GetProperty(obj, prop_name).ToHandleChecked()); 254 *Object::GetProperty(obj, prop_name).ToHandleChecked());
256 CHECK_EQ(Smi::FromInt(24), 255 CHECK_EQ(Smi::FromInt(24),
257 *Object::GetProperty(obj, prop_namex).ToHandleChecked()); 256 *Object::GetProperty(obj, prop_namex).ToHandleChecked());
258 } 257 }
259 258
260 heap->CollectGarbage(NEW_SPACE); 259 heap->CollectGarbage(NEW_SPACE);
261 260
262 // Function should be alive. 261 // Function should be alive.
263 v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, name); 262 CHECK(Just(true) == JSReceiver::HasOwnProperty(global, name));
264 CHECK(maybe.has_value);
265 CHECK(maybe.value);
266 // Check function is retained. 263 // Check function is retained.
267 Handle<Object> func_value = 264 Handle<Object> func_value =
268 Object::GetProperty(global, name).ToHandleChecked(); 265 Object::GetProperty(global, name).ToHandleChecked();
269 CHECK(func_value->IsJSFunction()); 266 CHECK(func_value->IsJSFunction());
270 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); 267 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
271 268
272 { 269 {
273 HandleScope inner_scope(isolate); 270 HandleScope inner_scope(isolate);
274 // Allocate another object, make it reachable from global. 271 // Allocate another object, make it reachable from global.
275 Handle<JSObject> obj = factory->NewJSObject(function); 272 Handle<JSObject> obj = factory->NewJSObject(function);
276 JSReceiver::SetProperty(global, obj_name, obj, SLOPPY).Check(); 273 JSReceiver::SetProperty(global, obj_name, obj, SLOPPY).Check();
277 JSReceiver::SetProperty(obj, prop_name, twenty_three, SLOPPY).Check(); 274 JSReceiver::SetProperty(obj, prop_name, twenty_three, SLOPPY).Check();
278 } 275 }
279 276
280 // After gc, it should survive. 277 // After gc, it should survive.
281 heap->CollectGarbage(NEW_SPACE); 278 heap->CollectGarbage(NEW_SPACE);
282 279
283 maybe = JSReceiver::HasOwnProperty(global, obj_name); 280 CHECK(Just(true) == JSReceiver::HasOwnProperty(global, obj_name));
284 CHECK(maybe.has_value);
285 CHECK(maybe.value);
286 Handle<Object> obj = 281 Handle<Object> obj =
287 Object::GetProperty(global, obj_name).ToHandleChecked(); 282 Object::GetProperty(global, obj_name).ToHandleChecked();
288 CHECK(obj->IsJSObject()); 283 CHECK(obj->IsJSObject());
289 CHECK_EQ(Smi::FromInt(23), 284 CHECK_EQ(Smi::FromInt(23),
290 *Object::GetProperty(obj, prop_name).ToHandleChecked()); 285 *Object::GetProperty(obj, prop_name).ToHandleChecked());
291 } 286 }
292 287
293 288
294 static void VerifyStringAllocation(Isolate* isolate, const char* string) { 289 static void VerifyStringAllocation(Isolate* isolate, const char* string) {
295 HandleScope scope(isolate); 290 HandleScope scope(isolate);
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 CcTest::i_isolate()->global_object(), object_string).ToHandleChecked(); 627 CcTest::i_isolate()->global_object(), object_string).ToHandleChecked();
633 Handle<JSFunction> constructor = Handle<JSFunction>::cast(object); 628 Handle<JSFunction> constructor = Handle<JSFunction>::cast(object);
634 Handle<JSObject> obj = factory->NewJSObject(constructor); 629 Handle<JSObject> obj = factory->NewJSObject(constructor);
635 Handle<String> first = factory->InternalizeUtf8String("first"); 630 Handle<String> first = factory->InternalizeUtf8String("first");
636 Handle<String> second = factory->InternalizeUtf8String("second"); 631 Handle<String> second = factory->InternalizeUtf8String("second");
637 632
638 Handle<Smi> one(Smi::FromInt(1), isolate); 633 Handle<Smi> one(Smi::FromInt(1), isolate);
639 Handle<Smi> two(Smi::FromInt(2), isolate); 634 Handle<Smi> two(Smi::FromInt(2), isolate);
640 635
641 // check for empty 636 // check for empty
642 v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(obj, first); 637 CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, first));
643 CHECK(maybe.has_value);
644 CHECK(!maybe.value);
645 638
646 // add first 639 // add first
647 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check(); 640 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
648 maybe = JSReceiver::HasOwnProperty(obj, first); 641 CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, first));
649 CHECK(maybe.has_value);
650 CHECK(maybe.value);
651 642
652 // delete first 643 // delete first
653 JSReceiver::DeleteProperty(obj, first, SLOPPY).Check(); 644 JSReceiver::DeleteProperty(obj, first, SLOPPY).Check();
654 maybe = JSReceiver::HasOwnProperty(obj, first); 645 CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, first));
655 CHECK(maybe.has_value);
656 CHECK(!maybe.value);
657 646
658 // add first and then second 647 // add first and then second
659 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check(); 648 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
660 JSReceiver::SetProperty(obj, second, two, SLOPPY).Check(); 649 JSReceiver::SetProperty(obj, second, two, SLOPPY).Check();
661 maybe = JSReceiver::HasOwnProperty(obj, first); 650 CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, first));
662 CHECK(maybe.has_value); 651 CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, second));
663 CHECK(maybe.value);
664 maybe = JSReceiver::HasOwnProperty(obj, second);
665 CHECK(maybe.has_value);
666 CHECK(maybe.value);
667 652
668 // delete first and then second 653 // delete first and then second
669 JSReceiver::DeleteProperty(obj, first, SLOPPY).Check(); 654 JSReceiver::DeleteProperty(obj, first, SLOPPY).Check();
670 maybe = JSReceiver::HasOwnProperty(obj, second); 655 CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, second));
671 CHECK(maybe.has_value);
672 CHECK(maybe.value);
673 JSReceiver::DeleteProperty(obj, second, SLOPPY).Check(); 656 JSReceiver::DeleteProperty(obj, second, SLOPPY).Check();
674 maybe = JSReceiver::HasOwnProperty(obj, first); 657 CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, first));
675 CHECK(maybe.has_value); 658 CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, second));
676 CHECK(!maybe.value);
677 maybe = JSReceiver::HasOwnProperty(obj, second);
678 CHECK(maybe.has_value);
679 CHECK(!maybe.value);
680 659
681 // add first and then second 660 // add first and then second
682 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check(); 661 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
683 JSReceiver::SetProperty(obj, second, two, SLOPPY).Check(); 662 JSReceiver::SetProperty(obj, second, two, SLOPPY).Check();
684 maybe = JSReceiver::HasOwnProperty(obj, first); 663 CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, first));
685 CHECK(maybe.has_value); 664 CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, second));
686 CHECK(maybe.value);
687 maybe = JSReceiver::HasOwnProperty(obj, second);
688 CHECK(maybe.has_value);
689 CHECK(maybe.value);
690 665
691 // delete second and then first 666 // delete second and then first
692 JSReceiver::DeleteProperty(obj, second, SLOPPY).Check(); 667 JSReceiver::DeleteProperty(obj, second, SLOPPY).Check();
693 maybe = JSReceiver::HasOwnProperty(obj, first); 668 CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, first));
694 CHECK(maybe.has_value);
695 CHECK(maybe.value);
696 JSReceiver::DeleteProperty(obj, first, SLOPPY).Check(); 669 JSReceiver::DeleteProperty(obj, first, SLOPPY).Check();
697 maybe = JSReceiver::HasOwnProperty(obj, first); 670 CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, first));
698 CHECK(maybe.has_value); 671 CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, second));
699 CHECK(!maybe.value);
700 maybe = JSReceiver::HasOwnProperty(obj, second);
701 CHECK(maybe.has_value);
702 CHECK(!maybe.value);
703 672
704 // check string and internalized string match 673 // check string and internalized string match
705 const char* string1 = "fisk"; 674 const char* string1 = "fisk";
706 Handle<String> s1 = factory->NewStringFromAsciiChecked(string1); 675 Handle<String> s1 = factory->NewStringFromAsciiChecked(string1);
707 JSReceiver::SetProperty(obj, s1, one, SLOPPY).Check(); 676 JSReceiver::SetProperty(obj, s1, one, SLOPPY).Check();
708 Handle<String> s1_string = factory->InternalizeUtf8String(string1); 677 Handle<String> s1_string = factory->InternalizeUtf8String(string1);
709 maybe = JSReceiver::HasOwnProperty(obj, s1_string); 678 CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, s1_string));
710 CHECK(maybe.has_value);
711 CHECK(maybe.value);
712 679
713 // check internalized string and string match 680 // check internalized string and string match
714 const char* string2 = "fugl"; 681 const char* string2 = "fugl";
715 Handle<String> s2_string = factory->InternalizeUtf8String(string2); 682 Handle<String> s2_string = factory->InternalizeUtf8String(string2);
716 JSReceiver::SetProperty(obj, s2_string, one, SLOPPY).Check(); 683 JSReceiver::SetProperty(obj, s2_string, one, SLOPPY).Check();
717 Handle<String> s2 = factory->NewStringFromAsciiChecked(string2); 684 Handle<String> s2 = factory->NewStringFromAsciiChecked(string2);
718 maybe = JSReceiver::HasOwnProperty(obj, s2); 685 CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, s2));
719 CHECK(maybe.has_value);
720 CHECK(maybe.value);
721 } 686 }
722 687
723 688
724 TEST(JSObjectMaps) { 689 TEST(JSObjectMaps) {
725 CcTest::InitializeVM(); 690 CcTest::InitializeVM();
726 Isolate* isolate = CcTest::i_isolate(); 691 Isolate* isolate = CcTest::i_isolate();
727 Factory* factory = isolate->factory(); 692 Factory* factory = isolate->factory();
728 693
729 v8::HandleScope sc(CcTest::isolate()); 694 v8::HandleScope sc(CcTest::isolate());
730 Handle<String> name = factory->InternalizeUtf8String("theFunction"); 695 Handle<String> name = factory->InternalizeUtf8String("theFunction");
(...skipping 4389 matching lines...) Expand 10 before | Expand all | Expand 10 after
5120 #ifdef DEBUG 5085 #ifdef DEBUG
5121 TEST(PathTracer) { 5086 TEST(PathTracer) {
5122 CcTest::InitializeVM(); 5087 CcTest::InitializeVM();
5123 v8::HandleScope scope(CcTest::isolate()); 5088 v8::HandleScope scope(CcTest::isolate());
5124 5089
5125 v8::Local<v8::Value> result = CompileRun("'abc'"); 5090 v8::Local<v8::Value> result = CompileRun("'abc'");
5126 Handle<Object> o = v8::Utils::OpenHandle(*result); 5091 Handle<Object> o = v8::Utils::OpenHandle(*result);
5127 CcTest::i_isolate()->heap()->TracePathToObject(*o); 5092 CcTest::i_isolate()->heap()->TracePathToObject(*o);
5128 } 5093 }
5129 #endif // DEBUG 5094 #endif // DEBUG
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698