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

Side by Side Diff: runtime/vm/class_finalizer_test.cc

Issue 1393373003: Remove isolate argument from handle allocation: Part I (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Cleanups Created 5 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/code_generator.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/class_finalizer.h" 6 #include "vm/class_finalizer.h"
7 #include "vm/symbols.h" 7 #include "vm/symbols.h"
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 9
10 namespace dart { 10 namespace dart {
11 11
12 12
13 static RawClass* CreateTestClass(const char* name) { 13 static RawClass* CreateTestClass(const char* name) {
14 const String& class_name = String::Handle(Symbols::New(name)); 14 const String& class_name = String::Handle(Symbols::New(name));
15 const Script& script = Script::Handle(); 15 const Script& script = Script::Handle();
16 const Class& cls = 16 const Class& cls =
17 Class::Handle(Class::New(class_name, script, Scanner::kNoSourcePos)); 17 Class::Handle(Class::New(class_name, script, Scanner::kNoSourcePos));
18 cls.set_interfaces(Object::empty_array()); 18 cls.set_interfaces(Object::empty_array());
19 cls.SetFunctions(Object::empty_array()); 19 cls.SetFunctions(Object::empty_array());
20 cls.SetFields(Object::empty_array()); 20 cls.SetFields(Object::empty_array());
21 return cls.raw(); 21 return cls.raw();
22 } 22 }
23 23
24 24
25 TEST_CASE(ClassFinalizer) { 25 TEST_CASE(ClassFinalizer) {
26 Isolate* isolate = Isolate::Current(); 26 Zone* zone = thread->zone();
27 Isolate* isolate = thread->isolate();
27 ObjectStore* object_store = isolate->object_store(); 28 ObjectStore* object_store = isolate->object_store();
28 const GrowableObjectArray& pending_classes = 29 const GrowableObjectArray& pending_classes =
29 GrowableObjectArray::Handle(isolate, object_store->pending_classes()); 30 GrowableObjectArray::Handle(zone, object_store->pending_classes());
30 GrowableArray<const Class*> classes_1; 31 GrowableArray<const Class*> classes_1;
31 classes_1.Add(&Class::Handle(CreateTestClass("BMW"))); 32 classes_1.Add(&Class::Handle(CreateTestClass("BMW")));
32 pending_classes.Add(*classes_1[0]); 33 pending_classes.Add(*classes_1[0]);
33 classes_1.Add(&Class::Handle(CreateTestClass("Porsche"))); 34 classes_1.Add(&Class::Handle(CreateTestClass("Porsche")));
34 pending_classes.Add(*classes_1[1]); 35 pending_classes.Add(*classes_1[1]);
35 36
36 GrowableArray<const Class*> classes_2; 37 GrowableArray<const Class*> classes_2;
37 classes_2.Add(&Class::ZoneHandle(CreateTestClass("Ferrari"))); 38 classes_2.Add(&Class::ZoneHandle(CreateTestClass("Ferrari")));
38 pending_classes.Add(*classes_2[0]); 39 pending_classes.Add(*classes_2[0]);
39 classes_2.Add(&Class::ZoneHandle(CreateTestClass("Fiat"))); 40 classes_2.Add(&Class::ZoneHandle(CreateTestClass("Fiat")));
40 pending_classes.Add(*classes_2[1]); 41 pending_classes.Add(*classes_2[1]);
41 classes_2.Add(&Class::ZoneHandle(CreateTestClass("Alfa"))); 42 classes_2.Add(&Class::ZoneHandle(CreateTestClass("Alfa")));
42 pending_classes.Add(*classes_2[2]); 43 pending_classes.Add(*classes_2[2]);
43 EXPECT(ClassFinalizer::ProcessPendingClasses()); 44 EXPECT(ClassFinalizer::ProcessPendingClasses());
44 for (int i = 0; i < classes_1.length(); i++) { 45 for (int i = 0; i < classes_1.length(); i++) {
45 EXPECT(classes_1[i]->is_type_finalized()); 46 EXPECT(classes_1[i]->is_type_finalized());
46 } 47 }
47 for (int i = 0; i < classes_2.length(); i++) { 48 for (int i = 0; i < classes_2.length(); i++) {
48 EXPECT(classes_2[i]->is_type_finalized()); 49 EXPECT(classes_2[i]->is_type_finalized());
49 } 50 }
50 EXPECT(ClassFinalizer::AllClassesFinalized()); 51 EXPECT(ClassFinalizer::AllClassesFinalized());
51 EXPECT(ClassFinalizer::ProcessPendingClasses()); 52 EXPECT(ClassFinalizer::ProcessPendingClasses());
52 } 53 }
53 54
54 55
55 TEST_CASE(ClassFinalize_Cycles) { 56 TEST_CASE(ClassFinalize_Cycles) {
56 Isolate* isolate = Isolate::Current(); 57 Zone* zone = thread->zone();
58 Isolate* isolate = thread->isolate();
57 ObjectStore* object_store = isolate->object_store(); 59 ObjectStore* object_store = isolate->object_store();
58 const GrowableObjectArray& pending_classes = 60 const GrowableObjectArray& pending_classes =
59 GrowableObjectArray::Handle(isolate, object_store->pending_classes()); 61 GrowableObjectArray::Handle(zone, object_store->pending_classes());
60 GrowableArray<const Class*> classes; 62 GrowableArray<const Class*> classes;
61 classes.Add(&Class::Handle(CreateTestClass("Jungfrau"))); 63 classes.Add(&Class::Handle(CreateTestClass("Jungfrau")));
62 pending_classes.Add(*classes[0]); 64 pending_classes.Add(*classes[0]);
63 classes.Add(&Class::Handle(CreateTestClass("Eiger"))); 65 classes.Add(&Class::Handle(CreateTestClass("Eiger")));
64 pending_classes.Add(*classes[1]); 66 pending_classes.Add(*classes[1]);
65 // Create a cycle. 67 // Create a cycle.
66 classes[0]->set_super_type( 68 classes[0]->set_super_type(
67 Type::Handle(Type::NewNonParameterizedType(*classes[1]))); 69 Type::Handle(Type::NewNonParameterizedType(*classes[1])));
68 classes[1]->set_super_type( 70 classes[1]->set_super_type(
69 Type::Handle(Type::NewNonParameterizedType(*classes[0]))); 71 Type::Handle(Type::NewNonParameterizedType(*classes[0])));
70 EXPECT(!ClassFinalizer::ProcessPendingClasses()); 72 EXPECT(!ClassFinalizer::ProcessPendingClasses());
71 } 73 }
72 74
73 75
74 static RawLibrary* NewLib(const char* url_chars) { 76 static RawLibrary* NewLib(const char* url_chars) {
75 String& url = String::ZoneHandle(Symbols::New(url_chars)); 77 String& url = String::ZoneHandle(Symbols::New(url_chars));
76 return Library::New(url); 78 return Library::New(url);
77 } 79 }
78 80
79 81
80 TEST_CASE(ClassFinalize_Resolve) { 82 TEST_CASE(ClassFinalize_Resolve) {
81 Isolate* isolate = Isolate::Current(); 83 Zone* zone = thread->zone();
84 Isolate* isolate = thread->isolate();
82 ObjectStore* object_store = isolate->object_store(); 85 ObjectStore* object_store = isolate->object_store();
83 const GrowableObjectArray& pending_classes = 86 const GrowableObjectArray& pending_classes =
84 GrowableObjectArray::Handle(isolate, object_store->pending_classes()); 87 GrowableObjectArray::Handle(zone, object_store->pending_classes());
85 Class& rhb = Class::Handle(CreateTestClass("RhB")); 88 Class& rhb = Class::Handle(CreateTestClass("RhB"));
86 pending_classes.Add(rhb); 89 pending_classes.Add(rhb);
87 Class& sbb = Class::Handle(CreateTestClass("SBB")); 90 Class& sbb = Class::Handle(CreateTestClass("SBB"));
88 pending_classes.Add(sbb); 91 pending_classes.Add(sbb);
89 Library& lib = Library::Handle(NewLib("TestLib")); 92 Library& lib = Library::Handle(NewLib("TestLib"));
90 lib.AddClass(rhb); 93 lib.AddClass(rhb);
91 lib.AddClass(sbb); 94 lib.AddClass(sbb);
92 const String& superclass_name = String::Handle(sbb.Name()); 95 const String& superclass_name = String::Handle(sbb.Name());
93 const UnresolvedClass& unresolved = UnresolvedClass::Handle( 96 const UnresolvedClass& unresolved = UnresolvedClass::Handle(
94 UnresolvedClass::New(LibraryPrefix::Handle(), 97 UnresolvedClass::New(LibraryPrefix::Handle(),
95 superclass_name, 98 superclass_name,
96 Scanner::kNoSourcePos)); 99 Scanner::kNoSourcePos));
97 const TypeArguments& type_arguments = TypeArguments::Handle(); 100 const TypeArguments& type_arguments = TypeArguments::Handle();
98 rhb.set_super_type(Type::Handle( 101 rhb.set_super_type(Type::Handle(
99 Type::New(Object::Handle(unresolved.raw()), 102 Type::New(Object::Handle(unresolved.raw()),
100 type_arguments, 103 type_arguments,
101 Scanner::kNoSourcePos))); 104 Scanner::kNoSourcePos)));
102 EXPECT(ClassFinalizer::ProcessPendingClasses()); 105 EXPECT(ClassFinalizer::ProcessPendingClasses());
103 } 106 }
104 107
105 } // namespace dart 108 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/code_generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698