| 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 "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 3865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3876 EXPECT_EQ(func_x.raw(), func_x_from_index.raw()); | 3876 EXPECT_EQ(func_x.raw(), func_x_from_index.raw()); |
| 3877 } | 3877 } |
| 3878 | 3878 |
| 3879 | 3879 |
| 3880 TEST_CASE(FindClosureIndex) { | 3880 TEST_CASE(FindClosureIndex) { |
| 3881 // Allocate the class first. | 3881 // Allocate the class first. |
| 3882 const String& class_name = String::Handle(Symbols::New("MyClass")); | 3882 const String& class_name = String::Handle(Symbols::New("MyClass")); |
| 3883 const Script& script = Script::Handle(); | 3883 const Script& script = Script::Handle(); |
| 3884 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 3884 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
| 3885 const Array& functions = Array::Handle(Array::New(1)); | 3885 const Array& functions = Array::Handle(Array::New(1)); |
| 3886 const Isolate* iso = Isolate::Current(); |
| 3886 | 3887 |
| 3887 Function& parent = Function::Handle(); | 3888 Function& parent = Function::Handle(); |
| 3888 const String& parent_name = String::Handle(Symbols::New("foo_papa")); | 3889 const String& parent_name = String::Handle(Symbols::New("foo_papa")); |
| 3889 parent = Function::New(parent_name, RawFunction::kRegularFunction, | 3890 parent = Function::New(parent_name, RawFunction::kRegularFunction, |
| 3890 false, false, false, false, false, cls, 0); | 3891 false, false, false, false, false, cls, 0); |
| 3891 functions.SetAt(0, parent); | 3892 functions.SetAt(0, parent); |
| 3892 cls.SetFunctions(functions); | 3893 cls.SetFunctions(functions); |
| 3893 | 3894 |
| 3894 Function& function = Function::Handle(); | 3895 Function& function = Function::Handle(); |
| 3895 const String& function_name = String::Handle(Symbols::New("foo")); | 3896 const String& function_name = String::Handle(Symbols::New("foo")); |
| 3896 function = Function::NewClosureFunction(function_name, parent, 0); | 3897 function = Function::NewClosureFunction(function_name, parent, 0); |
| 3897 // Add closure function to class. | 3898 // Add closure function to class. |
| 3898 cls.AddClosureFunction(function); | 3899 iso->AddClosureFunction(function); |
| 3899 | 3900 |
| 3900 // The closure should return a valid index. | 3901 // The closure should return a valid index. |
| 3901 intptr_t good_closure_index = cls.FindClosureIndex(function); | 3902 intptr_t good_closure_index = iso->FindClosureIndex(function); |
| 3902 EXPECT_GE(good_closure_index, 0); | 3903 EXPECT_GE(good_closure_index, 0); |
| 3903 // The parent function should return an invalid index. | 3904 // The parent function should return an invalid index. |
| 3904 intptr_t bad_closure_index = cls.FindClosureIndex(parent); | 3905 intptr_t bad_closure_index = iso->FindClosureIndex(parent); |
| 3905 EXPECT_EQ(bad_closure_index, -1); | 3906 EXPECT_EQ(bad_closure_index, -1); |
| 3906 | 3907 |
| 3907 // Retrieve closure function via index. | 3908 // Retrieve closure function via index. |
| 3908 Function& func_from_index = Function::Handle(); | 3909 Function& func_from_index = Function::Handle(); |
| 3909 func_from_index ^= cls.ClosureFunctionFromIndex(good_closure_index); | 3910 func_from_index ^= iso->ClosureFunctionFromIndex(good_closure_index); |
| 3910 // Same closure function. | 3911 // Same closure function. |
| 3911 EXPECT_EQ(func_from_index.raw(), function.raw()); | 3912 EXPECT_EQ(func_from_index.raw(), function.raw()); |
| 3912 } | 3913 } |
| 3913 | 3914 |
| 3914 | 3915 |
| 3915 TEST_CASE(FindInvocationDispatcherFunctionIndex) { | 3916 TEST_CASE(FindInvocationDispatcherFunctionIndex) { |
| 3916 const String& class_name = String::Handle(Symbols::New("MyClass")); | 3917 const String& class_name = String::Handle(Symbols::New("MyClass")); |
| 3917 const Script& script = Script::Handle(); | 3918 const Script& script = Script::Handle(); |
| 3918 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 3919 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
| 3919 ClassFinalizer::FinalizeTypesInClass(cls); | 3920 ClassFinalizer::FinalizeTypesInClass(cls); |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4788 String& test = String::Handle(); | 4789 String& test = String::Handle(); |
| 4789 String& result = String::Handle(); | 4790 String& result = String::Handle(); |
| 4790 for (size_t i = 0; i < ARRAY_SIZE(tests); i++) { | 4791 for (size_t i = 0; i < ARRAY_SIZE(tests); i++) { |
| 4791 test = String::New(tests[i].in); | 4792 test = String::New(tests[i].in); |
| 4792 result = String::IdentifierPrettyName(test); | 4793 result = String::IdentifierPrettyName(test); |
| 4793 EXPECT_STREQ(tests[i].out, result.ToCString()); | 4794 EXPECT_STREQ(tests[i].out, result.ToCString()); |
| 4794 } | 4795 } |
| 4795 } | 4796 } |
| 4796 | 4797 |
| 4797 } // namespace dart | 4798 } // namespace dart |
| OLD | NEW |