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

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

Issue 23484020: Update handling of ambiguous name references (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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
« no previous file with comments | « runtime/vm/dart_entry.cc ('k') | runtime/vm/debugger.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/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 TEST_CASE(DartEntry) { 17 TEST_CASE(DartEntry) {
18 const char* kScriptChars = 18 const char* kScriptChars =
19 "class A {\n" 19 "class A {\n"
20 " static foo() { return 42; }\n" 20 " static foo() { return 42; }\n"
21 "}\n"; 21 "}\n";
22 String& url = String::Handle(String::New("dart-test:DartEntry")); 22 String& url = String::Handle(String::New("dart-test:DartEntry"));
23 String& source = String::Handle(String::New(kScriptChars)); 23 String& source = String::Handle(String::New(kScriptChars));
24 Script& script = Script::Handle(Script::New(url, 24 Script& script = Script::Handle(Script::New(url,
25 source, 25 source,
26 RawScript::kScriptTag)); 26 RawScript::kScriptTag));
27 Library& lib = Library::Handle(Library::CoreLibrary()); 27 Library& lib = Library::Handle(Library::CoreLibrary());
28 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); 28 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
29 EXPECT(ClassFinalizer::FinalizePendingClasses()); 29 EXPECT(ClassFinalizer::FinalizePendingClasses());
30 String& ambiguity_error_msg = String::Handle();
31 Class& cls = Class::Handle( 30 Class& cls = Class::Handle(
32 lib.LookupClass(String::Handle(Symbols::New("A")), &ambiguity_error_msg)); 31 lib.LookupClass(String::Handle(Symbols::New("A"))));
33 EXPECT(!cls.IsNull()); // No ambiguity error expected. 32 EXPECT(!cls.IsNull()); // No ambiguity error expected.
34 String& name = String::Handle(String::New("foo")); 33 String& name = String::Handle(String::New("foo"));
35 Function& function = Function::Handle(cls.LookupStaticFunction(name)); 34 Function& function = Function::Handle(cls.LookupStaticFunction(name));
36 EXPECT(!function.IsNull()); 35 EXPECT(!function.IsNull());
37 36
38 EXPECT(CompilerTest::TestCompileFunction(function)); 37 EXPECT(CompilerTest::TestCompileFunction(function));
39 EXPECT(function.HasCode()); 38 EXPECT(function.HasCode());
40 const Smi& retval = Smi::Handle(reinterpret_cast<RawSmi*>( 39 const Smi& retval = Smi::Handle(reinterpret_cast<RawSmi*>(
41 DartEntry::InvokeFunction(function, Object::empty_array()))); 40 DartEntry::InvokeFunction(function, Object::empty_array())));
42 EXPECT_EQ(Smi::New(42), retval.raw()); 41 EXPECT_EQ(Smi::New(42), retval.raw());
43 } 42 }
44 43
45 44
46 TEST_CASE(InvokeStatic_CompileError) { 45 TEST_CASE(InvokeStatic_CompileError) {
47 const char* kScriptChars = 46 const char* kScriptChars =
48 "class A {\n" 47 "class A {\n"
49 " static foo() { return ++++; }\n" 48 " static foo() { return ++++; }\n"
50 "}\n"; 49 "}\n";
51 String& url = String::Handle(String::New("dart-test:DartEntry")); 50 String& url = String::Handle(String::New("dart-test:DartEntry"));
52 String& source = String::Handle(String::New(kScriptChars)); 51 String& source = String::Handle(String::New(kScriptChars));
53 Script& script = Script::Handle(Script::New(url, 52 Script& script = Script::Handle(Script::New(url,
54 source, 53 source,
55 RawScript::kScriptTag)); 54 RawScript::kScriptTag));
56 Library& lib = Library::Handle(Library::CoreLibrary()); 55 Library& lib = Library::Handle(Library::CoreLibrary());
57 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); 56 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
58 EXPECT(ClassFinalizer::FinalizePendingClasses()); 57 EXPECT(ClassFinalizer::FinalizePendingClasses());
59 String& ambiguity_error_msg = String::Handle();
60 Class& cls = Class::Handle( 58 Class& cls = Class::Handle(
61 lib.LookupClass(String::Handle(Symbols::New("A")), &ambiguity_error_msg)); 59 lib.LookupClass(String::Handle(Symbols::New("A"))));
62 EXPECT(!cls.IsNull()); // No ambiguity error expected. 60 EXPECT(!cls.IsNull()); // No ambiguity error expected.
63 String& name = String::Handle(String::New("foo")); 61 String& name = String::Handle(String::New("foo"));
64 Function& function = Function::Handle(cls.LookupStaticFunction(name)); 62 Function& function = Function::Handle(cls.LookupStaticFunction(name));
65 EXPECT(!function.IsNull()); 63 EXPECT(!function.IsNull());
66 GrowableArray<const Object*> arguments; 64 GrowableArray<const Object*> arguments;
67 const Object& retval = Object::Handle( 65 const Object& retval = Object::Handle(
68 DartEntry::InvokeFunction(function, Object::empty_array())); 66 DartEntry::InvokeFunction(function, Object::empty_array()));
69 EXPECT(retval.IsError()); 67 EXPECT(retval.IsError());
70 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); 68 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString());
71 } 69 }
72 70
73 71
74 TEST_CASE(InvokeDynamic_CompileError) { 72 TEST_CASE(InvokeDynamic_CompileError) {
75 const char* kScriptChars = 73 const char* kScriptChars =
76 "class A {\n" 74 "class A {\n"
77 " foo() { return ++++; }\n" 75 " foo() { return ++++; }\n"
78 "}\n"; 76 "}\n";
79 String& url = String::Handle(String::New("dart-test:DartEntry")); 77 String& url = String::Handle(String::New("dart-test:DartEntry"));
80 String& source = String::Handle(String::New(kScriptChars)); 78 String& source = String::Handle(String::New(kScriptChars));
81 Script& script = Script::Handle(Script::New(url, 79 Script& script = Script::Handle(Script::New(url,
82 source, 80 source,
83 RawScript::kScriptTag)); 81 RawScript::kScriptTag));
84 Library& lib = Library::Handle(Library::CoreLibrary()); 82 Library& lib = Library::Handle(Library::CoreLibrary());
85 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); 83 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
86 EXPECT(ClassFinalizer::FinalizePendingClasses()); 84 EXPECT(ClassFinalizer::FinalizePendingClasses());
87 String& ambiguity_error_msg = String::Handle();
88 Class& cls = Class::Handle( 85 Class& cls = Class::Handle(
89 lib.LookupClass(String::Handle(Symbols::New("A")), &ambiguity_error_msg)); 86 lib.LookupClass(String::Handle(Symbols::New("A"))));
90 EXPECT(!cls.IsNull()); // No ambiguity error expected. 87 EXPECT(!cls.IsNull()); // No ambiguity error expected.
91 88
92 // Invoke the constructor. 89 // Invoke the constructor.
93 const Instance& instance = Instance::Handle(Instance::New(cls)); 90 const Instance& instance = Instance::Handle(Instance::New(cls));
94 const Array& constructor_arguments = Array::Handle(Array::New(2)); 91 const Array& constructor_arguments = Array::Handle(Array::New(2));
95 constructor_arguments.SetAt(0, instance); 92 constructor_arguments.SetAt(0, instance);
96 constructor_arguments.SetAt( 93 constructor_arguments.SetAt(
97 1, Smi::Handle(Smi::New(Function::kCtorPhaseAll))); 94 1, Smi::Handle(Smi::New(Function::kCtorPhaseAll)));
98 String& constructor_name = String::Handle(Symbols::New("A.")); 95 String& constructor_name = String::Handle(Symbols::New("A."));
99 Function& constructor = 96 Function& constructor =
100 Function::Handle(cls.LookupConstructor(constructor_name)); 97 Function::Handle(cls.LookupConstructor(constructor_name));
101 ASSERT(!constructor.IsNull()); 98 ASSERT(!constructor.IsNull());
102 DartEntry::InvokeFunction(constructor, constructor_arguments); 99 DartEntry::InvokeFunction(constructor, constructor_arguments);
103 100
104 // Call foo. 101 // Call foo.
105 String& name = String::Handle(String::New("foo")); 102 String& name = String::Handle(String::New("foo"));
106 Function& function = Function::Handle(cls.LookupDynamicFunction(name)); 103 Function& function = Function::Handle(cls.LookupDynamicFunction(name));
107 EXPECT(!function.IsNull()); 104 EXPECT(!function.IsNull());
108 const Array& args = Array::Handle(Array::New(1)); 105 const Array& args = Array::Handle(Array::New(1));
109 args.SetAt(0, instance); 106 args.SetAt(0, instance);
110 const Object& retval = Object::Handle(DartEntry::InvokeFunction(function, 107 const Object& retval = Object::Handle(DartEntry::InvokeFunction(function,
111 args)); 108 args));
112 EXPECT(retval.IsError()); 109 EXPECT(retval.IsError());
113 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); 110 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString());
114 } 111 }
115 112
116 } // namespace dart 113 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_entry.cc ('k') | runtime/vm/debugger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698