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