| 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 24 matching lines...) Expand all Loading... |
| 35 Function& function = Function::Handle(cls.LookupStaticFunction(name)); | 35 Function& function = Function::Handle(cls.LookupStaticFunction(name)); |
| 36 EXPECT(!function.IsNull()); | 36 EXPECT(!function.IsNull()); |
| 37 | 37 |
| 38 EXPECT(CompilerTest::TestCompileFunction(function)); | 38 EXPECT(CompilerTest::TestCompileFunction(function)); |
| 39 EXPECT(function.HasCode()); | 39 EXPECT(function.HasCode()); |
| 40 const Smi& retval = Smi::Handle(reinterpret_cast<RawSmi*>( | 40 const Smi& retval = Smi::Handle(reinterpret_cast<RawSmi*>( |
| 41 DartEntry::InvokeFunction(function, Object::empty_array()))); | 41 DartEntry::InvokeFunction(function, Object::empty_array()))); |
| 42 EXPECT_EQ(Smi::New(42), retval.raw()); | 42 EXPECT_EQ(Smi::New(42), retval.raw()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 | |
| 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 = | 52 Script& script = |
| 54 Script::Handle(Script::New(url, source, RawScript::kScriptTag)); | 53 Script::Handle(Script::New(url, source, RawScript::kScriptTag)); |
| 55 Library& lib = Library::Handle(Library::CoreLibrary()); | 54 Library& lib = Library::Handle(Library::CoreLibrary()); |
| 56 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); | 55 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); |
| 57 EXPECT(ClassFinalizer::ProcessPendingClasses()); | 56 EXPECT(ClassFinalizer::ProcessPendingClasses()); |
| 58 Class& cls = | 57 Class& cls = |
| 59 Class::Handle(lib.LookupClass(String::Handle(Symbols::New(thread, "A")))); | 58 Class::Handle(lib.LookupClass(String::Handle(Symbols::New(thread, "A")))); |
| 60 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 59 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
| 61 String& name = String::Handle(String::New("foo")); | 60 String& name = String::Handle(String::New("foo")); |
| 62 Function& function = Function::Handle(cls.LookupStaticFunction(name)); | 61 Function& function = Function::Handle(cls.LookupStaticFunction(name)); |
| 63 EXPECT(!function.IsNull()); | 62 EXPECT(!function.IsNull()); |
| 64 const Object& retval = Object::Handle( | 63 const Object& retval = Object::Handle( |
| 65 DartEntry::InvokeFunction(function, Object::empty_array())); | 64 DartEntry::InvokeFunction(function, Object::empty_array())); |
| 66 EXPECT(retval.IsError()); | 65 EXPECT(retval.IsError()); |
| 67 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); | 66 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); |
| 68 } | 67 } |
| 69 | 68 |
| 70 | |
| 71 TEST_CASE(InvokeDynamic_CompileError) { | 69 TEST_CASE(InvokeDynamic_CompileError) { |
| 72 const char* kScriptChars = | 70 const char* kScriptChars = |
| 73 "class A {\n" | 71 "class A {\n" |
| 74 " foo() { return ++++; }\n" | 72 " foo() { return ++++; }\n" |
| 75 "}\n"; | 73 "}\n"; |
| 76 String& url = String::Handle(String::New("dart-test:DartEntry")); | 74 String& url = String::Handle(String::New("dart-test:DartEntry")); |
| 77 String& source = String::Handle(String::New(kScriptChars)); | 75 String& source = String::Handle(String::New(kScriptChars)); |
| 78 Script& script = | 76 Script& script = |
| 79 Script::Handle(Script::New(url, source, RawScript::kScriptTag)); | 77 Script::Handle(Script::New(url, source, RawScript::kScriptTag)); |
| 80 Library& lib = Library::Handle(Library::CoreLibrary()); | 78 Library& lib = Library::Handle(Library::CoreLibrary()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 100 EXPECT(!function.IsNull()); | 98 EXPECT(!function.IsNull()); |
| 101 const Array& args = Array::Handle(Array::New(1)); | 99 const Array& args = Array::Handle(Array::New(1)); |
| 102 args.SetAt(0, instance); | 100 args.SetAt(0, instance); |
| 103 const Object& retval = | 101 const Object& retval = |
| 104 Object::Handle(DartEntry::InvokeFunction(function, args)); | 102 Object::Handle(DartEntry::InvokeFunction(function, args)); |
| 105 EXPECT(retval.IsError()); | 103 EXPECT(retval.IsError()); |
| 106 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); | 104 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); |
| 107 } | 105 } |
| 108 | 106 |
| 109 } // namespace dart | 107 } // namespace dart |
| OLD | NEW |