OLD | NEW |
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/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 "}\n"; | 23 "}\n"; |
24 String& url = String::Handle(String::New("dart-test:DartEntry")); | 24 String& url = String::Handle(String::New("dart-test:DartEntry")); |
25 String& source = String::Handle(String::New(kScriptChars)); | 25 String& source = String::Handle(String::New(kScriptChars)); |
26 Script& script = Script::Handle(Script::New(url, | 26 Script& script = Script::Handle(Script::New(url, |
27 source, | 27 source, |
28 RawScript::kScriptTag)); | 28 RawScript::kScriptTag)); |
29 Library& lib = Library::Handle(Library::CoreLibrary()); | 29 Library& lib = Library::Handle(Library::CoreLibrary()); |
30 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); | 30 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); |
31 EXPECT(ClassFinalizer::ProcessPendingClasses()); | 31 EXPECT(ClassFinalizer::ProcessPendingClasses()); |
32 Class& cls = Class::Handle( | 32 Class& cls = Class::Handle( |
33 lib.LookupClass(String::Handle(Symbols::New("A")))); | 33 lib.LookupClass(String::Handle(Symbols::New(thread, "A")))); |
34 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 34 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
35 String& name = String::Handle(String::New("foo")); | 35 String& name = String::Handle(String::New("foo")); |
36 Function& function = Function::Handle(cls.LookupStaticFunction(name)); | 36 Function& function = Function::Handle(cls.LookupStaticFunction(name)); |
37 EXPECT(!function.IsNull()); | 37 EXPECT(!function.IsNull()); |
38 | 38 |
39 EXPECT(CompilerTest::TestCompileFunction(function)); | 39 EXPECT(CompilerTest::TestCompileFunction(function)); |
40 EXPECT(function.HasCode()); | 40 EXPECT(function.HasCode()); |
41 const Smi& retval = Smi::Handle(reinterpret_cast<RawSmi*>( | 41 const Smi& retval = Smi::Handle(reinterpret_cast<RawSmi*>( |
42 DartEntry::InvokeFunction(function, Object::empty_array()))); | 42 DartEntry::InvokeFunction(function, Object::empty_array()))); |
43 EXPECT_EQ(Smi::New(42), retval.raw()); | 43 EXPECT_EQ(Smi::New(42), retval.raw()); |
44 } | 44 } |
45 | 45 |
46 | 46 |
47 TEST_CASE(InvokeStatic_CompileError) { | 47 TEST_CASE(InvokeStatic_CompileError) { |
48 const char* kScriptChars = | 48 const char* kScriptChars = |
49 "class A {\n" | 49 "class A {\n" |
50 " static foo() { return ++++; }\n" | 50 " static foo() { return ++++; }\n" |
51 "}\n"; | 51 "}\n"; |
52 String& url = String::Handle(String::New("dart-test:DartEntry")); | 52 String& url = String::Handle(String::New("dart-test:DartEntry")); |
53 String& source = String::Handle(String::New(kScriptChars)); | 53 String& source = String::Handle(String::New(kScriptChars)); |
54 Script& script = Script::Handle(Script::New(url, | 54 Script& script = Script::Handle(Script::New(url, |
55 source, | 55 source, |
56 RawScript::kScriptTag)); | 56 RawScript::kScriptTag)); |
57 Library& lib = Library::Handle(Library::CoreLibrary()); | 57 Library& lib = Library::Handle(Library::CoreLibrary()); |
58 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); | 58 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); |
59 EXPECT(ClassFinalizer::ProcessPendingClasses()); | 59 EXPECT(ClassFinalizer::ProcessPendingClasses()); |
60 Class& cls = Class::Handle( | 60 Class& cls = Class::Handle( |
61 lib.LookupClass(String::Handle(Symbols::New("A")))); | 61 lib.LookupClass(String::Handle(Symbols::New(thread, "A")))); |
62 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 62 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
63 String& name = String::Handle(String::New("foo")); | 63 String& name = String::Handle(String::New("foo")); |
64 Function& function = Function::Handle(cls.LookupStaticFunction(name)); | 64 Function& function = Function::Handle(cls.LookupStaticFunction(name)); |
65 EXPECT(!function.IsNull()); | 65 EXPECT(!function.IsNull()); |
66 const Object& retval = Object::Handle( | 66 const Object& retval = Object::Handle( |
67 DartEntry::InvokeFunction(function, Object::empty_array())); | 67 DartEntry::InvokeFunction(function, Object::empty_array())); |
68 EXPECT(retval.IsError()); | 68 EXPECT(retval.IsError()); |
69 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); | 69 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); |
70 } | 70 } |
71 | 71 |
72 | 72 |
73 TEST_CASE(InvokeDynamic_CompileError) { | 73 TEST_CASE(InvokeDynamic_CompileError) { |
74 const char* kScriptChars = | 74 const char* kScriptChars = |
75 "class A {\n" | 75 "class A {\n" |
76 " foo() { return ++++; }\n" | 76 " foo() { return ++++; }\n" |
77 "}\n"; | 77 "}\n"; |
78 String& url = String::Handle(String::New("dart-test:DartEntry")); | 78 String& url = String::Handle(String::New("dart-test:DartEntry")); |
79 String& source = String::Handle(String::New(kScriptChars)); | 79 String& source = String::Handle(String::New(kScriptChars)); |
80 Script& script = Script::Handle(Script::New(url, | 80 Script& script = Script::Handle(Script::New(url, |
81 source, | 81 source, |
82 RawScript::kScriptTag)); | 82 RawScript::kScriptTag)); |
83 Library& lib = Library::Handle(Library::CoreLibrary()); | 83 Library& lib = Library::Handle(Library::CoreLibrary()); |
84 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); | 84 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); |
85 EXPECT(ClassFinalizer::ProcessPendingClasses()); | 85 EXPECT(ClassFinalizer::ProcessPendingClasses()); |
86 Class& cls = Class::Handle( | 86 Class& cls = Class::Handle( |
87 lib.LookupClass(String::Handle(Symbols::New("A")))); | 87 lib.LookupClass(String::Handle(Symbols::New(thread, "A")))); |
88 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 88 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
89 | 89 |
90 // Invoke the constructor. | 90 // Invoke the constructor. |
91 const Instance& instance = Instance::Handle(Instance::New(cls)); | 91 const Instance& instance = Instance::Handle(Instance::New(cls)); |
92 const Array& constructor_arguments = Array::Handle(Array::New(1)); | 92 const Array& constructor_arguments = Array::Handle(Array::New(1)); |
93 constructor_arguments.SetAt(0, instance); | 93 constructor_arguments.SetAt(0, instance); |
94 String& constructor_name = String::Handle(Symbols::New("A.")); | 94 String& constructor_name = String::Handle(Symbols::New(thread, "A.")); |
95 Function& constructor = | 95 Function& constructor = |
96 Function::Handle(cls.LookupConstructor(constructor_name)); | 96 Function::Handle(cls.LookupConstructor(constructor_name)); |
97 ASSERT(!constructor.IsNull()); | 97 ASSERT(!constructor.IsNull()); |
98 DartEntry::InvokeFunction(constructor, constructor_arguments); | 98 DartEntry::InvokeFunction(constructor, constructor_arguments); |
99 | 99 |
100 // Call foo. | 100 // Call foo. |
101 String& name = String::Handle(String::New("foo")); | 101 String& name = String::Handle(String::New("foo")); |
102 Function& function = Function::Handle(cls.LookupDynamicFunction(name)); | 102 Function& function = Function::Handle(cls.LookupDynamicFunction(name)); |
103 EXPECT(!function.IsNull()); | 103 EXPECT(!function.IsNull()); |
104 const Array& args = Array::Handle(Array::New(1)); | 104 const Array& args = Array::Handle(Array::New(1)); |
105 args.SetAt(0, instance); | 105 args.SetAt(0, instance); |
106 const Object& retval = Object::Handle(DartEntry::InvokeFunction(function, | 106 const Object& retval = Object::Handle(DartEntry::InvokeFunction(function, |
107 args)); | 107 args)); |
108 EXPECT(retval.IsError()); | 108 EXPECT(retval.IsError()); |
109 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); | 109 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); |
110 } | 110 } |
111 | 111 |
112 } // namespace dart | 112 } // namespace dart |
OLD | NEW |