| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 EXPECT(ClassFinalizer::FinalizePendingClasses()); | 32 EXPECT(ClassFinalizer::FinalizePendingClasses()); |
| 33 Class& cls = Class::Handle( | 33 Class& cls = Class::Handle( |
| 34 lib.LookupClass(String::Handle(Symbols::New("A")))); | 34 lib.LookupClass(String::Handle(Symbols::New("A")))); |
| 35 EXPECT(!cls.IsNull()); | 35 EXPECT(!cls.IsNull()); |
| 36 String& name = String::Handle(String::New("foo")); | 36 String& name = String::Handle(String::New("foo")); |
| 37 Function& function = Function::Handle(cls.LookupStaticFunction(name)); | 37 Function& function = Function::Handle(cls.LookupStaticFunction(name)); |
| 38 EXPECT(!function.IsNull()); | 38 EXPECT(!function.IsNull()); |
| 39 | 39 |
| 40 EXPECT(CompilerTest::TestCompileFunction(function)); | 40 EXPECT(CompilerTest::TestCompileFunction(function)); |
| 41 EXPECT(function.HasCode()); | 41 EXPECT(function.HasCode()); |
| 42 GrowableArray<const Object*> arguments; | 42 const Array& args = Array::Handle(Object::empty_array()); |
| 43 const Array& kNoArgumentNames = Array::Handle(); | |
| 44 const Smi& retval = Smi::Handle( | 43 const Smi& retval = Smi::Handle( |
| 45 reinterpret_cast<RawSmi*>(DartEntry::InvokeStatic(function, | 44 reinterpret_cast<RawSmi*>(DartEntry::InvokeStatic(function, args))); |
| 46 arguments, | |
| 47 kNoArgumentNames))); | |
| 48 EXPECT_EQ(Smi::New(42), retval.raw()); | 45 EXPECT_EQ(Smi::New(42), retval.raw()); |
| 49 } | 46 } |
| 50 | 47 |
| 51 | 48 |
| 52 TEST_CASE(InvokeStatic_CompileError) { | 49 TEST_CASE(InvokeStatic_CompileError) { |
| 53 const char* kScriptChars = | 50 const char* kScriptChars = |
| 54 "class A {\n" | 51 "class A {\n" |
| 55 " static foo() { return ++++; }\n" | 52 " static foo() { return ++++; }\n" |
| 56 "}\n"; | 53 "}\n"; |
| 57 String& url = String::Handle(String::New("dart-test:DartEntry")); | 54 String& url = String::Handle(String::New("dart-test:DartEntry")); |
| 58 String& source = String::Handle(String::New(kScriptChars)); | 55 String& source = String::Handle(String::New(kScriptChars)); |
| 59 Script& script = Script::Handle(Script::New(url, | 56 Script& script = Script::Handle(Script::New(url, |
| 60 source, | 57 source, |
| 61 RawScript::kScriptTag)); | 58 RawScript::kScriptTag)); |
| 62 Library& lib = Library::Handle(Library::CoreLibrary()); | 59 Library& lib = Library::Handle(Library::CoreLibrary()); |
| 63 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); | 60 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); |
| 64 EXPECT(ClassFinalizer::FinalizePendingClasses()); | 61 EXPECT(ClassFinalizer::FinalizePendingClasses()); |
| 65 Class& cls = Class::Handle( | 62 Class& cls = Class::Handle( |
| 66 lib.LookupClass(String::Handle(Symbols::New("A")))); | 63 lib.LookupClass(String::Handle(Symbols::New("A")))); |
| 67 EXPECT(!cls.IsNull()); | 64 EXPECT(!cls.IsNull()); |
| 68 String& name = String::Handle(String::New("foo")); | 65 String& name = String::Handle(String::New("foo")); |
| 69 Function& function = Function::Handle(cls.LookupStaticFunction(name)); | 66 Function& function = Function::Handle(cls.LookupStaticFunction(name)); |
| 70 EXPECT(!function.IsNull()); | 67 EXPECT(!function.IsNull()); |
| 71 GrowableArray<const Object*> arguments; | 68 GrowableArray<const Object*> arguments; |
| 72 const Array& kNoArgumentNames = Array::Handle(); | 69 const Array& args = Array::Handle(Object::empty_array()); |
| 73 const Object& retval = Object::Handle( | 70 const Object& retval = Object::Handle(DartEntry::InvokeStatic(function, |
| 74 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | 71 args)); |
| 75 EXPECT(retval.IsError()); | 72 EXPECT(retval.IsError()); |
| 76 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); | 73 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); |
| 77 } | 74 } |
| 78 | 75 |
| 79 | 76 |
| 80 TEST_CASE(InvokeDynamic_CompileError) { | 77 TEST_CASE(InvokeDynamic_CompileError) { |
| 81 const char* kScriptChars = | 78 const char* kScriptChars = |
| 82 "class A {\n" | 79 "class A {\n" |
| 83 " foo() { return ++++; }\n" | 80 " foo() { return ++++; }\n" |
| 84 "}\n"; | 81 "}\n"; |
| 85 String& url = String::Handle(String::New("dart-test:DartEntry")); | 82 String& url = String::Handle(String::New("dart-test:DartEntry")); |
| 86 String& source = String::Handle(String::New(kScriptChars)); | 83 String& source = String::Handle(String::New(kScriptChars)); |
| 87 Script& script = Script::Handle(Script::New(url, | 84 Script& script = Script::Handle(Script::New(url, |
| 88 source, | 85 source, |
| 89 RawScript::kScriptTag)); | 86 RawScript::kScriptTag)); |
| 90 Library& lib = Library::Handle(Library::CoreLibrary()); | 87 Library& lib = Library::Handle(Library::CoreLibrary()); |
| 91 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); | 88 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); |
| 92 EXPECT(ClassFinalizer::FinalizePendingClasses()); | 89 EXPECT(ClassFinalizer::FinalizePendingClasses()); |
| 93 Class& cls = Class::Handle( | 90 Class& cls = Class::Handle( |
| 94 lib.LookupClass(String::Handle(Symbols::New("A")))); | 91 lib.LookupClass(String::Handle(Symbols::New("A")))); |
| 95 EXPECT(!cls.IsNull()); | 92 EXPECT(!cls.IsNull()); |
| 96 | 93 |
| 97 // Invoke the constructor. | 94 // Invoke the constructor. |
| 98 const Instance& instance = Instance::Handle(Instance::New(cls)); | 95 const Instance& instance = Instance::Handle(Instance::New(cls)); |
| 99 GrowableArray<const Object*> constructor_arguments(2); | 96 const Array& constructor_arguments = Array::Handle(Array::New(2)); |
| 100 constructor_arguments.Add(&instance); | 97 constructor_arguments.SetAt(0, instance); |
| 101 constructor_arguments.Add(&Smi::Handle(Smi::New(Function::kCtorPhaseAll))); | 98 constructor_arguments.SetAt( |
| 99 1, Smi::Handle(Smi::New(Function::kCtorPhaseAll))); |
| 102 String& constructor_name = String::Handle(Symbols::New("A.")); | 100 String& constructor_name = String::Handle(Symbols::New("A.")); |
| 103 Function& constructor = | 101 Function& constructor = |
| 104 Function::Handle(cls.LookupConstructor(constructor_name)); | 102 Function::Handle(cls.LookupConstructor(constructor_name)); |
| 105 ASSERT(!constructor.IsNull()); | 103 ASSERT(!constructor.IsNull()); |
| 106 const Array& kNoArgumentNames = Array::Handle(); | 104 DartEntry::InvokeStatic(constructor, constructor_arguments); |
| 107 DartEntry::InvokeStatic(constructor, constructor_arguments, kNoArgumentNames); | |
| 108 | 105 |
| 109 // Call foo. | 106 // Call foo. |
| 110 String& name = String::Handle(String::New("foo")); | 107 String& name = String::Handle(String::New("foo")); |
| 111 Function& function = Function::Handle(cls.LookupDynamicFunction(name)); | 108 Function& function = Function::Handle(cls.LookupDynamicFunction(name)); |
| 112 EXPECT(!function.IsNull()); | 109 EXPECT(!function.IsNull()); |
| 113 GrowableArray<const Object*> arguments; | 110 const Array& args = Array::Handle(Array::New(1)); |
| 114 const Object& retval = Object::Handle( | 111 args.SetAt(0, instance); |
| 115 DartEntry::InvokeDynamic( | 112 const Object& retval = Object::Handle(DartEntry::InvokeDynamic(function, |
| 116 instance, function, arguments, kNoArgumentNames)); | 113 args)); |
| 117 EXPECT(retval.IsError()); | 114 EXPECT(retval.IsError()); |
| 118 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); | 115 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); |
| 119 } | 116 } |
| 120 | 117 |
| 121 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64. | 118 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64. |
| 122 | 119 |
| 123 } // namespace dart | 120 } // namespace dart |
| OLD | NEW |