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/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/compiler.h" | 8 #include "vm/compiler.h" |
8 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
9 #include "vm/object.h" | 10 #include "vm/object.h" |
10 #include "vm/resolver.h" | 11 #include "vm/resolver.h" |
11 #include "vm/unit_test.h" | 12 #include "vm/unit_test.h" |
12 | 13 |
13 namespace dart { | 14 namespace dart { |
14 | 15 |
15 // Only ia32 and x64 can run execution tests. | 16 // Only ia32 and x64 can run execution tests. |
16 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 17 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
(...skipping 19 matching lines...) Expand all Loading... |
36 EXPECT(function.HasCode()); | 37 EXPECT(function.HasCode()); |
37 GrowableArray<const Object*> arguments; | 38 GrowableArray<const Object*> arguments; |
38 const Array& kNoArgumentNames = Array::Handle(); | 39 const Array& kNoArgumentNames = Array::Handle(); |
39 const Smi& retval = Smi::Handle( | 40 const Smi& retval = Smi::Handle( |
40 reinterpret_cast<RawSmi*>(DartEntry::InvokeStatic(function, | 41 reinterpret_cast<RawSmi*>(DartEntry::InvokeStatic(function, |
41 arguments, | 42 arguments, |
42 kNoArgumentNames))); | 43 kNoArgumentNames))); |
43 EXPECT_EQ(Smi::New(42), retval.raw()); | 44 EXPECT_EQ(Smi::New(42), retval.raw()); |
44 } | 45 } |
45 | 46 |
| 47 |
| 48 TEST_CASE(InvokeStatic_CompileError) { |
| 49 const char* kScriptChars = |
| 50 "class A {\n" |
| 51 " static foo() { return ++++; }\n" |
| 52 "}\n"; |
| 53 String& url = String::Handle(String::New("dart-test:DartEntry")); |
| 54 String& source = String::Handle(String::New(kScriptChars)); |
| 55 Script& script = Script::Handle(Script::New(url, source, RawScript::kScript)); |
| 56 Library& lib = Library::Handle(Library::CoreLibrary()); |
| 57 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); |
| 58 EXPECT(ClassFinalizer::FinalizePendingClasses()); |
| 59 Class& cls = Class::Handle( |
| 60 lib.LookupClass(String::Handle(String::NewSymbol("A")))); |
| 61 EXPECT(!cls.IsNull()); |
| 62 String& name = String::Handle(String::New("foo")); |
| 63 Function& function = Function::Handle(cls.LookupStaticFunction(name)); |
| 64 EXPECT(!function.IsNull()); |
| 65 GrowableArray<const Object*> arguments; |
| 66 const Array& kNoArgumentNames = Array::Handle(); |
| 67 const Object& retval = Object::Handle( |
| 68 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
| 69 EXPECT(retval.IsError()); |
| 70 Error& error = Error::Handle(); |
| 71 error ^= retval.raw(); |
| 72 EXPECT_SUBSTRING("++++", error.ToErrorCString()); |
| 73 } |
| 74 |
| 75 |
| 76 TEST_CASE(InvokeDynamic_CompileError) { |
| 77 const char* kScriptChars = |
| 78 "class A {\n" |
| 79 " foo() { return ++++; }\n" |
| 80 "}\n"; |
| 81 String& url = String::Handle(String::New("dart-test:DartEntry")); |
| 82 String& source = String::Handle(String::New(kScriptChars)); |
| 83 Script& script = Script::Handle(Script::New(url, source, RawScript::kScript)); |
| 84 Library& lib = Library::Handle(Library::CoreLibrary()); |
| 85 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); |
| 86 EXPECT(ClassFinalizer::FinalizePendingClasses()); |
| 87 Class& cls = Class::Handle( |
| 88 lib.LookupClass(String::Handle(String::NewSymbol("A")))); |
| 89 EXPECT(!cls.IsNull()); |
| 90 |
| 91 // Invoke the constructor. |
| 92 const Instance& instance = Instance::Handle(Instance::New(cls)); |
| 93 GrowableArray<const Object*> constructor_arguments(2); |
| 94 constructor_arguments.Add(&instance); |
| 95 constructor_arguments.Add(&Smi::Handle(Smi::New(Function::kCtorPhaseAll))); |
| 96 String& constructor_name = String::Handle(String::NewSymbol("A.")); |
| 97 Function& constructor = |
| 98 Function::Handle(cls.LookupConstructor(constructor_name)); |
| 99 ASSERT(!constructor.IsNull()); |
| 100 const Array& kNoArgumentNames = Array::Handle(); |
| 101 DartEntry::InvokeStatic(constructor, constructor_arguments, kNoArgumentNames); |
| 102 |
| 103 // Call foo. |
| 104 String& name = String::Handle(String::New("foo")); |
| 105 Function& function = Function::Handle(cls.LookupDynamicFunction(name)); |
| 106 EXPECT(!function.IsNull()); |
| 107 GrowableArray<const Object*> arguments; |
| 108 const Object& retval = Object::Handle( |
| 109 DartEntry::InvokeDynamic( |
| 110 instance, function, arguments, kNoArgumentNames)); |
| 111 EXPECT(retval.IsError()); |
| 112 Error& error = Error::Handle(); |
| 113 error ^= retval.raw(); |
| 114 EXPECT_SUBSTRING("++++", error.ToErrorCString()); |
| 115 } |
| 116 |
46 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64. | 117 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64. |
47 | 118 |
48 } // namespace dart | 119 } // namespace dart |
OLD | NEW |