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

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

Issue 1955453002: - Use a map to lookup libraries by URL. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix precompiler handling. Created 4 years, 7 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
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/assembler.h" 6 #include "vm/assembler.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 #include "vm/resolver.h" 11 #include "vm/resolver.h"
12 #include "vm/symbols.h" 12 #include "vm/symbols.h"
13 #include "vm/unit_test.h" 13 #include "vm/unit_test.h"
14 14
15 namespace dart { 15 namespace dart {
16 16
17 // Setup function for invocation. 17 // Setup function for invocation.
18 static void SetupFunction(const char* test_library_name, 18 static void SetupFunction(const char* test_library_name,
19 const char* test_class_name, 19 const char* test_class_name,
20 const char* test_static_function_name, 20 const char* test_static_function_name,
21 bool is_static) { 21 bool is_static) {
22 Thread* thread = Thread::Current();
23 Zone* zone = thread->zone();
24
22 // Setup a dart class and function. 25 // Setup a dart class and function.
23 char script_chars[1024]; 26 char script_chars[1024];
24 OS::SNPrint(script_chars, 27 OS::SNPrint(script_chars,
25 sizeof(script_chars), 28 sizeof(script_chars),
26 "class Base {\n" 29 "class Base {\n"
27 " dynCall() { return 3; }\n" 30 " dynCall() { return 3; }\n"
28 " static statCall() { return 4; }\n" 31 " static statCall() { return 4; }\n"
29 "\n" 32 "\n"
30 "}\n" 33 "}\n"
31 "class %s extends Base {\n" 34 "class %s extends Base {\n"
32 " %s %s(String s, int i) { return i; }\n" 35 " %s %s(String s, int i) { return i; }\n"
33 "}\n", 36 "}\n",
34 test_class_name, 37 test_class_name,
35 is_static ? "static" : "", 38 is_static ? "static" : "",
36 test_static_function_name); 39 test_static_function_name);
37 40
38 String& url = String::Handle(is_static ? 41 String& url = String::Handle(zone,
39 String::New("dart-test:DartStaticResolve") : 42 is_static ?
40 String::New("dart-test:DartDynamicResolve")); 43 String::New("dart-test:DartStaticResolve") :
41 String& source = String::Handle(String::New(script_chars)); 44 String::New("dart-test:DartDynamicResolve"));
42 Script& script = Script::Handle(Script::New(url, 45 String& source = String::Handle(zone, String::New(script_chars));
43 source, 46 Script& script = Script::Handle(zone,
44 RawScript::kScriptTag)); 47 Script::New(url, source, RawScript::kScriptTag));
45 const String& lib_name = String::Handle(String::New(test_library_name)); 48 const String& lib_name = String::Handle(zone, String::New(test_library_name));
46 Library& lib = Library::Handle(Library::New(lib_name)); 49 Library& lib = Library::Handle(zone, Library::New(lib_name));
47 lib.Register(); 50 lib.Register(thread);
48 EXPECT(CompilerTest::TestCompileScript(lib, script)); 51 EXPECT(CompilerTest::TestCompileScript(lib, script));
49 EXPECT(ClassFinalizer::ProcessPendingClasses()); 52 EXPECT(ClassFinalizer::ProcessPendingClasses());
50 } 53 }
51 54
52 55
53 // Setup a static function for invocation. 56 // Setup a static function for invocation.
54 static void SetupStaticFunction(const char* test_library_name, 57 static void SetupStaticFunction(const char* test_library_name,
55 const char* test_class_name, 58 const char* test_class_name,
56 const char* test_static_function_name) { 59 const char* test_static_function_name) {
57 // Setup a static dart class and function. 60 // Setup a static dart class and function.
(...skipping 22 matching lines...) Expand all
80 const char* test_static_function_name = "static_foo"; 83 const char* test_static_function_name = "static_foo";
81 const int kTestValue = 42; 84 const int kTestValue = 42;
82 85
83 // Setup a static function which can be invoked. 86 // Setup a static function which can be invoked.
84 SetupStaticFunction(test_library_name, 87 SetupStaticFunction(test_library_name,
85 test_class_name, 88 test_class_name,
86 test_static_function_name); 89 test_static_function_name);
87 90
88 const String& library_name = String::Handle(String::New(test_library_name)); 91 const String& library_name = String::Handle(String::New(test_library_name));
89 const Library& library = 92 const Library& library =
90 Library::Handle(Library::LookupLibrary(library_name)); 93 Library::Handle(Library::LookupLibrary(thread, library_name));
91 const String& class_name = String::Handle(String::New(test_class_name)); 94 const String& class_name = String::Handle(String::New(test_class_name));
92 const String& static_function_name = 95 const String& static_function_name =
93 String::Handle(String::New(test_static_function_name)); 96 String::Handle(String::New(test_static_function_name));
94 97
95 // Now try to resolve and invoke the static function in this class. 98 // Now try to resolve and invoke the static function in this class.
96 { 99 {
97 const int kNumArguments = 2; 100 const int kNumArguments = 2;
98 const Function& function = Function::Handle( 101 const Function& function = Function::Handle(
99 Resolver::ResolveStatic(library, 102 Resolver::ResolveStatic(library,
100 class_name, 103 class_name,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 const int kTestValue = 42; 151 const int kTestValue = 42;
149 152
150 // Setup a function which can be invoked. 153 // Setup a function which can be invoked.
151 SetupInstanceFunction(test_library_name, 154 SetupInstanceFunction(test_library_name,
152 test_class_name, 155 test_class_name,
153 test_function_name); 156 test_function_name);
154 157
155 // Now create an instance object of the class and try to 158 // Now create an instance object of the class and try to
156 // resolve a function in it. 159 // resolve a function in it.
157 const String& lib_name = String::Handle(String::New(test_library_name)); 160 const String& lib_name = String::Handle(String::New(test_library_name));
158 const Library& lib = Library::Handle(Library::LookupLibrary(lib_name)); 161 const Library& lib = Library::Handle(Library::LookupLibrary(thread,
162 lib_name));
159 ASSERT(!lib.IsNull()); 163 ASSERT(!lib.IsNull());
160 const Class& cls = Class::Handle(lib.LookupClass( 164 const Class& cls = Class::Handle(lib.LookupClass(
161 String::Handle(Symbols::New(thread, test_class_name)))); 165 String::Handle(Symbols::New(thread, test_class_name))));
162 EXPECT(!cls.IsNull()); // No ambiguity error expected. 166 EXPECT(!cls.IsNull()); // No ambiguity error expected.
163 167
164 Instance& receiver = Instance::Handle(Instance::New(cls)); 168 Instance& receiver = Instance::Handle(Instance::New(cls));
165 const String& function_name = String::Handle(String::New(test_function_name)); 169 const String& function_name = String::Handle(String::New(test_function_name));
166 170
167 // Now try to resolve and invoke the instance function in this class. 171 // Now try to resolve and invoke the instance function in this class.
168 { 172 {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 String::Handle(String::New("dynCall")); 210 String::Handle(String::New("dynCall"));
207 const Function& super_function = Function::Handle( 211 const Function& super_function = Function::Handle(
208 Resolver::ResolveDynamic(receiver, 212 Resolver::ResolveDynamic(receiver,
209 super_function_name, 213 super_function_name,
210 args_desc)); 214 args_desc));
211 EXPECT(!super_function.IsNull()); 215 EXPECT(!super_function.IsNull());
212 } 216 }
213 } 217 }
214 218
215 } // namespace dart 219 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698