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 19 matching lines...) Expand all Loading... |
30 const Script& script) { | 30 const Script& script) { |
31 const Class& cls = Class::Handle( | 31 const Class& cls = Class::Handle( |
32 Class::New(class_name, script, TokenPosition::kNoSource)); | 32 Class::New(class_name, script, TokenPosition::kNoSource)); |
33 cls.set_is_synthesized_class(); // Dummy class for testing. | 33 cls.set_is_synthesized_class(); // Dummy class for testing. |
34 return cls.raw(); | 34 return cls.raw(); |
35 } | 35 } |
36 | 36 |
37 | 37 |
38 VM_TEST_CASE(Class) { | 38 VM_TEST_CASE(Class) { |
39 // Allocate the class first. | 39 // Allocate the class first. |
40 const String& class_name = String::Handle(Symbols::New("MyClass")); | 40 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); |
41 const Script& script = Script::Handle(); | 41 const Script& script = Script::Handle(); |
42 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 42 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
43 | 43 |
44 // Class has no fields and no functions yet. | 44 // Class has no fields and no functions yet. |
45 EXPECT_EQ(Array::Handle(cls.fields()).Length(), 0); | 45 EXPECT_EQ(Array::Handle(cls.fields()).Length(), 0); |
46 EXPECT_EQ(Array::Handle(cls.functions()).Length(), 0); | 46 EXPECT_EQ(Array::Handle(cls.functions()).Length(), 0); |
47 | 47 |
48 // Setup the interfaces in the class. | 48 // Setup the interfaces in the class. |
49 const Array& interfaces = Array::Handle(Array::New(2)); | 49 const Array& interfaces = Array::Handle(Array::New(2)); |
50 Class& interface = Class::Handle(); | 50 Class& interface = Class::Handle(); |
51 String& interface_name = String::Handle(); | 51 String& interface_name = String::Handle(); |
52 interface_name = Symbols::New("Harley"); | 52 interface_name = Symbols::New(thread, "Harley"); |
53 interface = CreateDummyClass(interface_name, script); | 53 interface = CreateDummyClass(interface_name, script); |
54 interfaces.SetAt(0, Type::Handle(Type::NewNonParameterizedType(interface))); | 54 interfaces.SetAt(0, Type::Handle(Type::NewNonParameterizedType(interface))); |
55 interface_name = Symbols::New("Norton"); | 55 interface_name = Symbols::New(thread, "Norton"); |
56 interface = CreateDummyClass(interface_name, script); | 56 interface = CreateDummyClass(interface_name, script); |
57 interfaces.SetAt(1, Type::Handle(Type::NewNonParameterizedType(interface))); | 57 interfaces.SetAt(1, Type::Handle(Type::NewNonParameterizedType(interface))); |
58 cls.set_interfaces(interfaces); | 58 cls.set_interfaces(interfaces); |
59 | 59 |
60 // Finalization of types happens before the fields and functions have been | 60 // Finalization of types happens before the fields and functions have been |
61 // parsed. | 61 // parsed. |
62 ClassFinalizer::FinalizeTypesInClass(cls); | 62 ClassFinalizer::FinalizeTypesInClass(cls); |
63 | 63 |
64 // Create and populate the function arrays. | 64 // Create and populate the function arrays. |
65 const Array& functions = Array::Handle(Array::New(6)); | 65 const Array& functions = Array::Handle(Array::New(6)); |
66 Function& function = Function::Handle(); | 66 Function& function = Function::Handle(); |
67 String& function_name = String::Handle(); | 67 String& function_name = String::Handle(); |
68 function_name = Symbols::New("foo"); | 68 function_name = Symbols::New(thread, "foo"); |
69 function = Function::New( | 69 function = Function::New( |
70 function_name, RawFunction::kRegularFunction, | 70 function_name, RawFunction::kRegularFunction, |
71 false, false, false, false, false, cls, TokenPosition::kMinSource); | 71 false, false, false, false, false, cls, TokenPosition::kMinSource); |
72 functions.SetAt(0, function); | 72 functions.SetAt(0, function); |
73 function_name = Symbols::New("bar"); | 73 function_name = Symbols::New(thread, "bar"); |
74 function = Function::New( | 74 function = Function::New( |
75 function_name, RawFunction::kRegularFunction, | 75 function_name, RawFunction::kRegularFunction, |
76 false, false, false, false, false, cls, TokenPosition::kMinSource); | 76 false, false, false, false, false, cls, TokenPosition::kMinSource); |
77 | 77 |
78 const int kNumFixedParameters = 2; | 78 const int kNumFixedParameters = 2; |
79 const int kNumOptionalParameters = 3; | 79 const int kNumOptionalParameters = 3; |
80 const bool kAreOptionalPositional = true; | 80 const bool kAreOptionalPositional = true; |
81 function.set_num_fixed_parameters(kNumFixedParameters); | 81 function.set_num_fixed_parameters(kNumFixedParameters); |
82 function.SetNumOptionalParameters(kNumOptionalParameters, | 82 function.SetNumOptionalParameters(kNumOptionalParameters, |
83 kAreOptionalPositional); | 83 kAreOptionalPositional); |
84 functions.SetAt(1, function); | 84 functions.SetAt(1, function); |
85 | 85 |
86 function_name = Symbols::New("baz"); | 86 function_name = Symbols::New(thread, "baz"); |
87 function = Function::New( | 87 function = Function::New( |
88 function_name, RawFunction::kRegularFunction, | 88 function_name, RawFunction::kRegularFunction, |
89 false, false, false, false, false, cls, TokenPosition::kMinSource); | 89 false, false, false, false, false, cls, TokenPosition::kMinSource); |
90 functions.SetAt(2, function); | 90 functions.SetAt(2, function); |
91 | 91 |
92 function_name = Symbols::New("Foo"); | 92 function_name = Symbols::New(thread, "Foo"); |
93 function = Function::New( | 93 function = Function::New( |
94 function_name, RawFunction::kRegularFunction, | 94 function_name, RawFunction::kRegularFunction, |
95 true, false, false, false, false, cls, TokenPosition::kMinSource); | 95 true, false, false, false, false, cls, TokenPosition::kMinSource); |
96 | 96 |
97 functions.SetAt(3, function); | 97 functions.SetAt(3, function); |
98 function_name = Symbols::New("Bar"); | 98 function_name = Symbols::New(thread, "Bar"); |
99 function = Function::New( | 99 function = Function::New( |
100 function_name, RawFunction::kRegularFunction, | 100 function_name, RawFunction::kRegularFunction, |
101 true, false, false, false, false, cls, TokenPosition::kMinSource); | 101 true, false, false, false, false, cls, TokenPosition::kMinSource); |
102 functions.SetAt(4, function); | 102 functions.SetAt(4, function); |
103 function_name = Symbols::New("BaZ"); | 103 function_name = Symbols::New(thread, "BaZ"); |
104 function = Function::New( | 104 function = Function::New( |
105 function_name, RawFunction::kRegularFunction, | 105 function_name, RawFunction::kRegularFunction, |
106 true, false, false, false, false, cls, TokenPosition::kMinSource); | 106 true, false, false, false, false, cls, TokenPosition::kMinSource); |
107 functions.SetAt(5, function); | 107 functions.SetAt(5, function); |
108 | 108 |
109 // Setup the functions in the class. | 109 // Setup the functions in the class. |
110 cls.SetFunctions(functions); | 110 cls.SetFunctions(functions); |
111 | 111 |
112 // The class can now be finalized. | 112 // The class can now be finalized. |
113 cls.Finalize(); | 113 cls.Finalize(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 const Script& scr = Script::Handle(cls.script()); | 251 const Script& scr = Script::Handle(cls.script()); |
252 intptr_t line; | 252 intptr_t line; |
253 intptr_t col; | 253 intptr_t col; |
254 scr.GetTokenLocation(end_token_pos, &line, &col); | 254 scr.GetTokenLocation(end_token_pos, &line, &col); |
255 EXPECT(line == 10 && col == 1); | 255 EXPECT(line == 10 && col == 1); |
256 } | 256 } |
257 | 257 |
258 | 258 |
259 VM_TEST_CASE(InstanceClass) { | 259 VM_TEST_CASE(InstanceClass) { |
260 // Allocate the class first. | 260 // Allocate the class first. |
261 String& class_name = String::Handle(Symbols::New("EmptyClass")); | 261 String& class_name = String::Handle(Symbols::New(thread, "EmptyClass")); |
262 Script& script = Script::Handle(); | 262 Script& script = Script::Handle(); |
263 const Class& empty_class = | 263 const Class& empty_class = |
264 Class::Handle(CreateDummyClass(class_name, script)); | 264 Class::Handle(CreateDummyClass(class_name, script)); |
265 | 265 |
266 // EmptyClass has no fields and no functions. | 266 // EmptyClass has no fields and no functions. |
267 EXPECT_EQ(Array::Handle(empty_class.fields()).Length(), 0); | 267 EXPECT_EQ(Array::Handle(empty_class.fields()).Length(), 0); |
268 EXPECT_EQ(Array::Handle(empty_class.functions()).Length(), 0); | 268 EXPECT_EQ(Array::Handle(empty_class.functions()).Length(), 0); |
269 | 269 |
270 ClassFinalizer::FinalizeTypesInClass(empty_class); | 270 ClassFinalizer::FinalizeTypesInClass(empty_class); |
271 empty_class.Finalize(); | 271 empty_class.Finalize(); |
272 | 272 |
273 EXPECT_EQ(kObjectAlignment, empty_class.instance_size()); | 273 EXPECT_EQ(kObjectAlignment, empty_class.instance_size()); |
274 Instance& instance = Instance::Handle(Instance::New(empty_class)); | 274 Instance& instance = Instance::Handle(Instance::New(empty_class)); |
275 EXPECT_EQ(empty_class.raw(), instance.clazz()); | 275 EXPECT_EQ(empty_class.raw(), instance.clazz()); |
276 | 276 |
277 class_name = Symbols::New("OneFieldClass"); | 277 class_name = Symbols::New(thread, "OneFieldClass"); |
278 const Class& one_field_class = | 278 const Class& one_field_class = |
279 Class::Handle(CreateDummyClass(class_name, script)); | 279 Class::Handle(CreateDummyClass(class_name, script)); |
280 | 280 |
281 // No fields, functions, or super type for the OneFieldClass. | 281 // No fields, functions, or super type for the OneFieldClass. |
282 EXPECT_EQ(Array::Handle(empty_class.fields()).Length(), 0); | 282 EXPECT_EQ(Array::Handle(empty_class.fields()).Length(), 0); |
283 EXPECT_EQ(Array::Handle(empty_class.functions()).Length(), 0); | 283 EXPECT_EQ(Array::Handle(empty_class.functions()).Length(), 0); |
284 EXPECT_EQ(empty_class.super_type(), AbstractType::null()); | 284 EXPECT_EQ(empty_class.super_type(), AbstractType::null()); |
285 ClassFinalizer::FinalizeTypesInClass(one_field_class); | 285 ClassFinalizer::FinalizeTypesInClass(one_field_class); |
286 | 286 |
287 const Array& one_fields = Array::Handle(Array::New(1)); | 287 const Array& one_fields = Array::Handle(Array::New(1)); |
288 const String& field_name = String::Handle(Symbols::New("the_field")); | 288 const String& field_name = String::Handle(Symbols::New(thread, "the_field")); |
289 const Field& field = Field::Handle( | 289 const Field& field = Field::Handle( |
290 Field::New(field_name, false, false, false, true, one_field_class, | 290 Field::New(field_name, false, false, false, true, one_field_class, |
291 Object::dynamic_type(), TokenPosition::kMinSource)); | 291 Object::dynamic_type(), TokenPosition::kMinSource)); |
292 one_fields.SetAt(0, field); | 292 one_fields.SetAt(0, field); |
293 one_field_class.SetFields(one_fields); | 293 one_field_class.SetFields(one_fields); |
294 one_field_class.Finalize(); | 294 one_field_class.Finalize(); |
295 intptr_t header_size = sizeof(RawObject); | 295 intptr_t header_size = sizeof(RawObject); |
296 EXPECT_EQ(Utils::RoundUp((header_size + (1 * kWordSize)), kObjectAlignment), | 296 EXPECT_EQ(Utils::RoundUp((header_size + (1 * kWordSize)), kObjectAlignment), |
297 one_field_class.instance_size()); | 297 one_field_class.instance_size()); |
298 EXPECT_EQ(header_size, field.Offset()); | 298 EXPECT_EQ(header_size, field.Offset()); |
(...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1819 | 1819 |
1820 const String& substr = String::Handle(String::SubString(str, 1, 1)); | 1820 const String& substr = String::Handle(String::SubString(str, 1, 1)); |
1821 EXPECT(!substr.IsExternalTwoByteString()); | 1821 EXPECT(!substr.IsExternalTwoByteString()); |
1822 EXPECT(substr.IsTwoByteString()); | 1822 EXPECT(substr.IsTwoByteString()); |
1823 EXPECT_EQ(1, substr.Length()); | 1823 EXPECT_EQ(1, substr.Length()); |
1824 EXPECT(substr.Equals("\xE1\xBA\x85")); | 1824 EXPECT(substr.Equals("\xE1\xBA\x85")); |
1825 } | 1825 } |
1826 | 1826 |
1827 | 1827 |
1828 VM_TEST_CASE(Symbol) { | 1828 VM_TEST_CASE(Symbol) { |
1829 const String& one = String::Handle(Symbols::New("Eins")); | 1829 const String& one = String::Handle(Symbols::New(thread, "Eins")); |
1830 EXPECT(one.IsSymbol()); | 1830 EXPECT(one.IsSymbol()); |
1831 const String& two = String::Handle(Symbols::New("Zwei")); | 1831 const String& two = String::Handle(Symbols::New(thread, "Zwei")); |
1832 const String& three = String::Handle(Symbols::New("Drei")); | 1832 const String& three = String::Handle(Symbols::New(thread, "Drei")); |
1833 const String& four = String::Handle(Symbols::New("Vier")); | 1833 const String& four = String::Handle(Symbols::New(thread, "Vier")); |
1834 const String& five = String::Handle(Symbols::New("Fuenf")); | 1834 const String& five = String::Handle(Symbols::New(thread, "Fuenf")); |
1835 const String& six = String::Handle(Symbols::New("Sechs")); | 1835 const String& six = String::Handle(Symbols::New(thread, "Sechs")); |
1836 const String& seven = String::Handle(Symbols::New("Sieben")); | 1836 const String& seven = String::Handle(Symbols::New(thread, "Sieben")); |
1837 const String& eight = String::Handle(Symbols::New("Acht")); | 1837 const String& eight = String::Handle(Symbols::New(thread, "Acht")); |
1838 const String& nine = String::Handle(Symbols::New("Neun")); | 1838 const String& nine = String::Handle(Symbols::New(thread, "Neun")); |
1839 const String& ten = String::Handle(Symbols::New("Zehn")); | 1839 const String& ten = String::Handle(Symbols::New(thread, "Zehn")); |
1840 String& eins = String::Handle(Symbols::New("Eins")); | 1840 String& eins = String::Handle(Symbols::New(thread, "Eins")); |
1841 EXPECT_EQ(one.raw(), eins.raw()); | 1841 EXPECT_EQ(one.raw(), eins.raw()); |
1842 EXPECT(one.raw() != two.raw()); | 1842 EXPECT(one.raw() != two.raw()); |
1843 EXPECT(two.Equals(String::Handle(String::New("Zwei")))); | 1843 EXPECT(two.Equals(String::Handle(String::New("Zwei")))); |
1844 EXPECT_EQ(two.raw(), Symbols::New("Zwei")); | 1844 EXPECT_EQ(two.raw(), Symbols::New(thread, "Zwei")); |
1845 EXPECT_EQ(three.raw(), Symbols::New("Drei")); | 1845 EXPECT_EQ(three.raw(), Symbols::New(thread, "Drei")); |
1846 EXPECT_EQ(four.raw(), Symbols::New("Vier")); | 1846 EXPECT_EQ(four.raw(), Symbols::New(thread, "Vier")); |
1847 EXPECT_EQ(five.raw(), Symbols::New("Fuenf")); | 1847 EXPECT_EQ(five.raw(), Symbols::New(thread, "Fuenf")); |
1848 EXPECT_EQ(six.raw(), Symbols::New("Sechs")); | 1848 EXPECT_EQ(six.raw(), Symbols::New(thread, "Sechs")); |
1849 EXPECT_EQ(seven.raw(), Symbols::New("Sieben")); | 1849 EXPECT_EQ(seven.raw(), Symbols::New(thread, "Sieben")); |
1850 EXPECT_EQ(eight.raw(), Symbols::New("Acht")); | 1850 EXPECT_EQ(eight.raw(), Symbols::New(thread, "Acht")); |
1851 EXPECT_EQ(nine.raw(), Symbols::New("Neun")); | 1851 EXPECT_EQ(nine.raw(), Symbols::New(thread, "Neun")); |
1852 EXPECT_EQ(ten.raw(), Symbols::New("Zehn")); | 1852 EXPECT_EQ(ten.raw(), Symbols::New(thread, "Zehn")); |
1853 | 1853 |
1854 // Make sure to cause symbol table overflow. | 1854 // Make sure to cause symbol table overflow. |
1855 for (int i = 0; i < 1024; i++) { | 1855 for (int i = 0; i < 1024; i++) { |
1856 char buf[256]; | 1856 char buf[256]; |
1857 OS::SNPrint(buf, sizeof(buf), "%d", i); | 1857 OS::SNPrint(buf, sizeof(buf), "%d", i); |
1858 Symbols::New(buf); | 1858 Symbols::New(thread, buf); |
1859 } | 1859 } |
1860 eins = Symbols::New("Eins"); | 1860 eins = Symbols::New(thread, "Eins"); |
1861 EXPECT_EQ(one.raw(), eins.raw()); | 1861 EXPECT_EQ(one.raw(), eins.raw()); |
1862 EXPECT_EQ(two.raw(), Symbols::New("Zwei")); | 1862 EXPECT_EQ(two.raw(), Symbols::New(thread, "Zwei")); |
1863 EXPECT_EQ(three.raw(), Symbols::New("Drei")); | 1863 EXPECT_EQ(three.raw(), Symbols::New(thread, "Drei")); |
1864 EXPECT_EQ(four.raw(), Symbols::New("Vier")); | 1864 EXPECT_EQ(four.raw(), Symbols::New(thread, "Vier")); |
1865 EXPECT_EQ(five.raw(), Symbols::New("Fuenf")); | 1865 EXPECT_EQ(five.raw(), Symbols::New(thread, "Fuenf")); |
1866 EXPECT_EQ(six.raw(), Symbols::New("Sechs")); | 1866 EXPECT_EQ(six.raw(), Symbols::New(thread, "Sechs")); |
1867 EXPECT_EQ(seven.raw(), Symbols::New("Sieben")); | 1867 EXPECT_EQ(seven.raw(), Symbols::New(thread, "Sieben")); |
1868 EXPECT_EQ(eight.raw(), Symbols::New("Acht")); | 1868 EXPECT_EQ(eight.raw(), Symbols::New(thread, "Acht")); |
1869 EXPECT_EQ(nine.raw(), Symbols::New("Neun")); | 1869 EXPECT_EQ(nine.raw(), Symbols::New(thread, "Neun")); |
1870 EXPECT_EQ(ten.raw(), Symbols::New("Zehn")); | 1870 EXPECT_EQ(ten.raw(), Symbols::New(thread, "Zehn")); |
1871 | 1871 |
1872 // Symbols from Strings. | 1872 // Symbols from Strings. |
1873 eins = String::New("Eins"); | 1873 eins = String::New("Eins"); |
1874 EXPECT(!eins.IsSymbol()); | 1874 EXPECT(!eins.IsSymbol()); |
1875 String& ein_symbol = String::Handle(Symbols::New(eins)); | 1875 String& ein_symbol = String::Handle(Symbols::New(thread, eins)); |
1876 EXPECT_EQ(one.raw(), ein_symbol.raw()); | 1876 EXPECT_EQ(one.raw(), ein_symbol.raw()); |
1877 EXPECT(one.raw() != eins.raw()); | 1877 EXPECT(one.raw() != eins.raw()); |
1878 | 1878 |
1879 uint16_t char16[] = { 'E', 'l', 'f' }; | 1879 uint16_t char16[] = { 'E', 'l', 'f' }; |
1880 String& elf1 = String::Handle(Symbols::FromUTF16(char16, 3)); | 1880 String& elf1 = String::Handle(Symbols::FromUTF16(thread, char16, 3)); |
1881 int32_t char32[] = { 'E', 'l', 'f' }; | 1881 int32_t char32[] = { 'E', 'l', 'f' }; |
1882 String& elf2 = String::Handle(Symbols::FromUTF32(char32, 3)); | 1882 String& elf2 = String::Handle(Symbols::FromUTF32(thread, char32, 3)); |
1883 EXPECT(elf1.IsSymbol()); | 1883 EXPECT(elf1.IsSymbol()); |
1884 EXPECT(elf2.IsSymbol()); | 1884 EXPECT(elf2.IsSymbol()); |
1885 EXPECT_EQ(elf1.raw(), Symbols::New("Elf")); | 1885 EXPECT_EQ(elf1.raw(), Symbols::New(thread, "Elf")); |
1886 EXPECT_EQ(elf2.raw(), Symbols::New("Elf")); | 1886 EXPECT_EQ(elf2.raw(), Symbols::New(thread, "Elf")); |
1887 } | 1887 } |
1888 | 1888 |
1889 | 1889 |
1890 VM_TEST_CASE(SymbolUnicode) { | 1890 VM_TEST_CASE(SymbolUnicode) { |
1891 uint16_t monkey_utf16[] = { 0xd83d, 0xdc35 }; // Unicode Monkey Face. | 1891 uint16_t monkey_utf16[] = { 0xd83d, 0xdc35 }; // Unicode Monkey Face. |
1892 String& monkey = String::Handle(Symbols::FromUTF16(monkey_utf16, 2)); | 1892 String& monkey = String::Handle(Symbols::FromUTF16(thread, monkey_utf16, 2)); |
1893 EXPECT(monkey.IsSymbol()); | 1893 EXPECT(monkey.IsSymbol()); |
1894 const char monkey_utf8[] = {'\xf0', '\x9f', '\x90', '\xb5', 0}; | 1894 const char monkey_utf8[] = {'\xf0', '\x9f', '\x90', '\xb5', 0}; |
1895 EXPECT_EQ(monkey.raw(), Symbols::New(monkey_utf8)); | 1895 EXPECT_EQ(monkey.raw(), Symbols::New(thread, monkey_utf8)); |
1896 | 1896 |
1897 int32_t kMonkeyFace = 0x1f435; | 1897 int32_t kMonkeyFace = 0x1f435; |
1898 String& monkey2 = String::Handle(Symbols::FromCharCode(kMonkeyFace)); | 1898 String& monkey2 = String::Handle(Symbols::FromCharCode(thread, kMonkeyFace)); |
1899 EXPECT_EQ(monkey.raw(), monkey2.raw()); | 1899 EXPECT_EQ(monkey.raw(), monkey2.raw()); |
1900 | 1900 |
1901 // Unicode cat face with tears of joy. | 1901 // Unicode cat face with tears of joy. |
1902 int32_t kCatFaceWithTearsOfJoy = 0x1f639; | 1902 int32_t kCatFaceWithTearsOfJoy = 0x1f639; |
1903 String& cat = String::Handle(Symbols::FromCharCode(kCatFaceWithTearsOfJoy)); | 1903 String& cat = String::Handle(Symbols::FromCharCode(thread, |
| 1904 kCatFaceWithTearsOfJoy)); |
1904 | 1905 |
1905 uint16_t cat_utf16[] = { 0xd83d, 0xde39 }; | 1906 uint16_t cat_utf16[] = { 0xd83d, 0xde39 }; |
1906 String& cat2 = String::Handle(Symbols::FromUTF16(cat_utf16, 2)); | 1907 String& cat2 = String::Handle(Symbols::FromUTF16(thread, cat_utf16, 2)); |
1907 EXPECT(cat2.IsSymbol()); | 1908 EXPECT(cat2.IsSymbol()); |
1908 EXPECT_EQ(cat2.raw(), cat.raw()); | 1909 EXPECT_EQ(cat2.raw(), cat.raw()); |
1909 } | 1910 } |
1910 | 1911 |
1911 | 1912 |
1912 VM_TEST_CASE(Bool) { | 1913 VM_TEST_CASE(Bool) { |
1913 EXPECT(Bool::True().value()); | 1914 EXPECT(Bool::True().value()); |
1914 EXPECT(!Bool::False().value()); | 1915 EXPECT(!Bool::False().value()); |
1915 } | 1916 } |
1916 | 1917 |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2534 VM_TEST_CASE(ContextScope) { | 2535 VM_TEST_CASE(ContextScope) { |
2535 const intptr_t parent_scope_function_level = 0; | 2536 const intptr_t parent_scope_function_level = 0; |
2536 LocalScope* parent_scope = | 2537 LocalScope* parent_scope = |
2537 new LocalScope(NULL, parent_scope_function_level, 0); | 2538 new LocalScope(NULL, parent_scope_function_level, 0); |
2538 | 2539 |
2539 const intptr_t local_scope_function_level = 1; | 2540 const intptr_t local_scope_function_level = 1; |
2540 LocalScope* local_scope = | 2541 LocalScope* local_scope = |
2541 new LocalScope(parent_scope, local_scope_function_level, 0); | 2542 new LocalScope(parent_scope, local_scope_function_level, 0); |
2542 | 2543 |
2543 const Type& dynamic_type = Type::ZoneHandle(Type::DynamicType()); | 2544 const Type& dynamic_type = Type::ZoneHandle(Type::DynamicType()); |
2544 const String& a = String::ZoneHandle(Symbols::New("a")); | 2545 const String& a = String::ZoneHandle(Symbols::New(thread, "a")); |
2545 LocalVariable* var_a = | 2546 LocalVariable* var_a = |
2546 new LocalVariable(TokenPosition::kNoSource, a, dynamic_type); | 2547 new LocalVariable(TokenPosition::kNoSource, a, dynamic_type); |
2547 parent_scope->AddVariable(var_a); | 2548 parent_scope->AddVariable(var_a); |
2548 | 2549 |
2549 const String& b = String::ZoneHandle(Symbols::New("b")); | 2550 const String& b = String::ZoneHandle(Symbols::New(thread, "b")); |
2550 LocalVariable* var_b = | 2551 LocalVariable* var_b = |
2551 new LocalVariable(TokenPosition::kNoSource, b, dynamic_type); | 2552 new LocalVariable(TokenPosition::kNoSource, b, dynamic_type); |
2552 local_scope->AddVariable(var_b); | 2553 local_scope->AddVariable(var_b); |
2553 | 2554 |
2554 const String& c = String::ZoneHandle(Symbols::New("c")); | 2555 const String& c = String::ZoneHandle(Symbols::New(thread, "c")); |
2555 LocalVariable* var_c = | 2556 LocalVariable* var_c = |
2556 new LocalVariable(TokenPosition::kNoSource, c, dynamic_type); | 2557 new LocalVariable(TokenPosition::kNoSource, c, dynamic_type); |
2557 parent_scope->AddVariable(var_c); | 2558 parent_scope->AddVariable(var_c); |
2558 | 2559 |
2559 bool test_only = false; // Please, insert alias. | 2560 bool test_only = false; // Please, insert alias. |
2560 var_a = local_scope->LookupVariable(a, test_only); | 2561 var_a = local_scope->LookupVariable(a, test_only); |
2561 EXPECT(var_a->is_captured()); | 2562 EXPECT(var_a->is_captured()); |
2562 EXPECT_EQ(parent_scope_function_level, var_a->owner()->function_level()); | 2563 EXPECT_EQ(parent_scope_function_level, var_a->owner()->function_level()); |
2563 EXPECT(local_scope->LocalLookupVariable(a) == var_a); // Alias. | 2564 EXPECT(local_scope->LocalLookupVariable(a) == var_a); // Alias. |
2564 | 2565 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2613 var_c = outer_scope->LocalLookupVariable(c); | 2614 var_c = outer_scope->LocalLookupVariable(c); |
2614 EXPECT(var_c->is_captured()); | 2615 EXPECT(var_c->is_captured()); |
2615 EXPECT_EQ(1, var_c->index()); | 2616 EXPECT_EQ(1, var_c->index()); |
2616 EXPECT_EQ(parent_scope_context_level - local_scope_context_level, | 2617 EXPECT_EQ(parent_scope_context_level - local_scope_context_level, |
2617 var_c->owner()->context_level()); // Adjusted context level. | 2618 var_c->owner()->context_level()); // Adjusted context level. |
2618 } | 2619 } |
2619 | 2620 |
2620 | 2621 |
2621 VM_TEST_CASE(Closure) { | 2622 VM_TEST_CASE(Closure) { |
2622 // Allocate the class first. | 2623 // Allocate the class first. |
2623 const String& class_name = String::Handle(Symbols::New("MyClass")); | 2624 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); |
2624 const Script& script = Script::Handle(); | 2625 const Script& script = Script::Handle(); |
2625 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 2626 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
2626 const Array& functions = Array::Handle(Array::New(1)); | 2627 const Array& functions = Array::Handle(Array::New(1)); |
2627 | 2628 |
2628 const Context& context = Context::Handle(Context::New(0)); | 2629 const Context& context = Context::Handle(Context::New(0)); |
2629 Function& parent = Function::Handle(); | 2630 Function& parent = Function::Handle(); |
2630 const String& parent_name = String::Handle(Symbols::New("foo_papa")); | 2631 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); |
2631 parent = Function::New(parent_name, RawFunction::kRegularFunction, | 2632 parent = Function::New(parent_name, RawFunction::kRegularFunction, |
2632 false, false, false, false, false, cls, | 2633 false, false, false, false, false, cls, |
2633 TokenPosition::kMinSource); | 2634 TokenPosition::kMinSource); |
2634 functions.SetAt(0, parent); | 2635 functions.SetAt(0, parent); |
2635 cls.SetFunctions(functions); | 2636 cls.SetFunctions(functions); |
2636 | 2637 |
2637 Function& function = Function::Handle(); | 2638 Function& function = Function::Handle(); |
2638 const String& function_name = String::Handle(Symbols::New("foo")); | 2639 const String& function_name = String::Handle(Symbols::New(thread, "foo")); |
2639 function = Function::NewClosureFunction( | 2640 function = Function::NewClosureFunction( |
2640 function_name, parent, TokenPosition::kMinSource); | 2641 function_name, parent, TokenPosition::kMinSource); |
2641 const Closure& closure = Closure::Handle(Closure::New(function, context)); | 2642 const Closure& closure = Closure::Handle(Closure::New(function, context)); |
2642 const Class& closure_class = Class::Handle(closure.clazz()); | 2643 const Class& closure_class = Class::Handle(closure.clazz()); |
2643 EXPECT_EQ(closure_class.id(), kClosureCid); | 2644 EXPECT_EQ(closure_class.id(), kClosureCid); |
2644 const Function& closure_function = Function::Handle(closure.function()); | 2645 const Function& closure_function = Function::Handle(closure.function()); |
2645 EXPECT_EQ(closure_function.raw(), function.raw()); | 2646 EXPECT_EQ(closure_function.raw(), function.raw()); |
2646 const Context& closure_context = Context::Handle(closure.context()); | 2647 const Context& closure_context = Context::Handle(closure.context()); |
2647 EXPECT_EQ(closure_context.raw(), context.raw()); | 2648 EXPECT_EQ(closure_context.raw(), context.raw()); |
2648 } | 2649 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2683 str3 = String::New("Steep and Deep!"); | 2684 str3 = String::New("Steep and Deep!"); |
2684 EXPECT(str3.IsString()); | 2685 EXPECT(str3.IsString()); |
2685 EXPECT(str3.IsOneByteString()); | 2686 EXPECT(str3.IsOneByteString()); |
2686 str3 = OneByteString::null(); | 2687 str3 = OneByteString::null(); |
2687 EXPECT(str3.IsString()); | 2688 EXPECT(str3.IsString()); |
2688 EXPECT(!str3.IsOneByteString()); | 2689 EXPECT(!str3.IsOneByteString()); |
2689 } | 2690 } |
2690 | 2691 |
2691 | 2692 |
2692 static RawFunction* CreateFunction(const char* name) { | 2693 static RawFunction* CreateFunction(const char* name) { |
2693 const String& class_name = String::Handle(Symbols::New("ownerClass")); | 2694 Thread* thread = Thread::Current(); |
2694 const String& lib_name = String::Handle(Symbols::New("ownerLibrary")); | 2695 const String& class_name = String::Handle(Symbols::New(thread, "ownerClass")); |
| 2696 const String& lib_name = String::Handle(Symbols::New(thread, "ownerLibrary")); |
2695 const Script& script = Script::Handle(); | 2697 const Script& script = Script::Handle(); |
2696 const Class& owner_class = | 2698 const Class& owner_class = |
2697 Class::Handle(CreateDummyClass(class_name, script)); | 2699 Class::Handle(CreateDummyClass(class_name, script)); |
2698 const Library& owner_library = | 2700 const Library& owner_library = |
2699 Library::Handle(CreateDummyLibrary(lib_name)); | 2701 Library::Handle(CreateDummyLibrary(lib_name)); |
2700 owner_class.set_library(owner_library); | 2702 owner_class.set_library(owner_library); |
2701 const String& function_name = String::ZoneHandle(Symbols::New(name)); | 2703 const String& function_name = String::ZoneHandle(Symbols::New(thread, name)); |
2702 return Function::New(function_name, RawFunction::kRegularFunction, | 2704 return Function::New(function_name, RawFunction::kRegularFunction, |
2703 true, false, false, false, false, owner_class, | 2705 true, false, false, false, false, owner_class, |
2704 TokenPosition::kMinSource); | 2706 TokenPosition::kMinSource); |
2705 } | 2707 } |
2706 | 2708 |
2707 | 2709 |
2708 // Test for Code and Instruction object creation. | 2710 // Test for Code and Instruction object creation. |
2709 VM_TEST_CASE(Code) { | 2711 VM_TEST_CASE(Code) { |
2710 extern void GenerateIncrement(Assembler* assembler); | 2712 extern void GenerateIncrement(Assembler* assembler); |
2711 Assembler _assembler_; | 2713 Assembler _assembler_; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2960 EXPECT_EQ(3, iter.TryIndex()); | 2962 EXPECT_EQ(3, iter.TryIndex()); |
2961 EXPECT_EQ(static_cast<uword>(800), iter.PcOffset()); | 2963 EXPECT_EQ(static_cast<uword>(800), iter.PcOffset()); |
2962 EXPECT_EQ(150, iter.TokenPos().value()); | 2964 EXPECT_EQ(150, iter.TokenPos().value()); |
2963 EXPECT_EQ(RawPcDescriptors::kOther, iter.Kind()); | 2965 EXPECT_EQ(RawPcDescriptors::kOther, iter.Kind()); |
2964 | 2966 |
2965 EXPECT_EQ(false, iter.MoveNext()); | 2967 EXPECT_EQ(false, iter.MoveNext()); |
2966 } | 2968 } |
2967 | 2969 |
2968 | 2970 |
2969 static RawClass* CreateTestClass(const char* name) { | 2971 static RawClass* CreateTestClass(const char* name) { |
2970 const String& class_name = String::Handle(Symbols::New(name)); | 2972 const String& class_name = String::Handle(Symbols::New(Thread::Current(), |
| 2973 name)); |
2971 const Class& cls = Class::Handle( | 2974 const Class& cls = Class::Handle( |
2972 CreateDummyClass(class_name, Script::Handle())); | 2975 CreateDummyClass(class_name, Script::Handle())); |
2973 return cls.raw(); | 2976 return cls.raw(); |
2974 } | 2977 } |
2975 | 2978 |
2976 | 2979 |
2977 static RawField* CreateTestField(const char* name) { | 2980 static RawField* CreateTestField(const char* name) { |
2978 const Class& cls = Class::Handle(CreateTestClass("global:")); | 2981 const Class& cls = Class::Handle(CreateTestClass("global:")); |
2979 const String& field_name = String::Handle(Symbols::New(name)); | 2982 const String& field_name = String::Handle(Symbols::New(Thread::Current(), |
| 2983 name)); |
2980 const Field& field = | 2984 const Field& field = |
2981 Field::Handle(Field::New(field_name, true, false, false, true, cls, | 2985 Field::Handle(Field::New(field_name, true, false, false, true, cls, |
2982 Object::dynamic_type(), TokenPosition::kMinSource)); | 2986 Object::dynamic_type(), TokenPosition::kMinSource)); |
2983 return field.raw(); | 2987 return field.raw(); |
2984 } | 2988 } |
2985 | 2989 |
2986 | 2990 |
2987 VM_TEST_CASE(ClassDictionaryIterator) { | 2991 VM_TEST_CASE(ClassDictionaryIterator) { |
2988 Class& ae66 = Class::ZoneHandle(CreateTestClass("Ae6/6")); | 2992 Class& ae66 = Class::ZoneHandle(CreateTestClass("Ae6/6")); |
2989 Class& re44 = Class::ZoneHandle(CreateTestClass("Re4/4")); | 2993 Class& re44 = Class::ZoneHandle(CreateTestClass("Re4/4")); |
(...skipping 11 matching lines...) Expand all Loading... |
3001 while (iterator.HasNext()) { | 3005 while (iterator.HasNext()) { |
3002 cls = iterator.GetNextClass(); | 3006 cls = iterator.GetNextClass(); |
3003 EXPECT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw())); | 3007 EXPECT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw())); |
3004 count++; | 3008 count++; |
3005 } | 3009 } |
3006 EXPECT(count == 2); | 3010 EXPECT(count == 2); |
3007 } | 3011 } |
3008 | 3012 |
3009 | 3013 |
3010 static RawFunction* GetDummyTarget(const char* name) { | 3014 static RawFunction* GetDummyTarget(const char* name) { |
3011 const String& function_name = String::Handle(Symbols::New(name)); | 3015 const String& function_name = String::Handle(Symbols::New(Thread::Current(), |
| 3016 name)); |
3012 const Class& cls = Class::Handle( | 3017 const Class& cls = Class::Handle( |
3013 CreateDummyClass(function_name, Script::Handle())); | 3018 CreateDummyClass(function_name, Script::Handle())); |
3014 const bool is_static = false; | 3019 const bool is_static = false; |
3015 const bool is_const = false; | 3020 const bool is_const = false; |
3016 const bool is_abstract = false; | 3021 const bool is_abstract = false; |
3017 const bool is_external = false; | 3022 const bool is_external = false; |
3018 const bool is_native = false; | 3023 const bool is_native = false; |
3019 return Function::New(function_name, | 3024 return Function::New(function_name, |
3020 RawFunction::kRegularFunction, | 3025 RawFunction::kRegularFunction, |
3021 is_static, | 3026 is_static, |
3022 is_const, | 3027 is_const, |
3023 is_abstract, | 3028 is_abstract, |
3024 is_external, | 3029 is_external, |
3025 is_native, | 3030 is_native, |
3026 cls, | 3031 cls, |
3027 TokenPosition::kMinSource); | 3032 TokenPosition::kMinSource); |
3028 } | 3033 } |
3029 | 3034 |
3030 | 3035 |
3031 VM_TEST_CASE(ICData) { | 3036 VM_TEST_CASE(ICData) { |
3032 Function& function = Function::Handle(GetDummyTarget("Bern")); | 3037 Function& function = Function::Handle(GetDummyTarget("Bern")); |
3033 const intptr_t id = 12; | 3038 const intptr_t id = 12; |
3034 const intptr_t num_args_tested = 1; | 3039 const intptr_t num_args_tested = 1; |
3035 const String& target_name = String::Handle(Symbols::New("Thun")); | 3040 const String& target_name = String::Handle(Symbols::New(thread, "Thun")); |
3036 const Array& args_descriptor = | 3041 const Array& args_descriptor = |
3037 Array::Handle(ArgumentsDescriptor::New(1, Object::null_array())); | 3042 Array::Handle(ArgumentsDescriptor::New(1, Object::null_array())); |
3038 ICData& o1 = ICData::Handle(); | 3043 ICData& o1 = ICData::Handle(); |
3039 o1 = ICData::New(function, target_name, args_descriptor, id, num_args_tested); | 3044 o1 = ICData::New(function, target_name, args_descriptor, id, num_args_tested); |
3040 EXPECT_EQ(1, o1.NumArgsTested()); | 3045 EXPECT_EQ(1, o1.NumArgsTested()); |
3041 EXPECT_EQ(id, o1.deopt_id()); | 3046 EXPECT_EQ(id, o1.deopt_id()); |
3042 EXPECT_EQ(function.raw(), o1.Owner()); | 3047 EXPECT_EQ(function.raw(), o1.Owner()); |
3043 EXPECT_EQ(0, o1.NumberOfChecks()); | 3048 EXPECT_EQ(0, o1.NumberOfChecks()); |
3044 EXPECT_EQ(target_name.raw(), o1.target_name()); | 3049 EXPECT_EQ(target_name.raw(), o1.target_name()); |
3045 EXPECT_EQ(args_descriptor.raw(), o1.arguments_descriptor()); | 3050 EXPECT_EQ(args_descriptor.raw(), o1.arguments_descriptor()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3094 // Check ICData for unoptimized static calls. | 3099 // Check ICData for unoptimized static calls. |
3095 const intptr_t kNumArgsChecked = 0; | 3100 const intptr_t kNumArgsChecked = 0; |
3096 const ICData& scall_icdata = ICData::Handle( | 3101 const ICData& scall_icdata = ICData::Handle( |
3097 ICData::New(function, target_name, args_descriptor, 57, kNumArgsChecked)); | 3102 ICData::New(function, target_name, args_descriptor, 57, kNumArgsChecked)); |
3098 scall_icdata.AddTarget(target1); | 3103 scall_icdata.AddTarget(target1); |
3099 EXPECT_EQ(target1.raw(), scall_icdata.GetTargetAt(0)); | 3104 EXPECT_EQ(target1.raw(), scall_icdata.GetTargetAt(0)); |
3100 } | 3105 } |
3101 | 3106 |
3102 | 3107 |
3103 VM_TEST_CASE(SubtypeTestCache) { | 3108 VM_TEST_CASE(SubtypeTestCache) { |
3104 String& class_name = String::Handle(Symbols::New("EmptyClass")); | 3109 String& class_name = String::Handle(Symbols::New(thread, "EmptyClass")); |
3105 Script& script = Script::Handle(); | 3110 Script& script = Script::Handle(); |
3106 const Class& empty_class = | 3111 const Class& empty_class = |
3107 Class::Handle(CreateDummyClass(class_name, script)); | 3112 Class::Handle(CreateDummyClass(class_name, script)); |
3108 SubtypeTestCache& cache = SubtypeTestCache::Handle(SubtypeTestCache::New()); | 3113 SubtypeTestCache& cache = SubtypeTestCache::Handle(SubtypeTestCache::New()); |
3109 EXPECT(!cache.IsNull()); | 3114 EXPECT(!cache.IsNull()); |
3110 EXPECT_EQ(0, cache.NumberOfChecks()); | 3115 EXPECT_EQ(0, cache.NumberOfChecks()); |
3111 const Object& class_id_or_fun = Object::Handle(Smi::New(empty_class.id())); | 3116 const Object& class_id_or_fun = Object::Handle(Smi::New(empty_class.id())); |
3112 const TypeArguments& targ_0 = TypeArguments::Handle(TypeArguments::New(2)); | 3117 const TypeArguments& targ_0 = TypeArguments::Handle(TypeArguments::New(2)); |
3113 const TypeArguments& targ_1 = TypeArguments::Handle(TypeArguments::New(3)); | 3118 const TypeArguments& targ_1 = TypeArguments::Handle(TypeArguments::New(3)); |
3114 cache.AddCheck(class_id_or_fun, targ_0, targ_1, Bool::True()); | 3119 cache.AddCheck(class_id_or_fun, targ_0, targ_1, Bool::True()); |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3774 static RawField* GetField(const Class& cls, const char* name) { | 3779 static RawField* GetField(const Class& cls, const char* name) { |
3775 const Field& field = | 3780 const Field& field = |
3776 Field::Handle(cls.LookupField(String::Handle(String::New(name)))); | 3781 Field::Handle(cls.LookupField(String::Handle(String::New(name)))); |
3777 EXPECT(!field.IsNull()); | 3782 EXPECT(!field.IsNull()); |
3778 return field.raw(); | 3783 return field.raw(); |
3779 } | 3784 } |
3780 | 3785 |
3781 | 3786 |
3782 static RawClass* GetClass(const Library& lib, const char* name) { | 3787 static RawClass* GetClass(const Library& lib, const char* name) { |
3783 const Class& cls = Class::Handle( | 3788 const Class& cls = Class::Handle( |
3784 lib.LookupClass(String::Handle(Symbols::New(name)))); | 3789 lib.LookupClass(String::Handle(Symbols::New(Thread::Current(), name)))); |
3785 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 3790 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
3786 return cls.raw(); | 3791 return cls.raw(); |
3787 } | 3792 } |
3788 | 3793 |
3789 | 3794 |
3790 VM_TEST_CASE(FindClosureIndex) { | 3795 VM_TEST_CASE(FindClosureIndex) { |
3791 // Allocate the class first. | 3796 // Allocate the class first. |
3792 const String& class_name = String::Handle(Symbols::New("MyClass")); | 3797 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); |
3793 const Script& script = Script::Handle(); | 3798 const Script& script = Script::Handle(); |
3794 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 3799 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
3795 const Array& functions = Array::Handle(Array::New(1)); | 3800 const Array& functions = Array::Handle(Array::New(1)); |
3796 const Isolate* iso = Isolate::Current(); | 3801 const Isolate* iso = Isolate::Current(); |
3797 | 3802 |
3798 Function& parent = Function::Handle(); | 3803 Function& parent = Function::Handle(); |
3799 const String& parent_name = String::Handle(Symbols::New("foo_papa")); | 3804 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); |
3800 parent = Function::New(parent_name, RawFunction::kRegularFunction, | 3805 parent = Function::New(parent_name, RawFunction::kRegularFunction, |
3801 false, false, false, false, false, cls, | 3806 false, false, false, false, false, cls, |
3802 TokenPosition::kMinSource); | 3807 TokenPosition::kMinSource); |
3803 functions.SetAt(0, parent); | 3808 functions.SetAt(0, parent); |
3804 cls.SetFunctions(functions); | 3809 cls.SetFunctions(functions); |
3805 | 3810 |
3806 Function& function = Function::Handle(); | 3811 Function& function = Function::Handle(); |
3807 const String& function_name = String::Handle(Symbols::New("foo")); | 3812 const String& function_name = String::Handle(Symbols::New(thread, "foo")); |
3808 function = Function::NewClosureFunction(function_name, parent, | 3813 function = Function::NewClosureFunction(function_name, parent, |
3809 TokenPosition::kMinSource); | 3814 TokenPosition::kMinSource); |
3810 // Add closure function to class. | 3815 // Add closure function to class. |
3811 iso->AddClosureFunction(function); | 3816 iso->AddClosureFunction(function); |
3812 | 3817 |
3813 // The closure should return a valid index. | 3818 // The closure should return a valid index. |
3814 intptr_t good_closure_index = iso->FindClosureIndex(function); | 3819 intptr_t good_closure_index = iso->FindClosureIndex(function); |
3815 EXPECT_GE(good_closure_index, 0); | 3820 EXPECT_GE(good_closure_index, 0); |
3816 // The parent function should return an invalid index. | 3821 // The parent function should return an invalid index. |
3817 intptr_t bad_closure_index = iso->FindClosureIndex(parent); | 3822 intptr_t bad_closure_index = iso->FindClosureIndex(parent); |
3818 EXPECT_EQ(bad_closure_index, -1); | 3823 EXPECT_EQ(bad_closure_index, -1); |
3819 | 3824 |
3820 // Retrieve closure function via index. | 3825 // Retrieve closure function via index. |
3821 Function& func_from_index = Function::Handle(); | 3826 Function& func_from_index = Function::Handle(); |
3822 func_from_index ^= iso->ClosureFunctionFromIndex(good_closure_index); | 3827 func_from_index ^= iso->ClosureFunctionFromIndex(good_closure_index); |
3823 // Same closure function. | 3828 // Same closure function. |
3824 EXPECT_EQ(func_from_index.raw(), function.raw()); | 3829 EXPECT_EQ(func_from_index.raw(), function.raw()); |
3825 } | 3830 } |
3826 | 3831 |
3827 | 3832 |
3828 VM_TEST_CASE(FindInvocationDispatcherFunctionIndex) { | 3833 VM_TEST_CASE(FindInvocationDispatcherFunctionIndex) { |
3829 const String& class_name = String::Handle(Symbols::New("MyClass")); | 3834 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); |
3830 const Script& script = Script::Handle(); | 3835 const Script& script = Script::Handle(); |
3831 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 3836 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
3832 ClassFinalizer::FinalizeTypesInClass(cls); | 3837 ClassFinalizer::FinalizeTypesInClass(cls); |
3833 | 3838 |
3834 const Array& functions = Array::Handle(Array::New(1)); | 3839 const Array& functions = Array::Handle(Array::New(1)); |
3835 Function& parent = Function::Handle(); | 3840 Function& parent = Function::Handle(); |
3836 const String& parent_name = String::Handle(Symbols::New("foo_papa")); | 3841 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); |
3837 parent = Function::New(parent_name, RawFunction::kRegularFunction, | 3842 parent = Function::New(parent_name, RawFunction::kRegularFunction, |
3838 false, false, false, false, false, cls, | 3843 false, false, false, false, false, cls, |
3839 TokenPosition::kMinSource); | 3844 TokenPosition::kMinSource); |
3840 functions.SetAt(0, parent); | 3845 functions.SetAt(0, parent); |
3841 cls.SetFunctions(functions); | 3846 cls.SetFunctions(functions); |
3842 cls.Finalize(); | 3847 cls.Finalize(); |
3843 | 3848 |
3844 // Add invocation dispatcher. | 3849 // Add invocation dispatcher. |
3845 const String& invocation_dispatcher_name = | 3850 const String& invocation_dispatcher_name = |
3846 String::Handle(Symbols::New("myMethod")); | 3851 String::Handle(Symbols::New(thread, "myMethod")); |
3847 const Array& args_desc = Array::Handle(ArgumentsDescriptor::New(1)); | 3852 const Array& args_desc = Array::Handle(ArgumentsDescriptor::New(1)); |
3848 Function& invocation_dispatcher = Function::Handle(); | 3853 Function& invocation_dispatcher = Function::Handle(); |
3849 invocation_dispatcher ^= | 3854 invocation_dispatcher ^= |
3850 cls.GetInvocationDispatcher(invocation_dispatcher_name, args_desc, | 3855 cls.GetInvocationDispatcher(invocation_dispatcher_name, args_desc, |
3851 RawFunction::kNoSuchMethodDispatcher, | 3856 RawFunction::kNoSuchMethodDispatcher, |
3852 true /* create_if_absent */); | 3857 true /* create_if_absent */); |
3853 EXPECT(!invocation_dispatcher.IsNull()); | 3858 EXPECT(!invocation_dispatcher.IsNull()); |
3854 // Get index to function. | 3859 // Get index to function. |
3855 intptr_t invocation_dispatcher_index = | 3860 intptr_t invocation_dispatcher_index = |
3856 cls.FindInvocationDispatcherFunctionIndex(invocation_dispatcher); | 3861 cls.FindInvocationDispatcherFunctionIndex(invocation_dispatcher); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3937 PrintMetadata("Meta", res); | 3942 PrintMetadata("Meta", res); |
3938 | 3943 |
3939 Field& field = Field::Handle(GetField(class_a, "aField")); | 3944 Field& field = Field::Handle(GetField(class_a, "aField")); |
3940 res = lib.GetMetadata(field); | 3945 res = lib.GetMetadata(field); |
3941 PrintMetadata("A.aField", res); | 3946 PrintMetadata("A.aField", res); |
3942 | 3947 |
3943 Function& func = Function::Handle(GetFunction(class_a, "aFunc")); | 3948 Function& func = Function::Handle(GetFunction(class_a, "aFunc")); |
3944 res = lib.GetMetadata(func); | 3949 res = lib.GetMetadata(func); |
3945 PrintMetadata("A.aFunc", res); | 3950 PrintMetadata("A.aFunc", res); |
3946 | 3951 |
3947 func = lib.LookupLocalFunction(String::Handle(Symbols::New("main"))); | 3952 func = lib.LookupLocalFunction(String::Handle(Symbols::New(thread, "main"))); |
3948 EXPECT(!func.IsNull()); | 3953 EXPECT(!func.IsNull()); |
3949 res = lib.GetMetadata(func); | 3954 res = lib.GetMetadata(func); |
3950 PrintMetadata("main", res); | 3955 PrintMetadata("main", res); |
3951 | 3956 |
3952 func = lib.LookupLocalFunction(String::Handle(Symbols::New("get:tlGetter"))); | 3957 func = lib.LookupLocalFunction(String::Handle(Symbols::New(thread, |
| 3958 "get:tlGetter"))); |
3953 EXPECT(!func.IsNull()); | 3959 EXPECT(!func.IsNull()); |
3954 res = lib.GetMetadata(func); | 3960 res = lib.GetMetadata(func); |
3955 PrintMetadata("tlGetter", res); | 3961 PrintMetadata("tlGetter", res); |
3956 | 3962 |
3957 field = lib.LookupLocalField(String::Handle(Symbols::New("gVar"))); | 3963 field = lib.LookupLocalField(String::Handle(Symbols::New(thread, "gVar"))); |
3958 EXPECT(!field.IsNull()); | 3964 EXPECT(!field.IsNull()); |
3959 res = lib.GetMetadata(field); | 3965 res = lib.GetMetadata(field); |
3960 PrintMetadata("gVar", res); | 3966 PrintMetadata("gVar", res); |
3961 } | 3967 } |
3962 | 3968 |
3963 | 3969 |
3964 TEST_CASE(FunctionSourceFingerprint) { | 3970 TEST_CASE(FunctionSourceFingerprint) { |
3965 const char* kScriptChars = | 3971 const char* kScriptChars = |
3966 "class A {\n" | 3972 "class A {\n" |
3967 " static void test1(int a) {\n" | 3973 " static void test1(int a) {\n" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3999 " return a > 1 ? a + 1 : a;\n" | 4005 " return a > 1 ? a + 1 : a;\n" |
4000 " }\n" | 4006 " }\n" |
4001 "}"; | 4007 "}"; |
4002 TestCase::LoadTestScript(kScriptChars, NULL); | 4008 TestCase::LoadTestScript(kScriptChars, NULL); |
4003 EXPECT(ClassFinalizer::ProcessPendingClasses()); | 4009 EXPECT(ClassFinalizer::ProcessPendingClasses()); |
4004 const String& name = String::Handle(String::New(TestCase::url())); | 4010 const String& name = String::Handle(String::New(TestCase::url())); |
4005 const Library& lib = Library::Handle(Library::LookupLibrary(name)); | 4011 const Library& lib = Library::Handle(Library::LookupLibrary(name)); |
4006 EXPECT(!lib.IsNull()); | 4012 EXPECT(!lib.IsNull()); |
4007 | 4013 |
4008 const Class& class_a = Class::Handle( | 4014 const Class& class_a = Class::Handle( |
4009 lib.LookupClass(String::Handle(Symbols::New("A")))); | 4015 lib.LookupClass(String::Handle(Symbols::New(thread, "A")))); |
4010 const Class& class_b = Class::Handle( | 4016 const Class& class_b = Class::Handle( |
4011 lib.LookupClass(String::Handle(Symbols::New("B")))); | 4017 lib.LookupClass(String::Handle(Symbols::New(thread, "B")))); |
4012 const Function& a_test1 = | 4018 const Function& a_test1 = |
4013 Function::Handle(GetStaticFunction(class_a, "test1")); | 4019 Function::Handle(GetStaticFunction(class_a, "test1")); |
4014 const Function& b_test1 = | 4020 const Function& b_test1 = |
4015 Function::Handle(GetStaticFunction(class_b, "test1")); | 4021 Function::Handle(GetStaticFunction(class_b, "test1")); |
4016 const Function& a_test2 = | 4022 const Function& a_test2 = |
4017 Function::Handle(GetStaticFunction(class_a, "test2")); | 4023 Function::Handle(GetStaticFunction(class_a, "test2")); |
4018 const Function& a_test3 = | 4024 const Function& a_test3 = |
4019 Function::Handle(GetStaticFunction(class_a, "test3")); | 4025 Function::Handle(GetStaticFunction(class_a, "test3")); |
4020 const Function& a_test4 = | 4026 const Function& a_test4 = |
4021 Function::Handle(GetStaticFunction(class_a, "test4")); | 4027 Function::Handle(GetStaticFunction(class_a, "test4")); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4063 | 4069 |
4064 // Run function A.b one time. | 4070 // Run function A.b one time. |
4065 Dart_Handle result = Dart_Invoke(lib, NewString("test"), 0, NULL); | 4071 Dart_Handle result = Dart_Invoke(lib, NewString("test"), 0, NULL); |
4066 EXPECT_VALID(result); | 4072 EXPECT_VALID(result); |
4067 | 4073 |
4068 // With no breakpoint, function A.b is inlineable. | 4074 // With no breakpoint, function A.b is inlineable. |
4069 const String& name = String::Handle(String::New(TestCase::url())); | 4075 const String& name = String::Handle(String::New(TestCase::url())); |
4070 const Library& vmlib = Library::Handle(Library::LookupLibrary(name)); | 4076 const Library& vmlib = Library::Handle(Library::LookupLibrary(name)); |
4071 EXPECT(!vmlib.IsNull()); | 4077 EXPECT(!vmlib.IsNull()); |
4072 const Class& class_a = Class::Handle( | 4078 const Class& class_a = Class::Handle( |
4073 vmlib.LookupClass(String::Handle(Symbols::New("A")))); | 4079 vmlib.LookupClass(String::Handle(Symbols::New(thread, "A")))); |
4074 const Function& func_b = | 4080 const Function& func_b = |
4075 Function::Handle(GetFunction(class_a, "b")); | 4081 Function::Handle(GetFunction(class_a, "b")); |
4076 EXPECT(func_b.CanBeInlined()); | 4082 EXPECT(func_b.CanBeInlined()); |
4077 | 4083 |
4078 // After setting a breakpoint in a function A.b, it is no longer inlineable. | 4084 // After setting a breakpoint in a function A.b, it is no longer inlineable. |
4079 Breakpoint* bpt = | 4085 Breakpoint* bpt = |
4080 Isolate::Current()->debugger()->SetBreakpointAtLine(name, | 4086 Isolate::Current()->debugger()->SetBreakpointAtLine(name, |
4081 kBreakpointLine); | 4087 kBreakpointLine); |
4082 ASSERT(bpt != NULL); | 4088 ASSERT(bpt != NULL); |
4083 EXPECT(!func_b.CanBeInlined()); | 4089 EXPECT(!func_b.CanBeInlined()); |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4604 object = iterator.CurrentKey(); | 4610 object = iterator.CurrentKey(); |
4605 EXPECT_STREQ("z", object.ToCString()); | 4611 EXPECT_STREQ("z", object.ToCString()); |
4606 object = iterator.CurrentValue(); | 4612 object = iterator.CurrentValue(); |
4607 EXPECT_STREQ("5", object.ToCString()); | 4613 EXPECT_STREQ("5", object.ToCString()); |
4608 | 4614 |
4609 EXPECT(!iterator.MoveNext()); | 4615 EXPECT(!iterator.MoveNext()); |
4610 } | 4616 } |
4611 | 4617 |
4612 | 4618 |
4613 static void CheckConcatAll(const String* data[], intptr_t n) { | 4619 static void CheckConcatAll(const String* data[], intptr_t n) { |
4614 Zone* zone = Thread::Current()->zone(); | 4620 Thread* thread = Thread::Current(); |
| 4621 Zone* zone = thread->zone(); |
4615 GrowableHandlePtrArray<const String> pieces(zone, n); | 4622 GrowableHandlePtrArray<const String> pieces(zone, n); |
4616 const Array& array = Array::Handle(zone, Array::New(n)); | 4623 const Array& array = Array::Handle(zone, Array::New(n)); |
4617 for (int i = 0; i < n; i++) { | 4624 for (int i = 0; i < n; i++) { |
4618 pieces.Add(*data[i]); | 4625 pieces.Add(*data[i]); |
4619 array.SetAt(i, *data[i]); | 4626 array.SetAt(i, *data[i]); |
4620 } | 4627 } |
4621 const String& res1 = String::Handle(zone, Symbols::FromConcatAll(pieces)); | 4628 const String& res1 = String::Handle(zone, Symbols::FromConcatAll(thread, |
| 4629 pieces)); |
4622 const String& res2 = String::Handle(zone, String::ConcatAll(array)); | 4630 const String& res2 = String::Handle(zone, String::ConcatAll(array)); |
4623 EXPECT(res1.Equals(res2)); | 4631 EXPECT(res1.Equals(res2)); |
4624 } | 4632 } |
4625 | 4633 |
4626 | 4634 |
4627 VM_TEST_CASE(Symbols_FromConcatAll) { | 4635 VM_TEST_CASE(Symbols_FromConcatAll) { |
4628 { | 4636 { |
4629 const String* data[3] = { &Symbols::FallThroughError(), | 4637 const String* data[3] = { &Symbols::FallThroughError(), |
4630 &Symbols::Dot(), | 4638 &Symbols::Dot(), |
4631 &Symbols::isPaused() }; | 4639 &Symbols::isPaused() }; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4715 String& test = String::Handle(); | 4723 String& test = String::Handle(); |
4716 String& result = String::Handle(); | 4724 String& result = String::Handle(); |
4717 for (size_t i = 0; i < ARRAY_SIZE(tests); i++) { | 4725 for (size_t i = 0; i < ARRAY_SIZE(tests); i++) { |
4718 test = String::New(tests[i].in); | 4726 test = String::New(tests[i].in); |
4719 result = String::ScrubName(test); | 4727 result = String::ScrubName(test); |
4720 EXPECT_STREQ(tests[i].out, result.ToCString()); | 4728 EXPECT_STREQ(tests[i].out, result.ToCString()); |
4721 } | 4729 } |
4722 } | 4730 } |
4723 | 4731 |
4724 } // namespace dart | 4732 } // namespace dart |
OLD | NEW |