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/code_descriptors.h" |
9 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_entry.h" | 11 #include "vm/dart_entry.h" |
11 #include "vm/debugger.h" | 12 #include "vm/debugger.h" |
12 #include "vm/isolate.h" | 13 #include "vm/isolate.h" |
13 #include "vm/malloc_hooks.h" | 14 #include "vm/malloc_hooks.h" |
14 #include "vm/object.h" | 15 #include "vm/object.h" |
15 #include "vm/object_store.h" | 16 #include "vm/object_store.h" |
16 #include "vm/simulator.h" | 17 #include "vm/simulator.h" |
17 #include "vm/symbols.h" | 18 #include "vm/symbols.h" |
18 #include "vm/unit_test.h" | 19 #include "vm/unit_test.h" |
19 #include "vm/code_descriptors.h" | |
20 | 20 |
21 namespace dart { | 21 namespace dart { |
22 | 22 |
23 DECLARE_FLAG(bool, write_protect_code); | 23 DECLARE_FLAG(bool, write_protect_code); |
24 | 24 |
25 | |
26 static RawClass* CreateDummyClass(const String& class_name, | 25 static RawClass* CreateDummyClass(const String& class_name, |
27 const Script& script) { | 26 const Script& script) { |
28 const Class& cls = Class::Handle(Class::New( | 27 const Class& cls = Class::Handle(Class::New( |
29 Library::Handle(), class_name, script, TokenPosition::kNoSource)); | 28 Library::Handle(), class_name, script, TokenPosition::kNoSource)); |
30 cls.set_is_synthesized_class(); // Dummy class for testing. | 29 cls.set_is_synthesized_class(); // Dummy class for testing. |
31 return cls.raw(); | 30 return cls.raw(); |
32 } | 31 } |
33 | 32 |
34 | |
35 ISOLATE_UNIT_TEST_CASE(Class) { | 33 ISOLATE_UNIT_TEST_CASE(Class) { |
36 // Allocate the class first. | 34 // Allocate the class first. |
37 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); | 35 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); |
38 const Script& script = Script::Handle(); | 36 const Script& script = Script::Handle(); |
39 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 37 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
40 | 38 |
41 // Class has no fields and no functions yet. | 39 // Class has no fields and no functions yet. |
42 EXPECT_EQ(Array::Handle(cls.fields()).Length(), 0); | 40 EXPECT_EQ(Array::Handle(cls.fields()).Length(), 0); |
43 EXPECT_EQ(Array::Handle(cls.functions()).Length(), 0); | 41 EXPECT_EQ(Array::Handle(cls.functions()).Length(), 0); |
44 | 42 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 EXPECT_EQ(0, function.num_fixed_parameters()); | 130 EXPECT_EQ(0, function.num_fixed_parameters()); |
133 EXPECT(!function.HasOptionalParameters()); | 131 EXPECT(!function.HasOptionalParameters()); |
134 | 132 |
135 function_name = String::New("bar"); | 133 function_name = String::New("bar"); |
136 function = cls.LookupDynamicFunction(function_name); | 134 function = cls.LookupDynamicFunction(function_name); |
137 EXPECT(!function.IsNull()); | 135 EXPECT(!function.IsNull()); |
138 EXPECT_EQ(kNumFixedParameters, function.num_fixed_parameters()); | 136 EXPECT_EQ(kNumFixedParameters, function.num_fixed_parameters()); |
139 EXPECT_EQ(kNumOptionalParameters, function.NumOptionalParameters()); | 137 EXPECT_EQ(kNumOptionalParameters, function.NumOptionalParameters()); |
140 } | 138 } |
141 | 139 |
142 | |
143 ISOLATE_UNIT_TEST_CASE(TypeArguments) { | 140 ISOLATE_UNIT_TEST_CASE(TypeArguments) { |
144 const Type& type1 = Type::Handle(Type::Double()); | 141 const Type& type1 = Type::Handle(Type::Double()); |
145 const Type& type2 = Type::Handle(Type::StringType()); | 142 const Type& type2 = Type::Handle(Type::StringType()); |
146 const TypeArguments& type_arguments1 = | 143 const TypeArguments& type_arguments1 = |
147 TypeArguments::Handle(TypeArguments::New(2)); | 144 TypeArguments::Handle(TypeArguments::New(2)); |
148 type_arguments1.SetTypeAt(0, type1); | 145 type_arguments1.SetTypeAt(0, type1); |
149 type_arguments1.SetTypeAt(1, type2); | 146 type_arguments1.SetTypeAt(1, type2); |
150 const TypeArguments& type_arguments2 = | 147 const TypeArguments& type_arguments2 = |
151 TypeArguments::Handle(TypeArguments::New(2)); | 148 TypeArguments::Handle(TypeArguments::New(2)); |
152 type_arguments2.SetTypeAt(0, type1); | 149 type_arguments2.SetTypeAt(0, type1); |
153 type_arguments2.SetTypeAt(1, type2); | 150 type_arguments2.SetTypeAt(1, type2); |
154 EXPECT_NE(type_arguments1.raw(), type_arguments2.raw()); | 151 EXPECT_NE(type_arguments1.raw(), type_arguments2.raw()); |
155 OS::Print("1: %s\n", type_arguments1.ToCString()); | 152 OS::Print("1: %s\n", type_arguments1.ToCString()); |
156 OS::Print("2: %s\n", type_arguments2.ToCString()); | 153 OS::Print("2: %s\n", type_arguments2.ToCString()); |
157 EXPECT(type_arguments1.Equals(type_arguments2)); | 154 EXPECT(type_arguments1.Equals(type_arguments2)); |
158 TypeArguments& type_arguments3 = TypeArguments::Handle(); | 155 TypeArguments& type_arguments3 = TypeArguments::Handle(); |
159 type_arguments1.Canonicalize(); | 156 type_arguments1.Canonicalize(); |
160 type_arguments3 ^= type_arguments2.Canonicalize(); | 157 type_arguments3 ^= type_arguments2.Canonicalize(); |
161 EXPECT_EQ(type_arguments1.raw(), type_arguments3.raw()); | 158 EXPECT_EQ(type_arguments1.raw(), type_arguments3.raw()); |
162 } | 159 } |
163 | 160 |
164 | |
165 ISOLATE_UNIT_TEST_CASE(TokenStream) { | 161 ISOLATE_UNIT_TEST_CASE(TokenStream) { |
166 Zone* zone = Thread::Current()->zone(); | 162 Zone* zone = Thread::Current()->zone(); |
167 String& source = String::Handle(zone, String::New("= ( 9 , .")); | 163 String& source = String::Handle(zone, String::New("= ( 9 , .")); |
168 String& private_key = String::Handle(zone, String::New("")); | 164 String& private_key = String::Handle(zone, String::New("")); |
169 const TokenStream& token_stream = | 165 const TokenStream& token_stream = |
170 TokenStream::Handle(zone, TokenStream::New(source, private_key, false)); | 166 TokenStream::Handle(zone, TokenStream::New(source, private_key, false)); |
171 TokenStream::Iterator iterator(zone, token_stream, TokenPosition::kMinSource); | 167 TokenStream::Iterator iterator(zone, token_stream, TokenPosition::kMinSource); |
172 iterator.Advance(); // Advance to '(' token. | 168 iterator.Advance(); // Advance to '(' token. |
173 EXPECT_EQ(Token::kLPAREN, iterator.CurrentTokenKind()); | 169 EXPECT_EQ(Token::kLPAREN, iterator.CurrentTokenKind()); |
174 iterator.Advance(); | 170 iterator.Advance(); |
175 iterator.Advance(); | 171 iterator.Advance(); |
176 iterator.Advance(); // Advance to '.' token. | 172 iterator.Advance(); // Advance to '.' token. |
177 EXPECT_EQ(Token::kPERIOD, iterator.CurrentTokenKind()); | 173 EXPECT_EQ(Token::kPERIOD, iterator.CurrentTokenKind()); |
178 iterator.Advance(); // Advance to end of stream. | 174 iterator.Advance(); // Advance to end of stream. |
179 EXPECT_EQ(Token::kEOS, iterator.CurrentTokenKind()); | 175 EXPECT_EQ(Token::kEOS, iterator.CurrentTokenKind()); |
180 } | 176 } |
181 | 177 |
182 | |
183 ISOLATE_UNIT_TEST_CASE(GenerateExactSource) { | 178 ISOLATE_UNIT_TEST_CASE(GenerateExactSource) { |
184 // Verify the exact formatting of generated sources. | 179 // Verify the exact formatting of generated sources. |
185 const char* kScriptChars = | 180 const char* kScriptChars = |
186 "\n" | 181 "\n" |
187 "class A {\n" | 182 "class A {\n" |
188 " static bar() { return 42; }\n" | 183 " static bar() { return 42; }\n" |
189 " static fly() { return 5; }\n" | 184 " static fly() { return 5; }\n" |
190 " void catcher(x) {\n" | 185 " void catcher(x) {\n" |
191 " try {\n" | 186 " try {\n" |
192 " if (x is! List) {\n" | 187 " if (x is! List) {\n" |
(...skipping 18 matching lines...) Expand all Loading... |
211 String& url = String::Handle(String::New("dart-test:GenerateExactSource")); | 206 String& url = String::Handle(String::New("dart-test:GenerateExactSource")); |
212 String& source = String::Handle(String::New(kScriptChars)); | 207 String& source = String::Handle(String::New(kScriptChars)); |
213 Script& script = | 208 Script& script = |
214 Script::Handle(Script::New(url, source, RawScript::kScriptTag)); | 209 Script::Handle(Script::New(url, source, RawScript::kScriptTag)); |
215 script.Tokenize(String::Handle(String::New(""))); | 210 script.Tokenize(String::Handle(String::New(""))); |
216 const TokenStream& tokens = TokenStream::Handle(script.tokens()); | 211 const TokenStream& tokens = TokenStream::Handle(script.tokens()); |
217 const String& gen_source = String::Handle(tokens.GenerateSource()); | 212 const String& gen_source = String::Handle(tokens.GenerateSource()); |
218 EXPECT_STREQ(source.ToCString(), gen_source.ToCString()); | 213 EXPECT_STREQ(source.ToCString(), gen_source.ToCString()); |
219 } | 214 } |
220 | 215 |
221 | |
222 TEST_CASE(Class_ComputeEndTokenPos) { | 216 TEST_CASE(Class_ComputeEndTokenPos) { |
223 const char* kScript = | 217 const char* kScript = |
224 "\n" | 218 "\n" |
225 "class A {\n" | 219 "class A {\n" |
226 " /**\n" | 220 " /**\n" |
227 " * Description of foo().\n" | 221 " * Description of foo().\n" |
228 " */\n" | 222 " */\n" |
229 " foo(a) { return '''\"}'''; }\n" | 223 " foo(a) { return '''\"}'''; }\n" |
230 " // }\n" | 224 " // }\n" |
231 " var bar = '\\'}';\n" | 225 " var bar = '\\'}';\n" |
232 " var baz = \"${foo('}')}\";\n" | 226 " var baz = \"${foo('}')}\";\n" |
233 "}\n"; | 227 "}\n"; |
234 Dart_Handle lib_h = TestCase::LoadTestScript(kScript, NULL); | 228 Dart_Handle lib_h = TestCase::LoadTestScript(kScript, NULL); |
235 EXPECT_VALID(lib_h); | 229 EXPECT_VALID(lib_h); |
236 Library& lib = Library::Handle(); | 230 Library& lib = Library::Handle(); |
237 lib ^= Api::UnwrapHandle(lib_h); | 231 lib ^= Api::UnwrapHandle(lib_h); |
238 EXPECT(!lib.IsNull()); | 232 EXPECT(!lib.IsNull()); |
239 const Class& cls = | 233 const Class& cls = |
240 Class::Handle(lib.LookupClass(String::Handle(String::New("A")))); | 234 Class::Handle(lib.LookupClass(String::Handle(String::New("A")))); |
241 EXPECT(!cls.IsNull()); | 235 EXPECT(!cls.IsNull()); |
242 const TokenPosition end_token_pos = cls.ComputeEndTokenPos(); | 236 const TokenPosition end_token_pos = cls.ComputeEndTokenPos(); |
243 const Script& scr = Script::Handle(cls.script()); | 237 const Script& scr = Script::Handle(cls.script()); |
244 intptr_t line; | 238 intptr_t line; |
245 intptr_t col; | 239 intptr_t col; |
246 scr.GetTokenLocation(end_token_pos, &line, &col); | 240 scr.GetTokenLocation(end_token_pos, &line, &col); |
247 EXPECT(line == 10 && col == 1); | 241 EXPECT(line == 10 && col == 1); |
248 } | 242 } |
249 | 243 |
250 | |
251 ISOLATE_UNIT_TEST_CASE(InstanceClass) { | 244 ISOLATE_UNIT_TEST_CASE(InstanceClass) { |
252 // Allocate the class first. | 245 // Allocate the class first. |
253 String& class_name = String::Handle(Symbols::New(thread, "EmptyClass")); | 246 String& class_name = String::Handle(Symbols::New(thread, "EmptyClass")); |
254 Script& script = Script::Handle(); | 247 Script& script = Script::Handle(); |
255 const Class& empty_class = | 248 const Class& empty_class = |
256 Class::Handle(CreateDummyClass(class_name, script)); | 249 Class::Handle(CreateDummyClass(class_name, script)); |
257 | 250 |
258 // EmptyClass has no fields and no functions. | 251 // EmptyClass has no fields and no functions. |
259 EXPECT_EQ(Array::Handle(empty_class.fields()).Length(), 0); | 252 EXPECT_EQ(Array::Handle(empty_class.fields()).Length(), 0); |
260 EXPECT_EQ(Array::Handle(empty_class.functions()).Length(), 0); | 253 EXPECT_EQ(Array::Handle(empty_class.functions()).Length(), 0); |
(...skipping 25 matching lines...) Expand all Loading... |
286 one_field_class.Finalize(); | 279 one_field_class.Finalize(); |
287 intptr_t header_size = sizeof(RawObject); | 280 intptr_t header_size = sizeof(RawObject); |
288 EXPECT_EQ(Utils::RoundUp((header_size + (1 * kWordSize)), kObjectAlignment), | 281 EXPECT_EQ(Utils::RoundUp((header_size + (1 * kWordSize)), kObjectAlignment), |
289 one_field_class.instance_size()); | 282 one_field_class.instance_size()); |
290 EXPECT_EQ(header_size, field.Offset()); | 283 EXPECT_EQ(header_size, field.Offset()); |
291 EXPECT(!one_field_class.is_implemented()); | 284 EXPECT(!one_field_class.is_implemented()); |
292 one_field_class.set_is_implemented(); | 285 one_field_class.set_is_implemented(); |
293 EXPECT(one_field_class.is_implemented()); | 286 EXPECT(one_field_class.is_implemented()); |
294 } | 287 } |
295 | 288 |
296 | |
297 ISOLATE_UNIT_TEST_CASE(Smi) { | 289 ISOLATE_UNIT_TEST_CASE(Smi) { |
298 const Smi& smi = Smi::Handle(Smi::New(5)); | 290 const Smi& smi = Smi::Handle(Smi::New(5)); |
299 Object& smi_object = Object::Handle(smi.raw()); | 291 Object& smi_object = Object::Handle(smi.raw()); |
300 EXPECT(smi.IsSmi()); | 292 EXPECT(smi.IsSmi()); |
301 EXPECT(smi_object.IsSmi()); | 293 EXPECT(smi_object.IsSmi()); |
302 EXPECT_EQ(5, smi.Value()); | 294 EXPECT_EQ(5, smi.Value()); |
303 const Object& object = Object::Handle(); | 295 const Object& object = Object::Handle(); |
304 EXPECT(!object.IsSmi()); | 296 EXPECT(!object.IsSmi()); |
305 smi_object = Object::null(); | 297 smi_object = Object::null(); |
306 EXPECT(!smi_object.IsSmi()); | 298 EXPECT(!smi_object.IsSmi()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 339 |
348 Bigint& big1 = Bigint::Handle(Bigint::NewFromCString("10000000000000000000")); | 340 Bigint& big1 = Bigint::Handle(Bigint::NewFromCString("10000000000000000000")); |
349 Bigint& big2 = | 341 Bigint& big2 = |
350 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000")); | 342 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000")); |
351 EXPECT_EQ(-1, a.CompareWith(big1)); | 343 EXPECT_EQ(-1, a.CompareWith(big1)); |
352 EXPECT_EQ(1, a.CompareWith(big2)); | 344 EXPECT_EQ(1, a.CompareWith(big2)); |
353 EXPECT_EQ(-1, c.CompareWith(big1)); | 345 EXPECT_EQ(-1, c.CompareWith(big1)); |
354 EXPECT_EQ(1, c.CompareWith(big2)); | 346 EXPECT_EQ(1, c.CompareWith(big2)); |
355 } | 347 } |
356 | 348 |
357 | |
358 ISOLATE_UNIT_TEST_CASE(StringCompareTo) { | 349 ISOLATE_UNIT_TEST_CASE(StringCompareTo) { |
359 const String& abcd = String::Handle(String::New("abcd")); | 350 const String& abcd = String::Handle(String::New("abcd")); |
360 const String& abce = String::Handle(String::New("abce")); | 351 const String& abce = String::Handle(String::New("abce")); |
361 EXPECT_EQ(0, abcd.CompareTo(abcd)); | 352 EXPECT_EQ(0, abcd.CompareTo(abcd)); |
362 EXPECT_EQ(0, abce.CompareTo(abce)); | 353 EXPECT_EQ(0, abce.CompareTo(abce)); |
363 EXPECT(abcd.CompareTo(abce) < 0); | 354 EXPECT(abcd.CompareTo(abce) < 0); |
364 EXPECT(abce.CompareTo(abcd) > 0); | 355 EXPECT(abce.CompareTo(abcd) > 0); |
365 | 356 |
366 const int kMonkeyLen = 4; | 357 const int kMonkeyLen = 4; |
367 const uint8_t monkey_utf8[kMonkeyLen] = {0xf0, 0x9f, 0x90, 0xb5}; | 358 const uint8_t monkey_utf8[kMonkeyLen] = {0xf0, 0x9f, 0x90, 0xb5}; |
(...skipping 22 matching lines...) Expand all Loading... |
390 EXPECT(abcd.CompareTo(monkey_face) < 0); | 381 EXPECT(abcd.CompareTo(monkey_face) < 0); |
391 EXPECT(abce.CompareTo(monkey_face) < 0); | 382 EXPECT(abce.CompareTo(monkey_face) < 0); |
392 EXPECT(abcd.CompareTo(domino) < 0); | 383 EXPECT(abcd.CompareTo(domino) < 0); |
393 EXPECT(abce.CompareTo(domino) < 0); | 384 EXPECT(abce.CompareTo(domino) < 0); |
394 EXPECT(domino.CompareTo(abcd) > 0); | 385 EXPECT(domino.CompareTo(abcd) > 0); |
395 EXPECT(domino.CompareTo(abcd) > 0); | 386 EXPECT(domino.CompareTo(abcd) > 0); |
396 EXPECT(monkey_face.CompareTo(abce) > 0); | 387 EXPECT(monkey_face.CompareTo(abce) > 0); |
397 EXPECT(monkey_face.CompareTo(abce) > 0); | 388 EXPECT(monkey_face.CompareTo(abce) > 0); |
398 } | 389 } |
399 | 390 |
400 | |
401 ISOLATE_UNIT_TEST_CASE(StringEncodeIRI) { | 391 ISOLATE_UNIT_TEST_CASE(StringEncodeIRI) { |
402 const char* kInput = | 392 const char* kInput = |
403 "file:///usr/local/johnmccutchan/workspace/dart-repo/dart/test.dart"; | 393 "file:///usr/local/johnmccutchan/workspace/dart-repo/dart/test.dart"; |
404 const char* kOutput = | 394 const char* kOutput = |
405 "file%3A%2F%2F%2Fusr%2Flocal%2Fjohnmccutchan%2Fworkspace%2F" | 395 "file%3A%2F%2F%2Fusr%2Flocal%2Fjohnmccutchan%2Fworkspace%2F" |
406 "dart-repo%2Fdart%2Ftest.dart"; | 396 "dart-repo%2Fdart%2Ftest.dart"; |
407 const String& input = String::Handle(String::New(kInput)); | 397 const String& input = String::Handle(String::New(kInput)); |
408 const char* encoded = String::EncodeIRI(input); | 398 const char* encoded = String::EncodeIRI(input); |
409 EXPECT(strcmp(encoded, kOutput) == 0); | 399 EXPECT(strcmp(encoded, kOutput) == 0); |
410 } | 400 } |
411 | 401 |
412 | |
413 ISOLATE_UNIT_TEST_CASE(StringDecodeIRI) { | 402 ISOLATE_UNIT_TEST_CASE(StringDecodeIRI) { |
414 const char* kOutput = | 403 const char* kOutput = |
415 "file:///usr/local/johnmccutchan/workspace/dart-repo/dart/test.dart"; | 404 "file:///usr/local/johnmccutchan/workspace/dart-repo/dart/test.dart"; |
416 const char* kInput = | 405 const char* kInput = |
417 "file%3A%2F%2F%2Fusr%2Flocal%2Fjohnmccutchan%2Fworkspace%2F" | 406 "file%3A%2F%2F%2Fusr%2Flocal%2Fjohnmccutchan%2Fworkspace%2F" |
418 "dart-repo%2Fdart%2Ftest.dart"; | 407 "dart-repo%2Fdart%2Ftest.dart"; |
419 const String& input = String::Handle(String::New(kInput)); | 408 const String& input = String::Handle(String::New(kInput)); |
420 const String& output = String::Handle(String::New(kOutput)); | 409 const String& output = String::Handle(String::New(kOutput)); |
421 const String& decoded = String::Handle(String::DecodeIRI(input)); | 410 const String& decoded = String::Handle(String::DecodeIRI(input)); |
422 EXPECT(output.Equals(decoded)); | 411 EXPECT(output.Equals(decoded)); |
423 } | 412 } |
424 | 413 |
425 | |
426 ISOLATE_UNIT_TEST_CASE(StringDecodeIRIInvalid) { | 414 ISOLATE_UNIT_TEST_CASE(StringDecodeIRIInvalid) { |
427 String& input = String::Handle(); | 415 String& input = String::Handle(); |
428 input = String::New("file%"); | 416 input = String::New("file%"); |
429 String& decoded = String::Handle(); | 417 String& decoded = String::Handle(); |
430 decoded = String::DecodeIRI(input); | 418 decoded = String::DecodeIRI(input); |
431 EXPECT(decoded.IsNull()); | 419 EXPECT(decoded.IsNull()); |
432 input = String::New("file%3"); | 420 input = String::New("file%3"); |
433 decoded = String::DecodeIRI(input); | 421 decoded = String::DecodeIRI(input); |
434 EXPECT(decoded.IsNull()); | 422 EXPECT(decoded.IsNull()); |
435 input = String::New("file%3g"); | 423 input = String::New("file%3g"); |
436 decoded = String::DecodeIRI(input); | 424 decoded = String::DecodeIRI(input); |
437 EXPECT(decoded.IsNull()); | 425 EXPECT(decoded.IsNull()); |
438 } | 426 } |
439 | 427 |
440 | |
441 ISOLATE_UNIT_TEST_CASE(StringIRITwoByte) { | 428 ISOLATE_UNIT_TEST_CASE(StringIRITwoByte) { |
442 const intptr_t kInputLen = 3; | 429 const intptr_t kInputLen = 3; |
443 const uint16_t kInput[kInputLen] = {'x', '/', 256}; | 430 const uint16_t kInput[kInputLen] = {'x', '/', 256}; |
444 const String& input = String::Handle(String::FromUTF16(kInput, kInputLen)); | 431 const String& input = String::Handle(String::FromUTF16(kInput, kInputLen)); |
445 const intptr_t kOutputLen = 10; | 432 const intptr_t kOutputLen = 10; |
446 const uint16_t kOutput[kOutputLen] = {'x', '%', '2', 'F', '%', | 433 const uint16_t kOutput[kOutputLen] = {'x', '%', '2', 'F', '%', |
447 'C', '4', '%', '8', '0'}; | 434 'C', '4', '%', '8', '0'}; |
448 const String& output = String::Handle(String::FromUTF16(kOutput, kOutputLen)); | 435 const String& output = String::Handle(String::FromUTF16(kOutput, kOutputLen)); |
449 const String& encoded = String::Handle(String::New(String::EncodeIRI(input))); | 436 const String& encoded = String::Handle(String::New(String::EncodeIRI(input))); |
450 EXPECT(output.Equals(encoded)); | 437 EXPECT(output.Equals(encoded)); |
451 const String& decoded = String::Handle(String::DecodeIRI(output)); | 438 const String& decoded = String::Handle(String::DecodeIRI(output)); |
452 EXPECT(input.Equals(decoded)); | 439 EXPECT(input.Equals(decoded)); |
453 } | 440 } |
454 | 441 |
455 | |
456 ISOLATE_UNIT_TEST_CASE(Mint) { | 442 ISOLATE_UNIT_TEST_CASE(Mint) { |
457 // On 64-bit architectures a Smi is stored in a 64 bit word. A Midint cannot | 443 // On 64-bit architectures a Smi is stored in a 64 bit word. A Midint cannot |
458 // be allocated if it does fit into a Smi. | 444 // be allocated if it does fit into a Smi. |
459 #if !defined(ARCH_IS_64_BIT) | 445 #if !defined(ARCH_IS_64_BIT) |
460 { | 446 { |
461 Mint& med = Mint::Handle(); | 447 Mint& med = Mint::Handle(); |
462 EXPECT(med.IsNull()); | 448 EXPECT(med.IsNull()); |
463 int64_t v = DART_2PART_UINT64_C(1, 0); | 449 int64_t v = DART_2PART_UINT64_C(1, 0); |
464 med ^= Integer::New(v); | 450 med ^= Integer::New(v); |
465 EXPECT_EQ(v, med.value()); | 451 EXPECT_EQ(v, med.value()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 Mint& mint1 = Mint::Handle(); | 505 Mint& mint1 = Mint::Handle(); |
520 mint1 ^= Integer::NewCanonical(mint_string); | 506 mint1 ^= Integer::NewCanonical(mint_string); |
521 Mint& mint2 = Mint::Handle(); | 507 Mint& mint2 = Mint::Handle(); |
522 mint2 ^= Integer::NewCanonical(mint_string); | 508 mint2 ^= Integer::NewCanonical(mint_string); |
523 EXPECT_EQ(mint1.value(), mint_value); | 509 EXPECT_EQ(mint1.value(), mint_value); |
524 EXPECT_EQ(mint2.value(), mint_value); | 510 EXPECT_EQ(mint2.value(), mint_value); |
525 EXPECT_EQ(mint1.raw(), mint2.raw()); | 511 EXPECT_EQ(mint1.raw(), mint2.raw()); |
526 #endif | 512 #endif |
527 } | 513 } |
528 | 514 |
529 | |
530 ISOLATE_UNIT_TEST_CASE(Double) { | 515 ISOLATE_UNIT_TEST_CASE(Double) { |
531 { | 516 { |
532 const double dbl_const = 5.0; | 517 const double dbl_const = 5.0; |
533 const Double& dbl = Double::Handle(Double::New(dbl_const)); | 518 const Double& dbl = Double::Handle(Double::New(dbl_const)); |
534 Object& dbl_object = Object::Handle(dbl.raw()); | 519 Object& dbl_object = Object::Handle(dbl.raw()); |
535 EXPECT(dbl.IsDouble()); | 520 EXPECT(dbl.IsDouble()); |
536 EXPECT(dbl_object.IsDouble()); | 521 EXPECT(dbl_object.IsDouble()); |
537 EXPECT_EQ(dbl_const, dbl.value()); | 522 EXPECT_EQ(dbl_const, dbl.value()); |
538 } | 523 } |
539 | 524 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 const Double& dbl1 = Double::Handle(Double::New(dbl_str1)); | 588 const Double& dbl1 = Double::Handle(Double::New(dbl_str1)); |
604 EXPECT_EQ(2.0, dbl1.value()); | 589 EXPECT_EQ(2.0, dbl1.value()); |
605 | 590 |
606 // Disallow legacy form. | 591 // Disallow legacy form. |
607 const String& dbl_str2 = String::Handle(String::New("2.0d")); | 592 const String& dbl_str2 = String::Handle(String::New("2.0d")); |
608 const Double& dbl2 = Double::Handle(Double::New(dbl_str2)); | 593 const Double& dbl2 = Double::Handle(Double::New(dbl_str2)); |
609 EXPECT(dbl2.IsNull()); | 594 EXPECT(dbl2.IsNull()); |
610 } | 595 } |
611 } | 596 } |
612 | 597 |
613 | |
614 ISOLATE_UNIT_TEST_CASE(Bigint) { | 598 ISOLATE_UNIT_TEST_CASE(Bigint) { |
615 Bigint& b = Bigint::Handle(); | 599 Bigint& b = Bigint::Handle(); |
616 EXPECT(b.IsNull()); | 600 EXPECT(b.IsNull()); |
617 const char* cstr = "18446744073709551615000"; | 601 const char* cstr = "18446744073709551615000"; |
618 const String& test = String::Handle(String::New(cstr)); | 602 const String& test = String::Handle(String::New(cstr)); |
619 b ^= Integer::NewCanonical(test); | 603 b ^= Integer::NewCanonical(test); |
620 const char* str = b.ToCString(); | 604 const char* str = b.ToCString(); |
621 EXPECT_STREQ(cstr, str); | 605 EXPECT_STREQ(cstr, str); |
622 | 606 |
623 int64_t t64 = DART_2PART_UINT64_C(1, 0); | 607 int64_t t64 = DART_2PART_UINT64_C(1, 0); |
(...skipping 18 matching lines...) Expand all Loading... |
642 Smi& smi1 = Smi::Handle(Smi::New(5)); | 626 Smi& smi1 = Smi::Handle(Smi::New(5)); |
643 Smi& smi2 = Smi::Handle(Smi::New(-2)); | 627 Smi& smi2 = Smi::Handle(Smi::New(-2)); |
644 | 628 |
645 EXPECT_EQ(-1, smi1.CompareWith(big1)); | 629 EXPECT_EQ(-1, smi1.CompareWith(big1)); |
646 EXPECT_EQ(-1, smi2.CompareWith(big1)); | 630 EXPECT_EQ(-1, smi2.CompareWith(big1)); |
647 | 631 |
648 EXPECT_EQ(1, smi1.CompareWith(big3)); | 632 EXPECT_EQ(1, smi1.CompareWith(big3)); |
649 EXPECT_EQ(1, smi2.CompareWith(big3)); | 633 EXPECT_EQ(1, smi2.CompareWith(big3)); |
650 } | 634 } |
651 | 635 |
652 | |
653 ISOLATE_UNIT_TEST_CASE(Integer) { | 636 ISOLATE_UNIT_TEST_CASE(Integer) { |
654 Integer& i = Integer::Handle(); | 637 Integer& i = Integer::Handle(); |
655 i = Integer::NewCanonical(String::Handle(String::New("12"))); | 638 i = Integer::NewCanonical(String::Handle(String::New("12"))); |
656 EXPECT(i.IsSmi()); | 639 EXPECT(i.IsSmi()); |
657 i = Integer::NewCanonical(String::Handle(String::New("-120"))); | 640 i = Integer::NewCanonical(String::Handle(String::New("-120"))); |
658 EXPECT(i.IsSmi()); | 641 EXPECT(i.IsSmi()); |
659 i = Integer::NewCanonical(String::Handle(String::New("0"))); | 642 i = Integer::NewCanonical(String::Handle(String::New("0"))); |
660 EXPECT(i.IsSmi()); | 643 EXPECT(i.IsSmi()); |
661 i = Integer::NewCanonical( | 644 i = Integer::NewCanonical( |
662 String::Handle(String::New("12345678901234567890"))); | 645 String::Handle(String::New("12345678901234567890"))); |
663 EXPECT(i.IsBigint()); | 646 EXPECT(i.IsBigint()); |
664 i = Integer::NewCanonical( | 647 i = Integer::NewCanonical( |
665 String::Handle(String::New("-12345678901234567890111222"))); | 648 String::Handle(String::New("-12345678901234567890111222"))); |
666 EXPECT(i.IsBigint()); | 649 EXPECT(i.IsBigint()); |
667 } | 650 } |
668 | 651 |
669 | |
670 ISOLATE_UNIT_TEST_CASE(String) { | 652 ISOLATE_UNIT_TEST_CASE(String) { |
671 const char* kHello = "Hello World!"; | 653 const char* kHello = "Hello World!"; |
672 int32_t hello_len = strlen(kHello); | 654 int32_t hello_len = strlen(kHello); |
673 const String& str = String::Handle(String::New(kHello)); | 655 const String& str = String::Handle(String::New(kHello)); |
674 EXPECT(str.IsInstance()); | 656 EXPECT(str.IsInstance()); |
675 EXPECT(str.IsString()); | 657 EXPECT(str.IsString()); |
676 EXPECT(str.IsOneByteString()); | 658 EXPECT(str.IsOneByteString()); |
677 EXPECT(!str.IsTwoByteString()); | 659 EXPECT(!str.IsTwoByteString()); |
678 EXPECT(!str.IsNumber()); | 660 EXPECT(!str.IsNumber()); |
679 EXPECT_EQ(hello_len, str.Length()); | 661 EXPECT_EQ(hello_len, str.Length()); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 const int32_t char32[] = {0, 0x7FFF, 0xFFFF}; | 788 const int32_t char32[] = {0, 0x7FFF, 0xFFFF}; |
807 const String& str16 = String::Handle(String::FromUTF32(char32, 3)); | 789 const String& str16 = String::Handle(String::FromUTF32(char32, 3)); |
808 EXPECT(!str16.IsOneByteString()); | 790 EXPECT(!str16.IsOneByteString()); |
809 EXPECT(str16.IsTwoByteString()); | 791 EXPECT(str16.IsTwoByteString()); |
810 EXPECT_EQ(0x0000, str16.CharAt(0)); | 792 EXPECT_EQ(0x0000, str16.CharAt(0)); |
811 EXPECT_EQ(0x7FFF, str16.CharAt(1)); | 793 EXPECT_EQ(0x7FFF, str16.CharAt(1)); |
812 EXPECT_EQ(0xFFFF, str16.CharAt(2)); | 794 EXPECT_EQ(0xFFFF, str16.CharAt(2)); |
813 } | 795 } |
814 } | 796 } |
815 | 797 |
816 | |
817 ISOLATE_UNIT_TEST_CASE(StringFormat) { | 798 ISOLATE_UNIT_TEST_CASE(StringFormat) { |
818 const char* hello_str = "Hello World!"; | 799 const char* hello_str = "Hello World!"; |
819 const String& str = | 800 const String& str = |
820 String::Handle(String::NewFormatted("Hello %s!", "World")); | 801 String::Handle(String::NewFormatted("Hello %s!", "World")); |
821 EXPECT(str.IsInstance()); | 802 EXPECT(str.IsInstance()); |
822 EXPECT(str.IsString()); | 803 EXPECT(str.IsString()); |
823 EXPECT(str.IsOneByteString()); | 804 EXPECT(str.IsOneByteString()); |
824 EXPECT(!str.IsTwoByteString()); | 805 EXPECT(!str.IsTwoByteString()); |
825 EXPECT(!str.IsNumber()); | 806 EXPECT(!str.IsNumber()); |
826 EXPECT(str.Equals(hello_str)); | 807 EXPECT(str.Equals(hello_str)); |
827 } | 808 } |
828 | 809 |
829 | |
830 ISOLATE_UNIT_TEST_CASE(StringConcat) { | 810 ISOLATE_UNIT_TEST_CASE(StringConcat) { |
831 // Create strings from concatenated 1-byte empty strings. | 811 // Create strings from concatenated 1-byte empty strings. |
832 { | 812 { |
833 const String& empty1 = String::Handle(String::New("")); | 813 const String& empty1 = String::Handle(String::New("")); |
834 EXPECT(empty1.IsOneByteString()); | 814 EXPECT(empty1.IsOneByteString()); |
835 EXPECT_EQ(0, empty1.Length()); | 815 EXPECT_EQ(0, empty1.Length()); |
836 | 816 |
837 const String& empty2 = String::Handle(String::New("")); | 817 const String& empty2 = String::Handle(String::New("")); |
838 EXPECT(empty2.IsOneByteString()); | 818 EXPECT(empty2.IsOneByteString()); |
839 EXPECT_EQ(0, empty2.Length()); | 819 EXPECT_EQ(0, empty2.Length()); |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 EXPECT(two_one_two_str.IsTwoByteString()); | 1330 EXPECT(two_one_two_str.IsTwoByteString()); |
1351 EXPECT_EQ(twostr.Length() * 2 + onestr.Length(), two_one_two_str.Length()); | 1331 EXPECT_EQ(twostr.Length() * 2 + onestr.Length(), two_one_two_str.Length()); |
1352 uint16_t two_one_two[] = {0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, 'o', | 1332 uint16_t two_one_two[] = {0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, 'o', |
1353 'n', 'e', ' ', 'b', 'y', 't', | 1333 'n', 'e', ' ', 'b', 'y', 't', |
1354 'e', 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9}; | 1334 'e', 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9}; |
1355 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); | 1335 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); |
1356 EXPECT(two_one_two_str.Equals(two_one_two, two_one_two_len)); | 1336 EXPECT(two_one_two_str.Equals(two_one_two, two_one_two_len)); |
1357 } | 1337 } |
1358 } | 1338 } |
1359 | 1339 |
1360 | |
1361 ISOLATE_UNIT_TEST_CASE(StringHashConcat) { | 1340 ISOLATE_UNIT_TEST_CASE(StringHashConcat) { |
1362 EXPECT_EQ(String::Handle(String::New("onebyte")).Hash(), | 1341 EXPECT_EQ(String::Handle(String::New("onebyte")).Hash(), |
1363 String::HashConcat(String::Handle(String::New("one")), | 1342 String::HashConcat(String::Handle(String::New("one")), |
1364 String::Handle(String::New("byte")))); | 1343 String::Handle(String::New("byte")))); |
1365 uint16_t clef_utf16[] = {0xD834, 0xDD1E}; | 1344 uint16_t clef_utf16[] = {0xD834, 0xDD1E}; |
1366 const String& clef = String::Handle(String::FromUTF16(clef_utf16, 2)); | 1345 const String& clef = String::Handle(String::FromUTF16(clef_utf16, 2)); |
1367 int32_t clef_utf32[] = {0x1D11E}; | 1346 int32_t clef_utf32[] = {0x1D11E}; |
1368 EXPECT(clef.Equals(clef_utf32, 1)); | 1347 EXPECT(clef.Equals(clef_utf32, 1)); |
1369 intptr_t hash32 = String::Hash(clef_utf32, 1); | 1348 intptr_t hash32 = String::Hash(clef_utf32, 1); |
1370 EXPECT_EQ(hash32, clef.Hash()); | 1349 EXPECT_EQ(hash32, clef.Hash()); |
1371 EXPECT_EQ(hash32, String::HashConcat( | 1350 EXPECT_EQ(hash32, String::HashConcat( |
1372 String::Handle(String::FromUTF16(clef_utf16, 1)), | 1351 String::Handle(String::FromUTF16(clef_utf16, 1)), |
1373 String::Handle(String::FromUTF16(clef_utf16 + 1, 1)))); | 1352 String::Handle(String::FromUTF16(clef_utf16 + 1, 1)))); |
1374 } | 1353 } |
1375 | 1354 |
1376 | |
1377 ISOLATE_UNIT_TEST_CASE(StringSubStringDifferentWidth) { | 1355 ISOLATE_UNIT_TEST_CASE(StringSubStringDifferentWidth) { |
1378 // Create 1-byte substring from a 1-byte source string. | 1356 // Create 1-byte substring from a 1-byte source string. |
1379 const char* onechars = "\xC3\xB6\xC3\xB1\xC3\xA9"; | 1357 const char* onechars = "\xC3\xB6\xC3\xB1\xC3\xA9"; |
1380 | 1358 |
1381 const String& onestr = String::Handle(String::New(onechars)); | 1359 const String& onestr = String::Handle(String::New(onechars)); |
1382 EXPECT(!onestr.IsNull()); | 1360 EXPECT(!onestr.IsNull()); |
1383 EXPECT(onestr.IsOneByteString()); | 1361 EXPECT(onestr.IsOneByteString()); |
1384 EXPECT(!onestr.IsTwoByteString()); | 1362 EXPECT(!onestr.IsTwoByteString()); |
1385 | 1363 |
1386 const String& onesub = String::Handle(String::SubString(onestr, 0)); | 1364 const String& onesub = String::Handle(String::SubString(onestr, 0)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 EXPECT(!foursub2.IsNull()); | 1405 EXPECT(!foursub2.IsNull()); |
1428 EXPECT(foursub2.IsTwoByteString()); | 1406 EXPECT(foursub2.IsTwoByteString()); |
1429 EXPECT_EQ(foursub2.Length(), 3); | 1407 EXPECT_EQ(foursub2.Length(), 3); |
1430 | 1408 |
1431 const String& foursub4 = String::Handle(String::SubString(fourstr, 6)); | 1409 const String& foursub4 = String::Handle(String::SubString(fourstr, 6)); |
1432 EXPECT_EQ(foursub4.Length(), 8); | 1410 EXPECT_EQ(foursub4.Length(), 8); |
1433 EXPECT(!foursub4.IsNull()); | 1411 EXPECT(!foursub4.IsNull()); |
1434 EXPECT(foursub4.IsTwoByteString()); | 1412 EXPECT(foursub4.IsTwoByteString()); |
1435 } | 1413 } |
1436 | 1414 |
1437 | |
1438 ISOLATE_UNIT_TEST_CASE(StringFromUtf8Literal) { | 1415 ISOLATE_UNIT_TEST_CASE(StringFromUtf8Literal) { |
1439 // Create a 1-byte string from a UTF-8 encoded string literal. | 1416 // Create a 1-byte string from a UTF-8 encoded string literal. |
1440 { | 1417 { |
1441 const char* src = | 1418 const char* src = |
1442 "\xC2\xA0\xC2\xA1\xC2\xA2\xC2\xA3" | 1419 "\xC2\xA0\xC2\xA1\xC2\xA2\xC2\xA3" |
1443 "\xC2\xA4\xC2\xA5\xC2\xA6\xC2\xA7" | 1420 "\xC2\xA4\xC2\xA5\xC2\xA6\xC2\xA7" |
1444 "\xC2\xA8\xC2\xA9\xC2\xAA\xC2\xAB" | 1421 "\xC2\xA8\xC2\xA9\xC2\xAA\xC2\xAB" |
1445 "\xC2\xAC\xC2\xAD\xC2\xAE\xC2\xAF" | 1422 "\xC2\xAC\xC2\xAD\xC2\xAE\xC2\xAF" |
1446 "\xC2\xB0\xC2\xB1\xC2\xB2\xC2\xB3" | 1423 "\xC2\xB0\xC2\xB1\xC2\xB2\xC2\xB3" |
1447 "\xC2\xB4\xC2\xB5\xC2\xB6\xC2\xB7" | 1424 "\xC2\xB4\xC2\xB5\xC2\xB6\xC2\xB7" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 const String& str = String::Handle(String::New(src)); | 1564 const String& str = String::Handle(String::New(src)); |
1588 EXPECT(str.IsTwoByteString()); | 1565 EXPECT(str.IsTwoByteString()); |
1589 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1566 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
1590 EXPECT_EQ(expected_size, str.Length()); | 1567 EXPECT_EQ(expected_size, str.Length()); |
1591 for (int i = 0; i < str.Length(); ++i) { | 1568 for (int i = 0; i < str.Length(); ++i) { |
1592 EXPECT_EQ(expected[i], str.CharAt(i)); | 1569 EXPECT_EQ(expected[i], str.CharAt(i)); |
1593 } | 1570 } |
1594 } | 1571 } |
1595 } | 1572 } |
1596 | 1573 |
1597 | |
1598 ISOLATE_UNIT_TEST_CASE(StringEqualsUtf8) { | 1574 ISOLATE_UNIT_TEST_CASE(StringEqualsUtf8) { |
1599 const char* onesrc = "abc"; | 1575 const char* onesrc = "abc"; |
1600 const String& onestr = String::Handle(String::New(onesrc)); | 1576 const String& onestr = String::Handle(String::New(onesrc)); |
1601 EXPECT(onestr.IsOneByteString()); | 1577 EXPECT(onestr.IsOneByteString()); |
1602 EXPECT(!onestr.Equals("")); | 1578 EXPECT(!onestr.Equals("")); |
1603 EXPECT(!onestr.Equals("a")); | 1579 EXPECT(!onestr.Equals("a")); |
1604 EXPECT(!onestr.Equals("ab")); | 1580 EXPECT(!onestr.Equals("ab")); |
1605 EXPECT(onestr.Equals("abc")); | 1581 EXPECT(onestr.Equals("abc")); |
1606 EXPECT(!onestr.Equals("abcd")); | 1582 EXPECT(!onestr.Equals("abcd")); |
1607 | 1583 |
(...skipping 11 matching lines...) Expand all Loading... |
1619 EXPECT(fourstr.IsTwoByteString()); | 1595 EXPECT(fourstr.IsTwoByteString()); |
1620 EXPECT(!fourstr.Equals("")); | 1596 EXPECT(!fourstr.Equals("")); |
1621 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0")); | 1597 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0")); |
1622 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1")); | 1598 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1")); |
1623 EXPECT(fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1\xF0\x90\x8E\xA2")); | 1599 EXPECT(fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1\xF0\x90\x8E\xA2")); |
1624 EXPECT( | 1600 EXPECT( |
1625 !fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1" | 1601 !fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1" |
1626 "\xF0\x90\x8E\xA2\xF0\x90\x8E\xA3")); | 1602 "\xF0\x90\x8E\xA2\xF0\x90\x8E\xA3")); |
1627 } | 1603 } |
1628 | 1604 |
1629 | |
1630 ISOLATE_UNIT_TEST_CASE(StringEqualsUTF32) { | 1605 ISOLATE_UNIT_TEST_CASE(StringEqualsUTF32) { |
1631 const String& empty = String::Handle(String::New("")); | 1606 const String& empty = String::Handle(String::New("")); |
1632 const String& t_str = String::Handle(String::New("t")); | 1607 const String& t_str = String::Handle(String::New("t")); |
1633 const String& th_str = String::Handle(String::New("th")); | 1608 const String& th_str = String::Handle(String::New("th")); |
1634 const int32_t chars[] = {'t', 'h', 'i', 's'}; | 1609 const int32_t chars[] = {'t', 'h', 'i', 's'}; |
1635 EXPECT(!empty.Equals(chars, -1)); | 1610 EXPECT(!empty.Equals(chars, -1)); |
1636 EXPECT(empty.Equals(chars, 0)); | 1611 EXPECT(empty.Equals(chars, 0)); |
1637 EXPECT(!empty.Equals(chars, 1)); | 1612 EXPECT(!empty.Equals(chars, 1)); |
1638 EXPECT(!t_str.Equals(chars, 0)); | 1613 EXPECT(!t_str.Equals(chars, 0)); |
1639 EXPECT(t_str.Equals(chars, 1)); | 1614 EXPECT(t_str.Equals(chars, 1)); |
1640 EXPECT(!t_str.Equals(chars, 2)); | 1615 EXPECT(!t_str.Equals(chars, 2)); |
1641 EXPECT(!th_str.Equals(chars, 1)); | 1616 EXPECT(!th_str.Equals(chars, 1)); |
1642 EXPECT(th_str.Equals(chars, 2)); | 1617 EXPECT(th_str.Equals(chars, 2)); |
1643 EXPECT(!th_str.Equals(chars, 3)); | 1618 EXPECT(!th_str.Equals(chars, 3)); |
1644 } | 1619 } |
1645 | 1620 |
1646 | |
1647 ISOLATE_UNIT_TEST_CASE(ExternalOneByteString) { | 1621 ISOLATE_UNIT_TEST_CASE(ExternalOneByteString) { |
1648 uint8_t characters[] = {0xF6, 0xF1, 0xE9}; | 1622 uint8_t characters[] = {0xF6, 0xF1, 0xE9}; |
1649 intptr_t len = ARRAY_SIZE(characters); | 1623 intptr_t len = ARRAY_SIZE(characters); |
1650 | 1624 |
1651 const String& str = String::Handle( | 1625 const String& str = String::Handle( |
1652 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); | 1626 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); |
1653 EXPECT(!str.IsOneByteString()); | 1627 EXPECT(!str.IsOneByteString()); |
1654 EXPECT(str.IsExternalOneByteString()); | 1628 EXPECT(str.IsExternalOneByteString()); |
1655 EXPECT_EQ(str.Length(), len); | 1629 EXPECT_EQ(str.Length(), len); |
1656 EXPECT(str.Equals("\xC3\xB6\xC3\xB1\xC3\xA9")); | 1630 EXPECT(str.Equals("\xC3\xB6\xC3\xB1\xC3\xA9")); |
(...skipping 10 matching lines...) Expand all Loading... |
1667 EXPECT_EQ(len * 2, concat.Length()); | 1641 EXPECT_EQ(len * 2, concat.Length()); |
1668 EXPECT(concat.Equals("\xC3\xB6\xC3\xB1\xC3\xA9\xC3\xB6\xC3\xB1\xC3\xA9")); | 1642 EXPECT(concat.Equals("\xC3\xB6\xC3\xB1\xC3\xA9\xC3\xB6\xC3\xB1\xC3\xA9")); |
1669 | 1643 |
1670 const String& substr = String::Handle(String::SubString(str, 1, 1)); | 1644 const String& substr = String::Handle(String::SubString(str, 1, 1)); |
1671 EXPECT(!substr.IsExternalOneByteString()); | 1645 EXPECT(!substr.IsExternalOneByteString()); |
1672 EXPECT(substr.IsOneByteString()); | 1646 EXPECT(substr.IsOneByteString()); |
1673 EXPECT_EQ(1, substr.Length()); | 1647 EXPECT_EQ(1, substr.Length()); |
1674 EXPECT(substr.Equals("\xC3\xB1")); | 1648 EXPECT(substr.Equals("\xC3\xB1")); |
1675 } | 1649 } |
1676 | 1650 |
1677 | |
1678 ISOLATE_UNIT_TEST_CASE(EscapeSpecialCharactersOneByteString) { | 1651 ISOLATE_UNIT_TEST_CASE(EscapeSpecialCharactersOneByteString) { |
1679 uint8_t characters[] = {'a', '\n', '\f', '\b', '\t', | 1652 uint8_t characters[] = {'a', '\n', '\f', '\b', '\t', |
1680 '\v', '\r', '\\', '$', 'z'}; | 1653 '\v', '\r', '\\', '$', 'z'}; |
1681 intptr_t len = ARRAY_SIZE(characters); | 1654 intptr_t len = ARRAY_SIZE(characters); |
1682 | 1655 |
1683 const String& str = | 1656 const String& str = |
1684 String::Handle(OneByteString::New(characters, len, Heap::kNew)); | 1657 String::Handle(OneByteString::New(characters, len, Heap::kNew)); |
1685 EXPECT(str.IsOneByteString()); | 1658 EXPECT(str.IsOneByteString()); |
1686 EXPECT_EQ(str.Length(), len); | 1659 EXPECT_EQ(str.Length(), len); |
1687 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); | 1660 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); |
1688 const String& escaped_str = | 1661 const String& escaped_str = |
1689 String::Handle(String::EscapeSpecialCharacters(str)); | 1662 String::Handle(String::EscapeSpecialCharacters(str)); |
1690 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); | 1663 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); |
1691 | 1664 |
1692 const String& escaped_empty_str = | 1665 const String& escaped_empty_str = |
1693 String::Handle(String::EscapeSpecialCharacters(Symbols::Empty())); | 1666 String::Handle(String::EscapeSpecialCharacters(Symbols::Empty())); |
1694 EXPECT_EQ(escaped_empty_str.Length(), 0); | 1667 EXPECT_EQ(escaped_empty_str.Length(), 0); |
1695 } | 1668 } |
1696 | 1669 |
1697 | |
1698 ISOLATE_UNIT_TEST_CASE(EscapeSpecialCharactersExternalOneByteString) { | 1670 ISOLATE_UNIT_TEST_CASE(EscapeSpecialCharactersExternalOneByteString) { |
1699 uint8_t characters[] = {'a', '\n', '\f', '\b', '\t', | 1671 uint8_t characters[] = {'a', '\n', '\f', '\b', '\t', |
1700 '\v', '\r', '\\', '$', 'z'}; | 1672 '\v', '\r', '\\', '$', 'z'}; |
1701 intptr_t len = ARRAY_SIZE(characters); | 1673 intptr_t len = ARRAY_SIZE(characters); |
1702 | 1674 |
1703 const String& str = String::Handle( | 1675 const String& str = String::Handle( |
1704 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); | 1676 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); |
1705 EXPECT(!str.IsOneByteString()); | 1677 EXPECT(!str.IsOneByteString()); |
1706 EXPECT(str.IsExternalOneByteString()); | 1678 EXPECT(str.IsExternalOneByteString()); |
1707 EXPECT_EQ(str.Length(), len); | 1679 EXPECT_EQ(str.Length(), len); |
(...skipping 25 matching lines...) Expand all Loading... |
1733 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); | 1705 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); |
1734 | 1706 |
1735 const String& empty_str = | 1707 const String& empty_str = |
1736 String::Handle(TwoByteString::New(static_cast<intptr_t>(0), Heap::kNew)); | 1708 String::Handle(TwoByteString::New(static_cast<intptr_t>(0), Heap::kNew)); |
1737 const String& escaped_empty_str = | 1709 const String& escaped_empty_str = |
1738 String::Handle(String::EscapeSpecialCharacters(empty_str)); | 1710 String::Handle(String::EscapeSpecialCharacters(empty_str)); |
1739 EXPECT_EQ(empty_str.Length(), 0); | 1711 EXPECT_EQ(empty_str.Length(), 0); |
1740 EXPECT_EQ(escaped_empty_str.Length(), 0); | 1712 EXPECT_EQ(escaped_empty_str.Length(), 0); |
1741 } | 1713 } |
1742 | 1714 |
1743 | |
1744 ISOLATE_UNIT_TEST_CASE(EscapeSpecialCharactersExternalTwoByteString) { | 1715 ISOLATE_UNIT_TEST_CASE(EscapeSpecialCharactersExternalTwoByteString) { |
1745 uint16_t characters[] = {'a', '\n', '\f', '\b', '\t', | 1716 uint16_t characters[] = {'a', '\n', '\f', '\b', '\t', |
1746 '\v', '\r', '\\', '$', 'z'}; | 1717 '\v', '\r', '\\', '$', 'z'}; |
1747 intptr_t len = ARRAY_SIZE(characters); | 1718 intptr_t len = ARRAY_SIZE(characters); |
1748 | 1719 |
1749 const String& str = String::Handle( | 1720 const String& str = String::Handle( |
1750 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew)); | 1721 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew)); |
1751 EXPECT(str.IsExternalTwoByteString()); | 1722 EXPECT(str.IsExternalTwoByteString()); |
1752 EXPECT_EQ(str.Length(), len); | 1723 EXPECT_EQ(str.Length(), len); |
1753 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); | 1724 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); |
1754 const String& escaped_str = | 1725 const String& escaped_str = |
1755 String::Handle(String::EscapeSpecialCharacters(str)); | 1726 String::Handle(String::EscapeSpecialCharacters(str)); |
1756 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); | 1727 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); |
1757 | 1728 |
1758 const String& empty_str = String::Handle( | 1729 const String& empty_str = String::Handle( |
1759 ExternalTwoByteString::New(characters, 0, NULL, NULL, Heap::kNew)); | 1730 ExternalTwoByteString::New(characters, 0, NULL, NULL, Heap::kNew)); |
1760 const String& escaped_empty_str = | 1731 const String& escaped_empty_str = |
1761 String::Handle(String::EscapeSpecialCharacters(empty_str)); | 1732 String::Handle(String::EscapeSpecialCharacters(empty_str)); |
1762 EXPECT_EQ(empty_str.Length(), 0); | 1733 EXPECT_EQ(empty_str.Length(), 0); |
1763 EXPECT_EQ(escaped_empty_str.Length(), 0); | 1734 EXPECT_EQ(escaped_empty_str.Length(), 0); |
1764 } | 1735 } |
1765 | 1736 |
1766 | |
1767 ISOLATE_UNIT_TEST_CASE(ExternalTwoByteString) { | 1737 ISOLATE_UNIT_TEST_CASE(ExternalTwoByteString) { |
1768 uint16_t characters[] = {0x1E6B, 0x1E85, 0x1E53}; | 1738 uint16_t characters[] = {0x1E6B, 0x1E85, 0x1E53}; |
1769 intptr_t len = ARRAY_SIZE(characters); | 1739 intptr_t len = ARRAY_SIZE(characters); |
1770 | 1740 |
1771 const String& str = String::Handle( | 1741 const String& str = String::Handle( |
1772 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew)); | 1742 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew)); |
1773 EXPECT(!str.IsTwoByteString()); | 1743 EXPECT(!str.IsTwoByteString()); |
1774 EXPECT(str.IsExternalTwoByteString()); | 1744 EXPECT(str.IsExternalTwoByteString()); |
1775 EXPECT_EQ(str.Length(), len); | 1745 EXPECT_EQ(str.Length(), len); |
1776 EXPECT(str.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93")); | 1746 EXPECT(str.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93")); |
(...skipping 12 matching lines...) Expand all Loading... |
1789 concat.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93" | 1759 concat.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93" |
1790 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93")); | 1760 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93")); |
1791 | 1761 |
1792 const String& substr = String::Handle(String::SubString(str, 1, 1)); | 1762 const String& substr = String::Handle(String::SubString(str, 1, 1)); |
1793 EXPECT(!substr.IsExternalTwoByteString()); | 1763 EXPECT(!substr.IsExternalTwoByteString()); |
1794 EXPECT(substr.IsTwoByteString()); | 1764 EXPECT(substr.IsTwoByteString()); |
1795 EXPECT_EQ(1, substr.Length()); | 1765 EXPECT_EQ(1, substr.Length()); |
1796 EXPECT(substr.Equals("\xE1\xBA\x85")); | 1766 EXPECT(substr.Equals("\xE1\xBA\x85")); |
1797 } | 1767 } |
1798 | 1768 |
1799 | |
1800 ISOLATE_UNIT_TEST_CASE(Symbol) { | 1769 ISOLATE_UNIT_TEST_CASE(Symbol) { |
1801 const String& one = String::Handle(Symbols::New(thread, "Eins")); | 1770 const String& one = String::Handle(Symbols::New(thread, "Eins")); |
1802 EXPECT(one.IsSymbol()); | 1771 EXPECT(one.IsSymbol()); |
1803 const String& two = String::Handle(Symbols::New(thread, "Zwei")); | 1772 const String& two = String::Handle(Symbols::New(thread, "Zwei")); |
1804 const String& three = String::Handle(Symbols::New(thread, "Drei")); | 1773 const String& three = String::Handle(Symbols::New(thread, "Drei")); |
1805 const String& four = String::Handle(Symbols::New(thread, "Vier")); | 1774 const String& four = String::Handle(Symbols::New(thread, "Vier")); |
1806 const String& five = String::Handle(Symbols::New(thread, "Fuenf")); | 1775 const String& five = String::Handle(Symbols::New(thread, "Fuenf")); |
1807 const String& six = String::Handle(Symbols::New(thread, "Sechs")); | 1776 const String& six = String::Handle(Symbols::New(thread, "Sechs")); |
1808 const String& seven = String::Handle(Symbols::New(thread, "Sieben")); | 1777 const String& seven = String::Handle(Symbols::New(thread, "Sieben")); |
1809 const String& eight = String::Handle(Symbols::New(thread, "Acht")); | 1778 const String& eight = String::Handle(Symbols::New(thread, "Acht")); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 uint16_t char16[] = {'E', 'l', 'f'}; | 1820 uint16_t char16[] = {'E', 'l', 'f'}; |
1852 String& elf1 = String::Handle(Symbols::FromUTF16(thread, char16, 3)); | 1821 String& elf1 = String::Handle(Symbols::FromUTF16(thread, char16, 3)); |
1853 int32_t char32[] = {'E', 'l', 'f'}; | 1822 int32_t char32[] = {'E', 'l', 'f'}; |
1854 String& elf2 = String::Handle(Symbols::FromUTF32(thread, char32, 3)); | 1823 String& elf2 = String::Handle(Symbols::FromUTF32(thread, char32, 3)); |
1855 EXPECT(elf1.IsSymbol()); | 1824 EXPECT(elf1.IsSymbol()); |
1856 EXPECT(elf2.IsSymbol()); | 1825 EXPECT(elf2.IsSymbol()); |
1857 EXPECT_EQ(elf1.raw(), Symbols::New(thread, "Elf")); | 1826 EXPECT_EQ(elf1.raw(), Symbols::New(thread, "Elf")); |
1858 EXPECT_EQ(elf2.raw(), Symbols::New(thread, "Elf")); | 1827 EXPECT_EQ(elf2.raw(), Symbols::New(thread, "Elf")); |
1859 } | 1828 } |
1860 | 1829 |
1861 | |
1862 ISOLATE_UNIT_TEST_CASE(SymbolUnicode) { | 1830 ISOLATE_UNIT_TEST_CASE(SymbolUnicode) { |
1863 uint16_t monkey_utf16[] = {0xd83d, 0xdc35}; // Unicode Monkey Face. | 1831 uint16_t monkey_utf16[] = {0xd83d, 0xdc35}; // Unicode Monkey Face. |
1864 String& monkey = String::Handle(Symbols::FromUTF16(thread, monkey_utf16, 2)); | 1832 String& monkey = String::Handle(Symbols::FromUTF16(thread, monkey_utf16, 2)); |
1865 EXPECT(monkey.IsSymbol()); | 1833 EXPECT(monkey.IsSymbol()); |
1866 const char monkey_utf8[] = {'\xf0', '\x9f', '\x90', '\xb5', 0}; | 1834 const char monkey_utf8[] = {'\xf0', '\x9f', '\x90', '\xb5', 0}; |
1867 EXPECT_EQ(monkey.raw(), Symbols::New(thread, monkey_utf8)); | 1835 EXPECT_EQ(monkey.raw(), Symbols::New(thread, monkey_utf8)); |
1868 | 1836 |
1869 int32_t kMonkeyFace = 0x1f435; | 1837 int32_t kMonkeyFace = 0x1f435; |
1870 String& monkey2 = String::Handle(Symbols::FromCharCode(thread, kMonkeyFace)); | 1838 String& monkey2 = String::Handle(Symbols::FromCharCode(thread, kMonkeyFace)); |
1871 EXPECT_EQ(monkey.raw(), monkey2.raw()); | 1839 EXPECT_EQ(monkey.raw(), monkey2.raw()); |
1872 | 1840 |
1873 // Unicode cat face with tears of joy. | 1841 // Unicode cat face with tears of joy. |
1874 int32_t kCatFaceWithTearsOfJoy = 0x1f639; | 1842 int32_t kCatFaceWithTearsOfJoy = 0x1f639; |
1875 String& cat = | 1843 String& cat = |
1876 String::Handle(Symbols::FromCharCode(thread, kCatFaceWithTearsOfJoy)); | 1844 String::Handle(Symbols::FromCharCode(thread, kCatFaceWithTearsOfJoy)); |
1877 | 1845 |
1878 uint16_t cat_utf16[] = {0xd83d, 0xde39}; | 1846 uint16_t cat_utf16[] = {0xd83d, 0xde39}; |
1879 String& cat2 = String::Handle(Symbols::FromUTF16(thread, cat_utf16, 2)); | 1847 String& cat2 = String::Handle(Symbols::FromUTF16(thread, cat_utf16, 2)); |
1880 EXPECT(cat2.IsSymbol()); | 1848 EXPECT(cat2.IsSymbol()); |
1881 EXPECT_EQ(cat2.raw(), cat.raw()); | 1849 EXPECT_EQ(cat2.raw(), cat.raw()); |
1882 } | 1850 } |
1883 | 1851 |
1884 | |
1885 ISOLATE_UNIT_TEST_CASE(Bool) { | 1852 ISOLATE_UNIT_TEST_CASE(Bool) { |
1886 EXPECT(Bool::True().value()); | 1853 EXPECT(Bool::True().value()); |
1887 EXPECT(!Bool::False().value()); | 1854 EXPECT(!Bool::False().value()); |
1888 } | 1855 } |
1889 | 1856 |
1890 | |
1891 ISOLATE_UNIT_TEST_CASE(Array) { | 1857 ISOLATE_UNIT_TEST_CASE(Array) { |
1892 const int kArrayLen = 5; | 1858 const int kArrayLen = 5; |
1893 const Array& array = Array::Handle(Array::New(kArrayLen)); | 1859 const Array& array = Array::Handle(Array::New(kArrayLen)); |
1894 EXPECT_EQ(kArrayLen, array.Length()); | 1860 EXPECT_EQ(kArrayLen, array.Length()); |
1895 Object& element = Object::Handle(array.At(0)); | 1861 Object& element = Object::Handle(array.At(0)); |
1896 EXPECT(element.IsNull()); | 1862 EXPECT(element.IsNull()); |
1897 element = array.At(kArrayLen - 1); | 1863 element = array.At(kArrayLen - 1); |
1898 EXPECT(element.IsNull()); | 1864 EXPECT(element.IsNull()); |
1899 array.SetAt(0, array); | 1865 array.SetAt(0, array); |
1900 array.SetAt(2, array); | 1866 array.SetAt(2, array); |
(...skipping 23 matching lines...) Expand all Loading... |
1924 | 1890 |
1925 EXPECT_EQ(1, Object::zero_array().Length()); | 1891 EXPECT_EQ(1, Object::zero_array().Length()); |
1926 element = Object::zero_array().At(0); | 1892 element = Object::zero_array().At(0); |
1927 EXPECT(Smi::Cast(element).IsZero()); | 1893 EXPECT(Smi::Cast(element).IsZero()); |
1928 | 1894 |
1929 array.MakeImmutable(); | 1895 array.MakeImmutable(); |
1930 Object& obj = Object::Handle(array.raw()); | 1896 Object& obj = Object::Handle(array.raw()); |
1931 EXPECT(obj.IsArray()); | 1897 EXPECT(obj.IsArray()); |
1932 } | 1898 } |
1933 | 1899 |
1934 | |
1935 static void TestIllegalArrayLength(intptr_t length) { | 1900 static void TestIllegalArrayLength(intptr_t length) { |
1936 char buffer[1024]; | 1901 char buffer[1024]; |
1937 OS::SNPrint(buffer, sizeof(buffer), | 1902 OS::SNPrint(buffer, sizeof(buffer), |
1938 "main() {\n" | 1903 "main() {\n" |
1939 " new List(%" Pd | 1904 " new List(%" Pd |
1940 ");\n" | 1905 ");\n" |
1941 "}\n", | 1906 "}\n", |
1942 length); | 1907 length); |
1943 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); | 1908 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); |
1944 EXPECT_VALID(lib); | 1909 EXPECT_VALID(lib); |
1945 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1910 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1946 OS::SNPrint(buffer, sizeof(buffer), | 1911 OS::SNPrint(buffer, sizeof(buffer), |
1947 "Unhandled exception:\n" | 1912 "Unhandled exception:\n" |
1948 "RangeError (length): Invalid value: " | 1913 "RangeError (length): Invalid value: " |
1949 "Not in range 0..%" Pd ", inclusive: %" Pd, | 1914 "Not in range 0..%" Pd ", inclusive: %" Pd, |
1950 Array::kMaxElements, length); | 1915 Array::kMaxElements, length); |
1951 EXPECT_ERROR(result, buffer); | 1916 EXPECT_ERROR(result, buffer); |
1952 } | 1917 } |
1953 | 1918 |
1954 | |
1955 TEST_CASE(ArrayLengthNegativeOne) { | 1919 TEST_CASE(ArrayLengthNegativeOne) { |
1956 TestIllegalArrayLength(-1); | 1920 TestIllegalArrayLength(-1); |
1957 } | 1921 } |
1958 TEST_CASE(ArrayLengthSmiMin) { | 1922 TEST_CASE(ArrayLengthSmiMin) { |
1959 TestIllegalArrayLength(kSmiMin); | 1923 TestIllegalArrayLength(kSmiMin); |
1960 } | 1924 } |
1961 TEST_CASE(ArrayLengthOneTooMany) { | 1925 TEST_CASE(ArrayLengthOneTooMany) { |
1962 const intptr_t kOneTooMany = Array::kMaxElements + 1; | 1926 const intptr_t kOneTooMany = Array::kMaxElements + 1; |
1963 ASSERT(kOneTooMany >= 0); | 1927 ASSERT(kOneTooMany >= 0); |
1964 TestIllegalArrayLength(kOneTooMany); | 1928 TestIllegalArrayLength(kOneTooMany); |
1965 } | 1929 } |
1966 | 1930 |
1967 | |
1968 TEST_CASE(ArrayLengthMaxElements) { | 1931 TEST_CASE(ArrayLengthMaxElements) { |
1969 char buffer[1024]; | 1932 char buffer[1024]; |
1970 OS::SNPrint(buffer, sizeof(buffer), | 1933 OS::SNPrint(buffer, sizeof(buffer), |
1971 "main() {\n" | 1934 "main() {\n" |
1972 " return new List(%" Pd | 1935 " return new List(%" Pd |
1973 ");\n" | 1936 ");\n" |
1974 "}\n", | 1937 "}\n", |
1975 Array::kMaxElements); | 1938 Array::kMaxElements); |
1976 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); | 1939 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); |
1977 EXPECT_VALID(lib); | 1940 EXPECT_VALID(lib); |
1978 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1941 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1979 if (Dart_IsError(result)) { | 1942 if (Dart_IsError(result)) { |
1980 EXPECT_ERROR(result, "Out of Memory"); | 1943 EXPECT_ERROR(result, "Out of Memory"); |
1981 } else { | 1944 } else { |
1982 const intptr_t kExpected = Array::kMaxElements; | 1945 const intptr_t kExpected = Array::kMaxElements; |
1983 intptr_t actual = 0; | 1946 intptr_t actual = 0; |
1984 EXPECT_VALID(Dart_ListLength(result, &actual)); | 1947 EXPECT_VALID(Dart_ListLength(result, &actual)); |
1985 EXPECT_EQ(kExpected, actual); | 1948 EXPECT_EQ(kExpected, actual); |
1986 } | 1949 } |
1987 } | 1950 } |
1988 | 1951 |
1989 | |
1990 static void TestIllegalTypedDataLength(const char* class_name, | 1952 static void TestIllegalTypedDataLength(const char* class_name, |
1991 intptr_t length) { | 1953 intptr_t length) { |
1992 char buffer[1024]; | 1954 char buffer[1024]; |
1993 OS::SNPrint(buffer, sizeof(buffer), | 1955 OS::SNPrint(buffer, sizeof(buffer), |
1994 "import 'dart:typed_data';\n" | 1956 "import 'dart:typed_data';\n" |
1995 "main() {\n" | 1957 "main() {\n" |
1996 " new %s(%" Pd | 1958 " new %s(%" Pd |
1997 ");\n" | 1959 ");\n" |
1998 "}\n", | 1960 "}\n", |
1999 class_name, length); | 1961 class_name, length); |
2000 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); | 1962 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); |
2001 EXPECT_VALID(lib); | 1963 EXPECT_VALID(lib); |
2002 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1964 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
2003 OS::SNPrint(buffer, sizeof(buffer), "%" Pd, length); | 1965 OS::SNPrint(buffer, sizeof(buffer), "%" Pd, length); |
2004 EXPECT_ERROR(result, "Invalid argument(s)"); | 1966 EXPECT_ERROR(result, "Invalid argument(s)"); |
2005 EXPECT_ERROR(result, buffer); | 1967 EXPECT_ERROR(result, buffer); |
2006 } | 1968 } |
2007 | 1969 |
2008 | |
2009 TEST_CASE(Int8ListLengthNegativeOne) { | 1970 TEST_CASE(Int8ListLengthNegativeOne) { |
2010 TestIllegalTypedDataLength("Int8List", -1); | 1971 TestIllegalTypedDataLength("Int8List", -1); |
2011 } | 1972 } |
2012 TEST_CASE(Int8ListLengthSmiMin) { | 1973 TEST_CASE(Int8ListLengthSmiMin) { |
2013 TestIllegalTypedDataLength("Int8List", kSmiMin); | 1974 TestIllegalTypedDataLength("Int8List", kSmiMin); |
2014 } | 1975 } |
2015 TEST_CASE(Int8ListLengthOneTooMany) { | 1976 TEST_CASE(Int8ListLengthOneTooMany) { |
2016 const intptr_t kOneTooMany = | 1977 const intptr_t kOneTooMany = |
2017 TypedData::MaxElements(kTypedDataInt8ArrayCid) + 1; | 1978 TypedData::MaxElements(kTypedDataInt8ArrayCid) + 1; |
2018 ASSERT(kOneTooMany >= 0); | 1979 ASSERT(kOneTooMany >= 0); |
2019 TestIllegalTypedDataLength("Int8List", kOneTooMany); | 1980 TestIllegalTypedDataLength("Int8List", kOneTooMany); |
2020 } | 1981 } |
2021 | 1982 |
2022 | |
2023 TEST_CASE(Int8ListLengthMaxElements) { | 1983 TEST_CASE(Int8ListLengthMaxElements) { |
2024 const intptr_t max_elements = TypedData::MaxElements(kTypedDataInt8ArrayCid); | 1984 const intptr_t max_elements = TypedData::MaxElements(kTypedDataInt8ArrayCid); |
2025 char buffer[1024]; | 1985 char buffer[1024]; |
2026 OS::SNPrint(buffer, sizeof(buffer), | 1986 OS::SNPrint(buffer, sizeof(buffer), |
2027 "import 'dart:typed_data';\n" | 1987 "import 'dart:typed_data';\n" |
2028 "main() {\n" | 1988 "main() {\n" |
2029 " return new Int8List(%" Pd | 1989 " return new Int8List(%" Pd |
2030 ");\n" | 1990 ");\n" |
2031 "}\n", | 1991 "}\n", |
2032 max_elements); | 1992 max_elements); |
2033 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); | 1993 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); |
2034 EXPECT_VALID(lib); | 1994 EXPECT_VALID(lib); |
2035 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1995 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
2036 if (Dart_IsError(result)) { | 1996 if (Dart_IsError(result)) { |
2037 EXPECT_ERROR(result, "Out of Memory"); | 1997 EXPECT_ERROR(result, "Out of Memory"); |
2038 } else { | 1998 } else { |
2039 intptr_t actual = 0; | 1999 intptr_t actual = 0; |
2040 EXPECT_VALID(Dart_ListLength(result, &actual)); | 2000 EXPECT_VALID(Dart_ListLength(result, &actual)); |
2041 EXPECT_EQ(max_elements, actual); | 2001 EXPECT_EQ(max_elements, actual); |
2042 } | 2002 } |
2043 } | 2003 } |
2044 | 2004 |
2045 | |
2046 ISOLATE_UNIT_TEST_CASE(StringCodePointIterator) { | 2005 ISOLATE_UNIT_TEST_CASE(StringCodePointIterator) { |
2047 const String& str0 = String::Handle(String::New("")); | 2006 const String& str0 = String::Handle(String::New("")); |
2048 String::CodePointIterator it0(str0); | 2007 String::CodePointIterator it0(str0); |
2049 EXPECT(!it0.Next()); | 2008 EXPECT(!it0.Next()); |
2050 | 2009 |
2051 const String& str1 = String::Handle(String::New(" \xc3\xa7 ")); | 2010 const String& str1 = String::Handle(String::New(" \xc3\xa7 ")); |
2052 String::CodePointIterator it1(str1); | 2011 String::CodePointIterator it1(str1); |
2053 EXPECT(it1.Next()); | 2012 EXPECT(it1.Next()); |
2054 EXPECT_EQ(' ', it1.Current()); | 2013 EXPECT_EQ(' ', it1.Current()); |
2055 EXPECT(it1.Next()); | 2014 EXPECT(it1.Next()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2092 EXPECT_EQ(0x1D460, it3.Current()); | 2051 EXPECT_EQ(0x1D460, it3.Current()); |
2093 EXPECT(it3.Next()); | 2052 EXPECT(it3.Next()); |
2094 EXPECT_EQ(0x1D461, it3.Current()); | 2053 EXPECT_EQ(0x1D461, it3.Current()); |
2095 EXPECT(it3.Next()); | 2054 EXPECT(it3.Next()); |
2096 EXPECT_EQ(0x1D462, it3.Current()); | 2055 EXPECT_EQ(0x1D462, it3.Current()); |
2097 EXPECT(it3.Next()); | 2056 EXPECT(it3.Next()); |
2098 EXPECT_EQ(0x1D463, it3.Current()); | 2057 EXPECT_EQ(0x1D463, it3.Current()); |
2099 EXPECT(!it3.Next()); | 2058 EXPECT(!it3.Next()); |
2100 } | 2059 } |
2101 | 2060 |
2102 | |
2103 ISOLATE_UNIT_TEST_CASE(StringCodePointIteratorRange) { | 2061 ISOLATE_UNIT_TEST_CASE(StringCodePointIteratorRange) { |
2104 const String& str = String::Handle(String::New("foo bar baz")); | 2062 const String& str = String::Handle(String::New("foo bar baz")); |
2105 | 2063 |
2106 String::CodePointIterator it0(str, 3, 0); | 2064 String::CodePointIterator it0(str, 3, 0); |
2107 EXPECT(!it0.Next()); | 2065 EXPECT(!it0.Next()); |
2108 | 2066 |
2109 String::CodePointIterator it1(str, 4, 3); | 2067 String::CodePointIterator it1(str, 4, 3); |
2110 EXPECT(it1.Next()); | 2068 EXPECT(it1.Next()); |
2111 EXPECT_EQ('b', it1.Current()); | 2069 EXPECT_EQ('b', it1.Current()); |
2112 EXPECT(it1.Next()); | 2070 EXPECT(it1.Next()); |
2113 EXPECT_EQ('a', it1.Current()); | 2071 EXPECT_EQ('a', it1.Current()); |
2114 EXPECT(it1.Next()); | 2072 EXPECT(it1.Next()); |
2115 EXPECT_EQ('r', it1.Current()); | 2073 EXPECT_EQ('r', it1.Current()); |
2116 EXPECT(!it1.Next()); | 2074 EXPECT(!it1.Next()); |
2117 } | 2075 } |
2118 | 2076 |
2119 | |
2120 ISOLATE_UNIT_TEST_CASE(GrowableObjectArray) { | 2077 ISOLATE_UNIT_TEST_CASE(GrowableObjectArray) { |
2121 const int kArrayLen = 5; | 2078 const int kArrayLen = 5; |
2122 Smi& value = Smi::Handle(); | 2079 Smi& value = Smi::Handle(); |
2123 Smi& expected_value = Smi::Handle(); | 2080 Smi& expected_value = Smi::Handle(); |
2124 GrowableObjectArray& array = GrowableObjectArray::Handle(); | 2081 GrowableObjectArray& array = GrowableObjectArray::Handle(); |
2125 | 2082 |
2126 // Test basic growing functionality. | 2083 // Test basic growing functionality. |
2127 array = GrowableObjectArray::New(kArrayLen); | 2084 array = GrowableObjectArray::New(kArrayLen); |
2128 EXPECT_EQ(kArrayLen, array.Capacity()); | 2085 EXPECT_EQ(kArrayLen, array.Capacity()); |
2129 EXPECT_EQ(0, array.Length()); | 2086 EXPECT_EQ(0, array.Length()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2231 intptr_t capacity_before = heap->CapacityInWords(Heap::kOld); | 2188 intptr_t capacity_before = heap->CapacityInWords(Heap::kOld); |
2232 new_array = Array::MakeFixedLength(array); | 2189 new_array = Array::MakeFixedLength(array); |
2233 EXPECT_EQ(1, new_array.Length()); | 2190 EXPECT_EQ(1, new_array.Length()); |
2234 heap->CollectAllGarbage(); | 2191 heap->CollectAllGarbage(); |
2235 intptr_t capacity_after = heap->CapacityInWords(Heap::kOld); | 2192 intptr_t capacity_after = heap->CapacityInWords(Heap::kOld); |
2236 // Page should shrink. | 2193 // Page should shrink. |
2237 EXPECT_LT(capacity_after, capacity_before); | 2194 EXPECT_LT(capacity_after, capacity_before); |
2238 EXPECT_EQ(1, new_array.Length()); | 2195 EXPECT_EQ(1, new_array.Length()); |
2239 } | 2196 } |
2240 | 2197 |
2241 | |
2242 ISOLATE_UNIT_TEST_CASE(InternalTypedData) { | 2198 ISOLATE_UNIT_TEST_CASE(InternalTypedData) { |
2243 uint8_t data[] = {253, 254, 255, 0, 1, 2, 3, 4}; | 2199 uint8_t data[] = {253, 254, 255, 0, 1, 2, 3, 4}; |
2244 intptr_t data_length = ARRAY_SIZE(data); | 2200 intptr_t data_length = ARRAY_SIZE(data); |
2245 | 2201 |
2246 const TypedData& int8_array = | 2202 const TypedData& int8_array = |
2247 TypedData::Handle(TypedData::New(kTypedDataInt8ArrayCid, data_length)); | 2203 TypedData::Handle(TypedData::New(kTypedDataInt8ArrayCid, data_length)); |
2248 EXPECT(!int8_array.IsNull()); | 2204 EXPECT(!int8_array.IsNull()); |
2249 EXPECT_EQ(data_length, int8_array.Length()); | 2205 EXPECT_EQ(data_length, int8_array.Length()); |
2250 for (intptr_t i = 0; i < data_length; ++i) { | 2206 for (intptr_t i = 0; i < data_length; ++i) { |
2251 int8_array.SetInt8(i, data[i]); | 2207 int8_array.SetInt8(i, data[i]); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2287 EXPECT_EQ(int8_array.GetInt8(i), int8_array2.GetInt8(i)); | 2243 EXPECT_EQ(int8_array.GetInt8(i), int8_array2.GetInt8(i)); |
2288 } | 2244 } |
2289 for (intptr_t i = 0; i < data_length; ++i) { | 2245 for (intptr_t i = 0; i < data_length; ++i) { |
2290 int8_array.SetInt8(i, 123 + i); | 2246 int8_array.SetInt8(i, 123 + i); |
2291 } | 2247 } |
2292 for (intptr_t i = 0; i < data_length; ++i) { | 2248 for (intptr_t i = 0; i < data_length; ++i) { |
2293 EXPECT(int8_array.GetInt8(i) != int8_array2.GetInt8(i)); | 2249 EXPECT(int8_array.GetInt8(i) != int8_array2.GetInt8(i)); |
2294 } | 2250 } |
2295 } | 2251 } |
2296 | 2252 |
2297 | |
2298 ISOLATE_UNIT_TEST_CASE(ExternalTypedData) { | 2253 ISOLATE_UNIT_TEST_CASE(ExternalTypedData) { |
2299 uint8_t data[] = {253, 254, 255, 0, 1, 2, 3, 4}; | 2254 uint8_t data[] = {253, 254, 255, 0, 1, 2, 3, 4}; |
2300 intptr_t data_length = ARRAY_SIZE(data); | 2255 intptr_t data_length = ARRAY_SIZE(data); |
2301 | 2256 |
2302 const ExternalTypedData& int8_array = | 2257 const ExternalTypedData& int8_array = |
2303 ExternalTypedData::Handle(ExternalTypedData::New( | 2258 ExternalTypedData::Handle(ExternalTypedData::New( |
2304 kExternalTypedDataInt8ArrayCid, data, data_length)); | 2259 kExternalTypedDataInt8ArrayCid, data, data_length)); |
2305 EXPECT(!int8_array.IsNull()); | 2260 EXPECT(!int8_array.IsNull()); |
2306 EXPECT_EQ(data_length, int8_array.Length()); | 2261 EXPECT_EQ(data_length, int8_array.Length()); |
2307 | 2262 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2350 for (intptr_t i = 0; i < int8_array.Length(); ++i) { | 2305 for (intptr_t i = 0; i < int8_array.Length(); ++i) { |
2351 EXPECT_EQ(int8_array.GetInt8(i), uint8_array.GetInt8(i)); | 2306 EXPECT_EQ(int8_array.GetInt8(i), uint8_array.GetInt8(i)); |
2352 } | 2307 } |
2353 | 2308 |
2354 uint8_clamped_array.SetUint8(0, 123); | 2309 uint8_clamped_array.SetUint8(0, 123); |
2355 for (intptr_t i = 0; i < int8_array.Length(); ++i) { | 2310 for (intptr_t i = 0; i < int8_array.Length(); ++i) { |
2356 EXPECT_EQ(int8_array.GetUint8(i), uint8_clamped_array.GetUint8(i)); | 2311 EXPECT_EQ(int8_array.GetUint8(i), uint8_clamped_array.GetUint8(i)); |
2357 } | 2312 } |
2358 } | 2313 } |
2359 | 2314 |
2360 | |
2361 TEST_CASE(Script) { | 2315 TEST_CASE(Script) { |
2362 const char* url_chars = "builtin:test-case"; | 2316 const char* url_chars = "builtin:test-case"; |
2363 const char* source_chars = "This will not compile."; | 2317 const char* source_chars = "This will not compile."; |
2364 const String& url = String::Handle(String::New(url_chars)); | 2318 const String& url = String::Handle(String::New(url_chars)); |
2365 const String& source = String::Handle(String::New(source_chars)); | 2319 const String& source = String::Handle(String::New(source_chars)); |
2366 const Script& script = | 2320 const Script& script = |
2367 Script::Handle(Script::New(url, source, RawScript::kScriptTag)); | 2321 Script::Handle(Script::New(url, source, RawScript::kScriptTag)); |
2368 EXPECT(!script.IsNull()); | 2322 EXPECT(!script.IsNull()); |
2369 EXPECT(script.IsScript()); | 2323 EXPECT(script.IsScript()); |
2370 String& str = String::Handle(script.url()); | 2324 String& str = String::Handle(script.url()); |
(...skipping 10 matching lines...) Expand all Loading... |
2381 const char* kScript = "main() {}"; | 2335 const char* kScript = "main() {}"; |
2382 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | 2336 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
2383 EXPECT_VALID(h_lib); | 2337 EXPECT_VALID(h_lib); |
2384 Library& lib = Library::Handle(); | 2338 Library& lib = Library::Handle(); |
2385 lib ^= Api::UnwrapHandle(h_lib); | 2339 lib ^= Api::UnwrapHandle(h_lib); |
2386 EXPECT(!lib.IsNull()); | 2340 EXPECT(!lib.IsNull()); |
2387 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | 2341 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
2388 EXPECT_VALID(result); | 2342 EXPECT_VALID(result); |
2389 } | 2343 } |
2390 | 2344 |
2391 | |
2392 ISOLATE_UNIT_TEST_CASE(EmbeddedScript) { | 2345 ISOLATE_UNIT_TEST_CASE(EmbeddedScript) { |
2393 const char* url_chars = "builtin:test-case"; | 2346 const char* url_chars = "builtin:test-case"; |
2394 const char* text = | 2347 const char* text = |
2395 /* 1 */ | 2348 /* 1 */ |
2396 "<!DOCTYPE html>\n" | 2349 "<!DOCTYPE html>\n" |
2397 /* 2 */ | 2350 /* 2 */ |
2398 " ... more junk ...\n" | 2351 " ... more junk ...\n" |
2399 /* 3 */ | 2352 /* 3 */ |
2400 " <script type='application/dart'>main() {\n" | 2353 " <script type='application/dart'>main() {\n" |
2401 /* 4 */ | 2354 /* 4 */ |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2483 script.TokenRangeAtLine(6, &first_idx, &last_idx); | 2436 script.TokenRangeAtLine(6, &first_idx, &last_idx); |
2484 EXPECT_EQ(-1, first_idx.value()); | 2437 EXPECT_EQ(-1, first_idx.value()); |
2485 EXPECT_EQ(-1, last_idx.value()); | 2438 EXPECT_EQ(-1, last_idx.value()); |
2486 script.TokenRangeAtLine(1000, &first_idx, &last_idx); | 2439 script.TokenRangeAtLine(1000, &first_idx, &last_idx); |
2487 EXPECT_EQ(-1, first_idx.value()); | 2440 EXPECT_EQ(-1, first_idx.value()); |
2488 EXPECT_EQ(-1, last_idx.value()); | 2441 EXPECT_EQ(-1, last_idx.value()); |
2489 | 2442 |
2490 free(src_chars); | 2443 free(src_chars); |
2491 } | 2444 } |
2492 | 2445 |
2493 | |
2494 ISOLATE_UNIT_TEST_CASE(Context) { | 2446 ISOLATE_UNIT_TEST_CASE(Context) { |
2495 const int kNumVariables = 5; | 2447 const int kNumVariables = 5; |
2496 const Context& parent_context = Context::Handle(Context::New(0)); | 2448 const Context& parent_context = Context::Handle(Context::New(0)); |
2497 const Context& context = Context::Handle(Context::New(kNumVariables)); | 2449 const Context& context = Context::Handle(Context::New(kNumVariables)); |
2498 context.set_parent(parent_context); | 2450 context.set_parent(parent_context); |
2499 EXPECT_EQ(kNumVariables, context.num_variables()); | 2451 EXPECT_EQ(kNumVariables, context.num_variables()); |
2500 EXPECT(Context::Handle(context.parent()).raw() == parent_context.raw()); | 2452 EXPECT(Context::Handle(context.parent()).raw() == parent_context.raw()); |
2501 EXPECT_EQ(0, Context::Handle(context.parent()).num_variables()); | 2453 EXPECT_EQ(0, Context::Handle(context.parent()).num_variables()); |
2502 EXPECT(Context::Handle(Context::Handle(context.parent()).parent()).IsNull()); | 2454 EXPECT(Context::Handle(Context::Handle(context.parent()).parent()).IsNull()); |
2503 Object& variable = Object::Handle(context.At(0)); | 2455 Object& variable = Object::Handle(context.At(0)); |
2504 EXPECT(variable.IsNull()); | 2456 EXPECT(variable.IsNull()); |
2505 variable = context.At(kNumVariables - 1); | 2457 variable = context.At(kNumVariables - 1); |
2506 EXPECT(variable.IsNull()); | 2458 EXPECT(variable.IsNull()); |
2507 context.SetAt(0, Smi::Handle(Smi::New(2))); | 2459 context.SetAt(0, Smi::Handle(Smi::New(2))); |
2508 context.SetAt(2, Smi::Handle(Smi::New(3))); | 2460 context.SetAt(2, Smi::Handle(Smi::New(3))); |
2509 Smi& smi = Smi::Handle(); | 2461 Smi& smi = Smi::Handle(); |
2510 smi ^= context.At(0); | 2462 smi ^= context.At(0); |
2511 EXPECT_EQ(2, smi.Value()); | 2463 EXPECT_EQ(2, smi.Value()); |
2512 smi ^= context.At(2); | 2464 smi ^= context.At(2); |
2513 EXPECT_EQ(3, smi.Value()); | 2465 EXPECT_EQ(3, smi.Value()); |
2514 } | 2466 } |
2515 | 2467 |
2516 | |
2517 ISOLATE_UNIT_TEST_CASE(ContextScope) { | 2468 ISOLATE_UNIT_TEST_CASE(ContextScope) { |
2518 const intptr_t parent_scope_function_level = 0; | 2469 const intptr_t parent_scope_function_level = 0; |
2519 LocalScope* parent_scope = | 2470 LocalScope* parent_scope = |
2520 new LocalScope(NULL, parent_scope_function_level, 0); | 2471 new LocalScope(NULL, parent_scope_function_level, 0); |
2521 | 2472 |
2522 const intptr_t local_scope_function_level = 1; | 2473 const intptr_t local_scope_function_level = 1; |
2523 LocalScope* local_scope = | 2474 LocalScope* local_scope = |
2524 new LocalScope(parent_scope, local_scope_function_level, 0); | 2475 new LocalScope(parent_scope, local_scope_function_level, 0); |
2525 | 2476 |
2526 const Type& dynamic_type = Type::ZoneHandle(Type::DynamicType()); | 2477 const Type& dynamic_type = Type::ZoneHandle(Type::DynamicType()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2609 // var b was not captured. | 2560 // var b was not captured. |
2610 EXPECT(outer_scope->LocalLookupVariable(b) == NULL); | 2561 EXPECT(outer_scope->LocalLookupVariable(b) == NULL); |
2611 | 2562 |
2612 var_c = outer_scope->LocalLookupVariable(c); | 2563 var_c = outer_scope->LocalLookupVariable(c); |
2613 EXPECT(var_c->is_captured()); | 2564 EXPECT(var_c->is_captured()); |
2614 EXPECT_EQ(2, var_c->index()); | 2565 EXPECT_EQ(2, var_c->index()); |
2615 EXPECT_EQ(parent_scope_context_level - local_scope_context_level, | 2566 EXPECT_EQ(parent_scope_context_level - local_scope_context_level, |
2616 var_c->owner()->context_level()); // Adjusted context level. | 2567 var_c->owner()->context_level()); // Adjusted context level. |
2617 } | 2568 } |
2618 | 2569 |
2619 | |
2620 ISOLATE_UNIT_TEST_CASE(Closure) { | 2570 ISOLATE_UNIT_TEST_CASE(Closure) { |
2621 // Allocate the class first. | 2571 // Allocate the class first. |
2622 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); | 2572 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); |
2623 const Script& script = Script::Handle(); | 2573 const Script& script = Script::Handle(); |
2624 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 2574 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
2625 const Array& functions = Array::Handle(Array::New(1)); | 2575 const Array& functions = Array::Handle(Array::New(1)); |
2626 | 2576 |
2627 const Context& context = Context::Handle(Context::New(0)); | 2577 const Context& context = Context::Handle(Context::New(0)); |
2628 Function& parent = Function::Handle(); | 2578 Function& parent = Function::Handle(); |
2629 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); | 2579 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); |
(...skipping 11 matching lines...) Expand all Loading... |
2641 Closure::New(Object::null_type_arguments(), Object::null_type_arguments(), | 2591 Closure::New(Object::null_type_arguments(), Object::null_type_arguments(), |
2642 function, context)); | 2592 function, context)); |
2643 const Class& closure_class = Class::Handle(closure.clazz()); | 2593 const Class& closure_class = Class::Handle(closure.clazz()); |
2644 EXPECT_EQ(closure_class.id(), kClosureCid); | 2594 EXPECT_EQ(closure_class.id(), kClosureCid); |
2645 const Function& closure_function = Function::Handle(closure.function()); | 2595 const Function& closure_function = Function::Handle(closure.function()); |
2646 EXPECT_EQ(closure_function.raw(), function.raw()); | 2596 EXPECT_EQ(closure_function.raw(), function.raw()); |
2647 const Context& closure_context = Context::Handle(closure.context()); | 2597 const Context& closure_context = Context::Handle(closure.context()); |
2648 EXPECT_EQ(closure_context.raw(), context.raw()); | 2598 EXPECT_EQ(closure_context.raw(), context.raw()); |
2649 } | 2599 } |
2650 | 2600 |
2651 | |
2652 ISOLATE_UNIT_TEST_CASE(ObjectPrinting) { | 2601 ISOLATE_UNIT_TEST_CASE(ObjectPrinting) { |
2653 // Simple Smis. | 2602 // Simple Smis. |
2654 EXPECT_STREQ("2", Smi::Handle(Smi::New(2)).ToCString()); | 2603 EXPECT_STREQ("2", Smi::Handle(Smi::New(2)).ToCString()); |
2655 EXPECT_STREQ("-15", Smi::Handle(Smi::New(-15)).ToCString()); | 2604 EXPECT_STREQ("-15", Smi::Handle(Smi::New(-15)).ToCString()); |
2656 | 2605 |
2657 // bool class and true/false values. | 2606 // bool class and true/false values. |
2658 ObjectStore* object_store = Isolate::Current()->object_store(); | 2607 ObjectStore* object_store = Isolate::Current()->object_store(); |
2659 const Class& bool_class = Class::Handle(object_store->bool_class()); | 2608 const Class& bool_class = Class::Handle(object_store->bool_class()); |
2660 EXPECT_STREQ("Library:'dart:core' Class: bool", bool_class.ToCString()); | 2609 EXPECT_STREQ("Library:'dart:core' Class: bool", bool_class.ToCString()); |
2661 EXPECT_STREQ("true", Bool::True().ToCString()); | 2610 EXPECT_STREQ("true", Bool::True().ToCString()); |
2662 EXPECT_STREQ("false", Bool::False().ToCString()); | 2611 EXPECT_STREQ("false", Bool::False().ToCString()); |
2663 | 2612 |
2664 // Strings. | 2613 // Strings. |
2665 EXPECT_STREQ("Sugarbowl", | 2614 EXPECT_STREQ("Sugarbowl", |
2666 String::Handle(String::New("Sugarbowl")).ToCString()); | 2615 String::Handle(String::New("Sugarbowl")).ToCString()); |
2667 } | 2616 } |
2668 | 2617 |
2669 | |
2670 ISOLATE_UNIT_TEST_CASE(CheckedHandle) { | 2618 ISOLATE_UNIT_TEST_CASE(CheckedHandle) { |
2671 // Ensure that null handles have the correct C++ vtable setup. | 2619 // Ensure that null handles have the correct C++ vtable setup. |
2672 const String& str1 = String::Handle(); | 2620 const String& str1 = String::Handle(); |
2673 EXPECT(str1.IsString()); | 2621 EXPECT(str1.IsString()); |
2674 EXPECT(str1.IsNull()); | 2622 EXPECT(str1.IsNull()); |
2675 const String& str2 = String::CheckedHandle(Object::null()); | 2623 const String& str2 = String::CheckedHandle(Object::null()); |
2676 EXPECT(str2.IsString()); | 2624 EXPECT(str2.IsString()); |
2677 EXPECT(str2.IsNull()); | 2625 EXPECT(str2.IsNull()); |
2678 String& str3 = String::Handle(); | 2626 String& str3 = String::Handle(); |
2679 str3 ^= Object::null(); | 2627 str3 ^= Object::null(); |
2680 EXPECT(str3.IsString()); | 2628 EXPECT(str3.IsString()); |
2681 EXPECT(str3.IsNull()); | 2629 EXPECT(str3.IsNull()); |
2682 EXPECT(!str3.IsOneByteString()); | 2630 EXPECT(!str3.IsOneByteString()); |
2683 str3 = String::New("Steep and Deep!"); | 2631 str3 = String::New("Steep and Deep!"); |
2684 EXPECT(str3.IsString()); | 2632 EXPECT(str3.IsString()); |
2685 EXPECT(str3.IsOneByteString()); | 2633 EXPECT(str3.IsOneByteString()); |
2686 str3 = OneByteString::null(); | 2634 str3 = OneByteString::null(); |
2687 EXPECT(str3.IsString()); | 2635 EXPECT(str3.IsString()); |
2688 EXPECT(!str3.IsOneByteString()); | 2636 EXPECT(!str3.IsOneByteString()); |
2689 } | 2637 } |
2690 | 2638 |
2691 | |
2692 static RawLibrary* CreateDummyLibrary(const String& library_name) { | 2639 static RawLibrary* CreateDummyLibrary(const String& library_name) { |
2693 return Library::New(library_name); | 2640 return Library::New(library_name); |
2694 } | 2641 } |
2695 | 2642 |
2696 | |
2697 static RawFunction* CreateFunction(const char* name) { | 2643 static RawFunction* CreateFunction(const char* name) { |
2698 Thread* thread = Thread::Current(); | 2644 Thread* thread = Thread::Current(); |
2699 const String& class_name = String::Handle(Symbols::New(thread, "ownerClass")); | 2645 const String& class_name = String::Handle(Symbols::New(thread, "ownerClass")); |
2700 const String& lib_name = String::Handle(Symbols::New(thread, "ownerLibrary")); | 2646 const String& lib_name = String::Handle(Symbols::New(thread, "ownerLibrary")); |
2701 const Script& script = Script::Handle(); | 2647 const Script& script = Script::Handle(); |
2702 const Class& owner_class = | 2648 const Class& owner_class = |
2703 Class::Handle(CreateDummyClass(class_name, script)); | 2649 Class::Handle(CreateDummyClass(class_name, script)); |
2704 const Library& owner_library = Library::Handle(CreateDummyLibrary(lib_name)); | 2650 const Library& owner_library = Library::Handle(CreateDummyLibrary(lib_name)); |
2705 owner_class.set_library(owner_library); | 2651 owner_class.set_library(owner_library); |
2706 const String& function_name = String::ZoneHandle(Symbols::New(thread, name)); | 2652 const String& function_name = String::ZoneHandle(Symbols::New(thread, name)); |
2707 return Function::New(function_name, RawFunction::kRegularFunction, true, | 2653 return Function::New(function_name, RawFunction::kRegularFunction, true, |
2708 false, false, false, false, owner_class, | 2654 false, false, false, false, owner_class, |
2709 TokenPosition::kMinSource); | 2655 TokenPosition::kMinSource); |
2710 } | 2656 } |
2711 | 2657 |
2712 | |
2713 // Test for Code and Instruction object creation. | 2658 // Test for Code and Instruction object creation. |
2714 ISOLATE_UNIT_TEST_CASE(Code) { | 2659 ISOLATE_UNIT_TEST_CASE(Code) { |
2715 extern void GenerateIncrement(Assembler * assembler); | 2660 extern void GenerateIncrement(Assembler * assembler); |
2716 Assembler _assembler_; | 2661 Assembler _assembler_; |
2717 GenerateIncrement(&_assembler_); | 2662 GenerateIncrement(&_assembler_); |
2718 const Function& function = Function::Handle(CreateFunction("Test_Code")); | 2663 const Function& function = Function::Handle(CreateFunction("Test_Code")); |
2719 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); | 2664 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); |
2720 function.AttachCode(code); | 2665 function.AttachCode(code); |
2721 const Instructions& instructions = Instructions::Handle(code.instructions()); | 2666 const Instructions& instructions = Instructions::Handle(code.instructions()); |
2722 uword payload_start = instructions.PayloadStart(); | 2667 uword payload_start = instructions.PayloadStart(); |
2723 EXPECT_EQ(instructions.raw(), Instructions::FromPayloadStart(payload_start)); | 2668 EXPECT_EQ(instructions.raw(), Instructions::FromPayloadStart(payload_start)); |
2724 const Object& result = | 2669 const Object& result = |
2725 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); | 2670 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); |
2726 EXPECT_EQ(1, Smi::Cast(result).Value()); | 2671 EXPECT_EQ(1, Smi::Cast(result).Value()); |
2727 } | 2672 } |
2728 | 2673 |
2729 | |
2730 // Test for immutability of generated instructions. The test crashes with a | 2674 // Test for immutability of generated instructions. The test crashes with a |
2731 // segmentation fault when writing into it. | 2675 // segmentation fault when writing into it. |
2732 ISOLATE_UNIT_TEST_CASE(CodeImmutability) { | 2676 ISOLATE_UNIT_TEST_CASE(CodeImmutability) { |
2733 bool stack_trace_collection_enabled = | 2677 bool stack_trace_collection_enabled = |
2734 MallocHooks::stack_trace_collection_enabled(); | 2678 MallocHooks::stack_trace_collection_enabled(); |
2735 MallocHooks::set_stack_trace_collection_enabled(false); | 2679 MallocHooks::set_stack_trace_collection_enabled(false); |
2736 extern void GenerateIncrement(Assembler * assembler); | 2680 extern void GenerateIncrement(Assembler * assembler); |
2737 Assembler _assembler_; | 2681 Assembler _assembler_; |
2738 GenerateIncrement(&_assembler_); | 2682 GenerateIncrement(&_assembler_); |
2739 const Function& function = Function::Handle(CreateFunction("Test_Code")); | 2683 const Function& function = Function::Handle(CreateFunction("Test_Code")); |
2740 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); | 2684 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); |
2741 function.AttachCode(code); | 2685 function.AttachCode(code); |
2742 Instructions& instructions = Instructions::Handle(code.instructions()); | 2686 Instructions& instructions = Instructions::Handle(code.instructions()); |
2743 uword payload_start = instructions.PayloadStart(); | 2687 uword payload_start = instructions.PayloadStart(); |
2744 EXPECT_EQ(instructions.raw(), Instructions::FromPayloadStart(payload_start)); | 2688 EXPECT_EQ(instructions.raw(), Instructions::FromPayloadStart(payload_start)); |
2745 // Try writing into the generated code, expected to crash. | 2689 // Try writing into the generated code, expected to crash. |
2746 *(reinterpret_cast<char*>(payload_start) + 1) = 1; | 2690 *(reinterpret_cast<char*>(payload_start) + 1) = 1; |
2747 if (!FLAG_write_protect_code) { | 2691 if (!FLAG_write_protect_code) { |
2748 // Since this test is expected to crash, crash if write protection of code | 2692 // Since this test is expected to crash, crash if write protection of code |
2749 // is switched off. | 2693 // is switched off. |
2750 // TODO(regis, fschneider): Should this be FATAL() instead? | 2694 // TODO(regis, fschneider): Should this be FATAL() instead? |
2751 OS::DebugBreak(); | 2695 OS::DebugBreak(); |
2752 } | 2696 } |
2753 MallocHooks::set_stack_trace_collection_enabled( | 2697 MallocHooks::set_stack_trace_collection_enabled( |
2754 stack_trace_collection_enabled); | 2698 stack_trace_collection_enabled); |
2755 } | 2699 } |
2756 | 2700 |
2757 | |
2758 // Test for Embedded String object in the instructions. | 2701 // Test for Embedded String object in the instructions. |
2759 ISOLATE_UNIT_TEST_CASE(EmbedStringInCode) { | 2702 ISOLATE_UNIT_TEST_CASE(EmbedStringInCode) { |
2760 extern void GenerateEmbedStringInCode(Assembler * assembler, const char* str); | 2703 extern void GenerateEmbedStringInCode(Assembler * assembler, const char* str); |
2761 const char* kHello = "Hello World!"; | 2704 const char* kHello = "Hello World!"; |
2762 word expected_length = static_cast<word>(strlen(kHello)); | 2705 word expected_length = static_cast<word>(strlen(kHello)); |
2763 Assembler _assembler_; | 2706 Assembler _assembler_; |
2764 GenerateEmbedStringInCode(&_assembler_, kHello); | 2707 GenerateEmbedStringInCode(&_assembler_, kHello); |
2765 const Function& function = | 2708 const Function& function = |
2766 Function::Handle(CreateFunction("Test_EmbedStringInCode")); | 2709 Function::Handle(CreateFunction("Test_EmbedStringInCode")); |
2767 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); | 2710 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); |
2768 function.AttachCode(code); | 2711 function.AttachCode(code); |
2769 const Object& result = | 2712 const Object& result = |
2770 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); | 2713 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); |
2771 EXPECT(result.raw()->IsHeapObject()); | 2714 EXPECT(result.raw()->IsHeapObject()); |
2772 String& string_object = String::Handle(); | 2715 String& string_object = String::Handle(); |
2773 string_object ^= result.raw(); | 2716 string_object ^= result.raw(); |
2774 EXPECT(string_object.Length() == expected_length); | 2717 EXPECT(string_object.Length() == expected_length); |
2775 for (int i = 0; i < expected_length; i++) { | 2718 for (int i = 0; i < expected_length; i++) { |
2776 EXPECT(string_object.CharAt(i) == kHello[i]); | 2719 EXPECT(string_object.CharAt(i) == kHello[i]); |
2777 } | 2720 } |
2778 } | 2721 } |
2779 | 2722 |
2780 | |
2781 // Test for Embedded Smi object in the instructions. | 2723 // Test for Embedded Smi object in the instructions. |
2782 ISOLATE_UNIT_TEST_CASE(EmbedSmiInCode) { | 2724 ISOLATE_UNIT_TEST_CASE(EmbedSmiInCode) { |
2783 extern void GenerateEmbedSmiInCode(Assembler * assembler, intptr_t value); | 2725 extern void GenerateEmbedSmiInCode(Assembler * assembler, intptr_t value); |
2784 const intptr_t kSmiTestValue = 5; | 2726 const intptr_t kSmiTestValue = 5; |
2785 Assembler _assembler_; | 2727 Assembler _assembler_; |
2786 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); | 2728 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); |
2787 const Function& function = | 2729 const Function& function = |
2788 Function::Handle(CreateFunction("Test_EmbedSmiInCode")); | 2730 Function::Handle(CreateFunction("Test_EmbedSmiInCode")); |
2789 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); | 2731 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); |
2790 function.AttachCode(code); | 2732 function.AttachCode(code); |
2791 const Object& result = | 2733 const Object& result = |
2792 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); | 2734 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); |
2793 EXPECT(Smi::Cast(result).Value() == kSmiTestValue); | 2735 EXPECT(Smi::Cast(result).Value() == kSmiTestValue); |
2794 } | 2736 } |
2795 | 2737 |
2796 | |
2797 #if defined(ARCH_IS_64_BIT) | 2738 #if defined(ARCH_IS_64_BIT) |
2798 // Test for Embedded Smi object in the instructions. | 2739 // Test for Embedded Smi object in the instructions. |
2799 ISOLATE_UNIT_TEST_CASE(EmbedSmiIn64BitCode) { | 2740 ISOLATE_UNIT_TEST_CASE(EmbedSmiIn64BitCode) { |
2800 extern void GenerateEmbedSmiInCode(Assembler * assembler, intptr_t value); | 2741 extern void GenerateEmbedSmiInCode(Assembler * assembler, intptr_t value); |
2801 const intptr_t kSmiTestValue = DART_INT64_C(5) << 32; | 2742 const intptr_t kSmiTestValue = DART_INT64_C(5) << 32; |
2802 Assembler _assembler_; | 2743 Assembler _assembler_; |
2803 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); | 2744 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); |
2804 const Function& function = | 2745 const Function& function = |
2805 Function::Handle(CreateFunction("Test_EmbedSmiIn64BitCode")); | 2746 Function::Handle(CreateFunction("Test_EmbedSmiIn64BitCode")); |
2806 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); | 2747 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); |
2807 function.AttachCode(code); | 2748 function.AttachCode(code); |
2808 const Object& result = | 2749 const Object& result = |
2809 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); | 2750 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); |
2810 EXPECT(Smi::Cast(result).Value() == kSmiTestValue); | 2751 EXPECT(Smi::Cast(result).Value() == kSmiTestValue); |
2811 } | 2752 } |
2812 #endif // ARCH_IS_64_BIT | 2753 #endif // ARCH_IS_64_BIT |
2813 | 2754 |
2814 | |
2815 ISOLATE_UNIT_TEST_CASE(ExceptionHandlers) { | 2755 ISOLATE_UNIT_TEST_CASE(ExceptionHandlers) { |
2816 const int kNumEntries = 4; | 2756 const int kNumEntries = 4; |
2817 // Add an exception handler table to the code. | 2757 // Add an exception handler table to the code. |
2818 ExceptionHandlers& exception_handlers = ExceptionHandlers::Handle(); | 2758 ExceptionHandlers& exception_handlers = ExceptionHandlers::Handle(); |
2819 exception_handlers ^= ExceptionHandlers::New(kNumEntries); | 2759 exception_handlers ^= ExceptionHandlers::New(kNumEntries); |
2820 const bool kNeedsStackTrace = true; | 2760 const bool kNeedsStackTrace = true; |
2821 const bool kNoStackTrace = false; | 2761 const bool kNoStackTrace = false; |
2822 exception_handlers.SetHandlerInfo(0, -1, 20u, kNeedsStackTrace, false, | 2762 exception_handlers.SetHandlerInfo(0, -1, 20u, kNeedsStackTrace, false, |
2823 TokenPosition::kNoSource, true); | 2763 TokenPosition::kNoSource, true); |
2824 exception_handlers.SetHandlerInfo(1, 0, 30u, kNeedsStackTrace, false, | 2764 exception_handlers.SetHandlerInfo(1, 0, 30u, kNeedsStackTrace, false, |
(...skipping 21 matching lines...) Expand all Loading... |
2846 EXPECT_EQ(20u, handlers.HandlerPCOffset(0)); | 2786 EXPECT_EQ(20u, handlers.HandlerPCOffset(0)); |
2847 EXPECT(handlers.NeedsStackTrace(0)); | 2787 EXPECT(handlers.NeedsStackTrace(0)); |
2848 EXPECT(!handlers.HasCatchAll(0)); | 2788 EXPECT(!handlers.HasCatchAll(0)); |
2849 EXPECT_EQ(20u, info.handler_pc_offset); | 2789 EXPECT_EQ(20u, info.handler_pc_offset); |
2850 EXPECT_EQ(1, handlers.OuterTryIndex(3)); | 2790 EXPECT_EQ(1, handlers.OuterTryIndex(3)); |
2851 EXPECT_EQ(150u, handlers.HandlerPCOffset(3)); | 2791 EXPECT_EQ(150u, handlers.HandlerPCOffset(3)); |
2852 EXPECT(!handlers.NeedsStackTrace(3)); | 2792 EXPECT(!handlers.NeedsStackTrace(3)); |
2853 EXPECT(handlers.HasCatchAll(3)); | 2793 EXPECT(handlers.HasCatchAll(3)); |
2854 } | 2794 } |
2855 | 2795 |
2856 | |
2857 ISOLATE_UNIT_TEST_CASE(PcDescriptors) { | 2796 ISOLATE_UNIT_TEST_CASE(PcDescriptors) { |
2858 DescriptorList* builder = new DescriptorList(0); | 2797 DescriptorList* builder = new DescriptorList(0); |
2859 | 2798 |
2860 // kind, pc_offset, deopt_id, token_pos, try_index | 2799 // kind, pc_offset, deopt_id, token_pos, try_index |
2861 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 1, TokenPosition(20), 1); | 2800 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 1, TokenPosition(20), 1); |
2862 builder->AddDescriptor(RawPcDescriptors::kDeopt, 20, 2, TokenPosition(30), 0); | 2801 builder->AddDescriptor(RawPcDescriptors::kDeopt, 20, 2, TokenPosition(30), 0); |
2863 builder->AddDescriptor(RawPcDescriptors::kOther, 30, 3, TokenPosition(40), 1); | 2802 builder->AddDescriptor(RawPcDescriptors::kOther, 30, 3, TokenPosition(40), 1); |
2864 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 4, TokenPosition(40), 2); | 2803 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 4, TokenPosition(40), 2); |
2865 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 5, TokenPosition(80), 3); | 2804 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 5, TokenPosition(80), 3); |
2866 builder->AddDescriptor(RawPcDescriptors::kOther, 80, 6, TokenPosition(150), | 2805 builder->AddDescriptor(RawPcDescriptors::kOther, 80, 6, TokenPosition(150), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2904 EXPECT_EQ(150, iter.TokenPos().value()); | 2843 EXPECT_EQ(150, iter.TokenPos().value()); |
2905 | 2844 |
2906 EXPECT_EQ(3, iter.TryIndex()); | 2845 EXPECT_EQ(3, iter.TryIndex()); |
2907 EXPECT_EQ(static_cast<uword>(80), iter.PcOffset()); | 2846 EXPECT_EQ(static_cast<uword>(80), iter.PcOffset()); |
2908 EXPECT_EQ(150, iter.TokenPos().value()); | 2847 EXPECT_EQ(150, iter.TokenPos().value()); |
2909 EXPECT_EQ(RawPcDescriptors::kOther, iter.Kind()); | 2848 EXPECT_EQ(RawPcDescriptors::kOther, iter.Kind()); |
2910 | 2849 |
2911 EXPECT_EQ(false, iter.MoveNext()); | 2850 EXPECT_EQ(false, iter.MoveNext()); |
2912 } | 2851 } |
2913 | 2852 |
2914 | |
2915 ISOLATE_UNIT_TEST_CASE(PcDescriptorsLargeDeltas) { | 2853 ISOLATE_UNIT_TEST_CASE(PcDescriptorsLargeDeltas) { |
2916 DescriptorList* builder = new DescriptorList(0); | 2854 DescriptorList* builder = new DescriptorList(0); |
2917 | 2855 |
2918 // kind, pc_offset, deopt_id, token_pos, try_index | 2856 // kind, pc_offset, deopt_id, token_pos, try_index |
2919 builder->AddDescriptor(RawPcDescriptors::kOther, 100, 1, TokenPosition(200), | 2857 builder->AddDescriptor(RawPcDescriptors::kOther, 100, 1, TokenPosition(200), |
2920 1); | 2858 1); |
2921 builder->AddDescriptor(RawPcDescriptors::kDeopt, 200, 2, TokenPosition(300), | 2859 builder->AddDescriptor(RawPcDescriptors::kDeopt, 200, 2, TokenPosition(300), |
2922 0); | 2860 0); |
2923 builder->AddDescriptor(RawPcDescriptors::kOther, 300, 3, TokenPosition(400), | 2861 builder->AddDescriptor(RawPcDescriptors::kOther, 300, 3, TokenPosition(400), |
2924 1); | 2862 1); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2966 EXPECT_EQ(150, iter.TokenPos().value()); | 2904 EXPECT_EQ(150, iter.TokenPos().value()); |
2967 | 2905 |
2968 EXPECT_EQ(3, iter.TryIndex()); | 2906 EXPECT_EQ(3, iter.TryIndex()); |
2969 EXPECT_EQ(static_cast<uword>(800), iter.PcOffset()); | 2907 EXPECT_EQ(static_cast<uword>(800), iter.PcOffset()); |
2970 EXPECT_EQ(150, iter.TokenPos().value()); | 2908 EXPECT_EQ(150, iter.TokenPos().value()); |
2971 EXPECT_EQ(RawPcDescriptors::kOther, iter.Kind()); | 2909 EXPECT_EQ(RawPcDescriptors::kOther, iter.Kind()); |
2972 | 2910 |
2973 EXPECT_EQ(false, iter.MoveNext()); | 2911 EXPECT_EQ(false, iter.MoveNext()); |
2974 } | 2912 } |
2975 | 2913 |
2976 | |
2977 static RawClass* CreateTestClass(const char* name) { | 2914 static RawClass* CreateTestClass(const char* name) { |
2978 const String& class_name = | 2915 const String& class_name = |
2979 String::Handle(Symbols::New(Thread::Current(), name)); | 2916 String::Handle(Symbols::New(Thread::Current(), name)); |
2980 const Class& cls = | 2917 const Class& cls = |
2981 Class::Handle(CreateDummyClass(class_name, Script::Handle())); | 2918 Class::Handle(CreateDummyClass(class_name, Script::Handle())); |
2982 return cls.raw(); | 2919 return cls.raw(); |
2983 } | 2920 } |
2984 | 2921 |
2985 | |
2986 static RawField* CreateTestField(const char* name) { | 2922 static RawField* CreateTestField(const char* name) { |
2987 const Class& cls = Class::Handle(CreateTestClass("global:")); | 2923 const Class& cls = Class::Handle(CreateTestClass("global:")); |
2988 const String& field_name = | 2924 const String& field_name = |
2989 String::Handle(Symbols::New(Thread::Current(), name)); | 2925 String::Handle(Symbols::New(Thread::Current(), name)); |
2990 const Field& field = Field::Handle( | 2926 const Field& field = Field::Handle( |
2991 Field::New(field_name, true, false, false, true, cls, | 2927 Field::New(field_name, true, false, false, true, cls, |
2992 Object::dynamic_type(), TokenPosition::kMinSource)); | 2928 Object::dynamic_type(), TokenPosition::kMinSource)); |
2993 return field.raw(); | 2929 return field.raw(); |
2994 } | 2930 } |
2995 | 2931 |
2996 | |
2997 ISOLATE_UNIT_TEST_CASE(ClassDictionaryIterator) { | 2932 ISOLATE_UNIT_TEST_CASE(ClassDictionaryIterator) { |
2998 Class& ae66 = Class::ZoneHandle(CreateTestClass("Ae6/6")); | 2933 Class& ae66 = Class::ZoneHandle(CreateTestClass("Ae6/6")); |
2999 Class& re44 = Class::ZoneHandle(CreateTestClass("Re4/4")); | 2934 Class& re44 = Class::ZoneHandle(CreateTestClass("Re4/4")); |
3000 Field& ce68 = Field::ZoneHandle(CreateTestField("Ce6/8")); | 2935 Field& ce68 = Field::ZoneHandle(CreateTestField("Ce6/8")); |
3001 Field& tee = Field::ZoneHandle(CreateTestField("TEE")); | 2936 Field& tee = Field::ZoneHandle(CreateTestField("TEE")); |
3002 String& url = String::ZoneHandle(String::New("SBB")); | 2937 String& url = String::ZoneHandle(String::New("SBB")); |
3003 Library& lib = Library::Handle(Library::New(url)); | 2938 Library& lib = Library::Handle(Library::New(url)); |
3004 lib.AddClass(ae66); | 2939 lib.AddClass(ae66); |
3005 lib.AddObject(ce68, String::ZoneHandle(ce68.name())); | 2940 lib.AddObject(ce68, String::ZoneHandle(ce68.name())); |
3006 lib.AddClass(re44); | 2941 lib.AddClass(re44); |
3007 lib.AddObject(tee, String::ZoneHandle(tee.name())); | 2942 lib.AddObject(tee, String::ZoneHandle(tee.name())); |
3008 ClassDictionaryIterator iterator(lib); | 2943 ClassDictionaryIterator iterator(lib); |
3009 int count = 0; | 2944 int count = 0; |
3010 Class& cls = Class::Handle(); | 2945 Class& cls = Class::Handle(); |
3011 while (iterator.HasNext()) { | 2946 while (iterator.HasNext()) { |
3012 cls = iterator.GetNextClass(); | 2947 cls = iterator.GetNextClass(); |
3013 EXPECT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw())); | 2948 EXPECT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw())); |
3014 count++; | 2949 count++; |
3015 } | 2950 } |
3016 EXPECT(count == 2); | 2951 EXPECT(count == 2); |
3017 } | 2952 } |
3018 | 2953 |
3019 | |
3020 static RawFunction* GetDummyTarget(const char* name) { | 2954 static RawFunction* GetDummyTarget(const char* name) { |
3021 const String& function_name = | 2955 const String& function_name = |
3022 String::Handle(Symbols::New(Thread::Current(), name)); | 2956 String::Handle(Symbols::New(Thread::Current(), name)); |
3023 const Class& cls = | 2957 const Class& cls = |
3024 Class::Handle(CreateDummyClass(function_name, Script::Handle())); | 2958 Class::Handle(CreateDummyClass(function_name, Script::Handle())); |
3025 const bool is_static = false; | 2959 const bool is_static = false; |
3026 const bool is_const = false; | 2960 const bool is_const = false; |
3027 const bool is_abstract = false; | 2961 const bool is_abstract = false; |
3028 const bool is_external = false; | 2962 const bool is_external = false; |
3029 const bool is_native = false; | 2963 const bool is_native = false; |
3030 return Function::New(function_name, RawFunction::kRegularFunction, is_static, | 2964 return Function::New(function_name, RawFunction::kRegularFunction, is_static, |
3031 is_const, is_abstract, is_external, is_native, cls, | 2965 is_const, is_abstract, is_external, is_native, cls, |
3032 TokenPosition::kMinSource); | 2966 TokenPosition::kMinSource); |
3033 } | 2967 } |
3034 | 2968 |
3035 | |
3036 ISOLATE_UNIT_TEST_CASE(ICData) { | 2969 ISOLATE_UNIT_TEST_CASE(ICData) { |
3037 Function& function = Function::Handle(GetDummyTarget("Bern")); | 2970 Function& function = Function::Handle(GetDummyTarget("Bern")); |
3038 const intptr_t id = 12; | 2971 const intptr_t id = 12; |
3039 const intptr_t num_args_tested = 1; | 2972 const intptr_t num_args_tested = 1; |
3040 const String& target_name = String::Handle(Symbols::New(thread, "Thun")); | 2973 const String& target_name = String::Handle(Symbols::New(thread, "Thun")); |
3041 const intptr_t kTypeArgsLen = 0; | 2974 const intptr_t kTypeArgsLen = 0; |
3042 const intptr_t kNumArgs = 1; | 2975 const intptr_t kNumArgs = 1; |
3043 const Array& args_descriptor = Array::Handle( | 2976 const Array& args_descriptor = Array::Handle( |
3044 ArgumentsDescriptor::New(kTypeArgsLen, kNumArgs, Object::null_array())); | 2977 ArgumentsDescriptor::New(kTypeArgsLen, kNumArgs, Object::null_array())); |
3045 ICData& o1 = ICData::Handle(); | 2978 ICData& o1 = ICData::Handle(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3100 EXPECT_EQ(target1.raw(), test_target.raw()); | 3033 EXPECT_EQ(target1.raw(), test_target.raw()); |
3101 | 3034 |
3102 // Check ICData for unoptimized static calls. | 3035 // Check ICData for unoptimized static calls. |
3103 const intptr_t kNumArgsChecked = 0; | 3036 const intptr_t kNumArgsChecked = 0; |
3104 const ICData& scall_icdata = ICData::Handle(ICData::New( | 3037 const ICData& scall_icdata = ICData::Handle(ICData::New( |
3105 function, target_name, args_descriptor, 57, kNumArgsChecked, false)); | 3038 function, target_name, args_descriptor, 57, kNumArgsChecked, false)); |
3106 scall_icdata.AddTarget(target1); | 3039 scall_icdata.AddTarget(target1); |
3107 EXPECT_EQ(target1.raw(), scall_icdata.GetTargetAt(0)); | 3040 EXPECT_EQ(target1.raw(), scall_icdata.GetTargetAt(0)); |
3108 } | 3041 } |
3109 | 3042 |
3110 | |
3111 ISOLATE_UNIT_TEST_CASE(SubtypeTestCache) { | 3043 ISOLATE_UNIT_TEST_CASE(SubtypeTestCache) { |
3112 String& class_name = String::Handle(Symbols::New(thread, "EmptyClass")); | 3044 String& class_name = String::Handle(Symbols::New(thread, "EmptyClass")); |
3113 Script& script = Script::Handle(); | 3045 Script& script = Script::Handle(); |
3114 const Class& empty_class = | 3046 const Class& empty_class = |
3115 Class::Handle(CreateDummyClass(class_name, script)); | 3047 Class::Handle(CreateDummyClass(class_name, script)); |
3116 SubtypeTestCache& cache = SubtypeTestCache::Handle(SubtypeTestCache::New()); | 3048 SubtypeTestCache& cache = SubtypeTestCache::Handle(SubtypeTestCache::New()); |
3117 EXPECT(!cache.IsNull()); | 3049 EXPECT(!cache.IsNull()); |
3118 EXPECT_EQ(0, cache.NumberOfChecks()); | 3050 EXPECT_EQ(0, cache.NumberOfChecks()); |
3119 const Object& class_id_or_fun = Object::Handle(Smi::New(empty_class.id())); | 3051 const Object& class_id_or_fun = Object::Handle(Smi::New(empty_class.id())); |
3120 const TypeArguments& targ_0 = TypeArguments::Handle(TypeArguments::New(2)); | 3052 const TypeArguments& targ_0 = TypeArguments::Handle(TypeArguments::New(2)); |
3121 const TypeArguments& targ_1 = TypeArguments::Handle(TypeArguments::New(3)); | 3053 const TypeArguments& targ_1 = TypeArguments::Handle(TypeArguments::New(3)); |
3122 const TypeArguments& targ_2 = TypeArguments::Handle(TypeArguments::New(4)); | 3054 const TypeArguments& targ_2 = TypeArguments::Handle(TypeArguments::New(4)); |
3123 cache.AddCheck(class_id_or_fun, targ_0, targ_1, targ_2, Bool::True()); | 3055 cache.AddCheck(class_id_or_fun, targ_0, targ_1, targ_2, Bool::True()); |
3124 EXPECT_EQ(1, cache.NumberOfChecks()); | 3056 EXPECT_EQ(1, cache.NumberOfChecks()); |
3125 Object& test_class_id_or_fun = Object::Handle(); | 3057 Object& test_class_id_or_fun = Object::Handle(); |
3126 TypeArguments& test_targ_0 = TypeArguments::Handle(); | 3058 TypeArguments& test_targ_0 = TypeArguments::Handle(); |
3127 TypeArguments& test_targ_1 = TypeArguments::Handle(); | 3059 TypeArguments& test_targ_1 = TypeArguments::Handle(); |
3128 TypeArguments& test_targ_2 = TypeArguments::Handle(); | 3060 TypeArguments& test_targ_2 = TypeArguments::Handle(); |
3129 Bool& test_result = Bool::Handle(); | 3061 Bool& test_result = Bool::Handle(); |
3130 cache.GetCheck(0, &test_class_id_or_fun, &test_targ_0, &test_targ_1, | 3062 cache.GetCheck(0, &test_class_id_or_fun, &test_targ_0, &test_targ_1, |
3131 &test_targ_2, &test_result); | 3063 &test_targ_2, &test_result); |
3132 EXPECT_EQ(class_id_or_fun.raw(), test_class_id_or_fun.raw()); | 3064 EXPECT_EQ(class_id_or_fun.raw(), test_class_id_or_fun.raw()); |
3133 EXPECT_EQ(targ_0.raw(), test_targ_0.raw()); | 3065 EXPECT_EQ(targ_0.raw(), test_targ_0.raw()); |
3134 EXPECT_EQ(targ_1.raw(), test_targ_1.raw()); | 3066 EXPECT_EQ(targ_1.raw(), test_targ_1.raw()); |
3135 EXPECT_EQ(targ_2.raw(), test_targ_2.raw()); | 3067 EXPECT_EQ(targ_2.raw(), test_targ_2.raw()); |
3136 EXPECT_EQ(Bool::True().raw(), test_result.raw()); | 3068 EXPECT_EQ(Bool::True().raw(), test_result.raw()); |
3137 } | 3069 } |
3138 | 3070 |
3139 | |
3140 ISOLATE_UNIT_TEST_CASE(FieldTests) { | 3071 ISOLATE_UNIT_TEST_CASE(FieldTests) { |
3141 const String& f = String::Handle(String::New("oneField")); | 3072 const String& f = String::Handle(String::New("oneField")); |
3142 const String& getter_f = String::Handle(Field::GetterName(f)); | 3073 const String& getter_f = String::Handle(Field::GetterName(f)); |
3143 const String& setter_f = String::Handle(Field::SetterName(f)); | 3074 const String& setter_f = String::Handle(Field::SetterName(f)); |
3144 EXPECT(!Field::IsGetterName(f)); | 3075 EXPECT(!Field::IsGetterName(f)); |
3145 EXPECT(!Field::IsSetterName(f)); | 3076 EXPECT(!Field::IsSetterName(f)); |
3146 EXPECT(Field::IsGetterName(getter_f)); | 3077 EXPECT(Field::IsGetterName(getter_f)); |
3147 EXPECT(!Field::IsSetterName(getter_f)); | 3078 EXPECT(!Field::IsSetterName(getter_f)); |
3148 EXPECT(!Field::IsGetterName(setter_f)); | 3079 EXPECT(!Field::IsGetterName(setter_f)); |
3149 EXPECT(Field::IsSetterName(setter_f)); | 3080 EXPECT(Field::IsSetterName(setter_f)); |
3150 EXPECT_STREQ(f.ToCString(), | 3081 EXPECT_STREQ(f.ToCString(), |
3151 String::Handle(Field::NameFromGetter(getter_f)).ToCString()); | 3082 String::Handle(Field::NameFromGetter(getter_f)).ToCString()); |
3152 EXPECT_STREQ(f.ToCString(), | 3083 EXPECT_STREQ(f.ToCString(), |
3153 String::Handle(Field::NameFromSetter(setter_f)).ToCString()); | 3084 String::Handle(Field::NameFromSetter(setter_f)).ToCString()); |
3154 } | 3085 } |
3155 | 3086 |
3156 | |
3157 // Expose helper function from object.cc for testing. | 3087 // Expose helper function from object.cc for testing. |
3158 bool EqualsIgnoringPrivate(const String& name, const String& private_name); | 3088 bool EqualsIgnoringPrivate(const String& name, const String& private_name); |
3159 | 3089 |
3160 | |
3161 ISOLATE_UNIT_TEST_CASE(EqualsIgnoringPrivate) { | 3090 ISOLATE_UNIT_TEST_CASE(EqualsIgnoringPrivate) { |
3162 String& mangled_name = String::Handle(); | 3091 String& mangled_name = String::Handle(); |
3163 String& bare_name = String::Handle(); | 3092 String& bare_name = String::Handle(); |
3164 | 3093 |
3165 // Simple matches. | 3094 // Simple matches. |
3166 mangled_name = OneByteString::New("foo"); | 3095 mangled_name = OneByteString::New("foo"); |
3167 bare_name = OneByteString::New("foo"); | 3096 bare_name = OneByteString::New("foo"); |
3168 EXPECT(String::EqualsIgnoringPrivateKey(mangled_name, bare_name)); | 3097 EXPECT(String::EqualsIgnoringPrivateKey(mangled_name, bare_name)); |
3169 | 3098 |
3170 mangled_name = OneByteString::New("foo."); | 3099 mangled_name = OneByteString::New("foo."); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3293 | 3222 |
3294 // str1 - ExternalOneByteString, str2 - OneByteString. | 3223 // str1 - ExternalOneByteString, str2 - OneByteString. |
3295 EXPECT(String::EqualsIgnoringPrivateKey(ext_mangled_name, bare_name)); | 3224 EXPECT(String::EqualsIgnoringPrivateKey(ext_mangled_name, bare_name)); |
3296 | 3225 |
3297 // str1 - ExternalOneByteString, str2 - ExternalOneByteString. | 3226 // str1 - ExternalOneByteString, str2 - ExternalOneByteString. |
3298 EXPECT(String::EqualsIgnoringPrivateKey(ext_mangled_name, ext_bare_name)); | 3227 EXPECT(String::EqualsIgnoringPrivateKey(ext_mangled_name, ext_bare_name)); |
3299 EXPECT( | 3228 EXPECT( |
3300 !String::EqualsIgnoringPrivateKey(ext_mangled_name, ext_bad_bare_name)); | 3229 !String::EqualsIgnoringPrivateKey(ext_mangled_name, ext_bad_bare_name)); |
3301 } | 3230 } |
3302 | 3231 |
3303 | |
3304 ISOLATE_UNIT_TEST_CASE(ArrayNew_Overflow_Crash) { | 3232 ISOLATE_UNIT_TEST_CASE(ArrayNew_Overflow_Crash) { |
3305 Array::Handle(Array::New(Array::kMaxElements + 1)); | 3233 Array::Handle(Array::New(Array::kMaxElements + 1)); |
3306 } | 3234 } |
3307 | 3235 |
3308 | |
3309 TEST_CASE(StackTraceFormat) { | 3236 TEST_CASE(StackTraceFormat) { |
3310 const char* kScriptChars = | 3237 const char* kScriptChars = |
3311 "void baz() {\n" | 3238 "void baz() {\n" |
3312 " throw 'MyException';\n" | 3239 " throw 'MyException';\n" |
3313 "}\n" | 3240 "}\n" |
3314 "\n" | 3241 "\n" |
3315 "class _OtherClass {\n" | 3242 "class _OtherClass {\n" |
3316 " _OtherClass._named() {\n" | 3243 " _OtherClass._named() {\n" |
3317 " baz();\n" | 3244 " baz();\n" |
3318 " }\n" | 3245 " }\n" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3358 "#3 _bar (test-lib:16:3)\n" | 3285 "#3 _bar (test-lib:16:3)\n" |
3359 "#4 MyClass.field (test-lib:25:5)\n" | 3286 "#4 MyClass.field (test-lib:25:5)\n" |
3360 "#5 MyClass.foo.fooHelper (test-lib:30:7)\n" | 3287 "#5 MyClass.foo.fooHelper (test-lib:30:7)\n" |
3361 "#6 MyClass.foo (test-lib:32:14)\n" | 3288 "#6 MyClass.foo (test-lib:32:14)\n" |
3362 "#7 new MyClass.<anonymous closure> (test-lib:21:12)\n" | 3289 "#7 new MyClass.<anonymous closure> (test-lib:21:12)\n" |
3363 "#8 new MyClass (test-lib:21:18)\n" | 3290 "#8 new MyClass (test-lib:21:18)\n" |
3364 "#9 main.<anonymous closure> (test-lib:37:14)\n" | 3291 "#9 main.<anonymous closure> (test-lib:37:14)\n" |
3365 "#10 main (test-lib:37:24)"); | 3292 "#10 main (test-lib:37:24)"); |
3366 } | 3293 } |
3367 | 3294 |
3368 | |
3369 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveCrossGen) { | 3295 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveCrossGen) { |
3370 Isolate* isolate = Isolate::Current(); | 3296 Isolate* isolate = Isolate::Current(); |
3371 WeakProperty& weak = WeakProperty::Handle(); | 3297 WeakProperty& weak = WeakProperty::Handle(); |
3372 { | 3298 { |
3373 // Weak property and value in new. Key in old. | 3299 // Weak property and value in new. Key in old. |
3374 HANDLESCOPE(thread); | 3300 HANDLESCOPE(thread); |
3375 String& key = String::Handle(); | 3301 String& key = String::Handle(); |
3376 key ^= OneByteString::New("key", Heap::kOld); | 3302 key ^= OneByteString::New("key", Heap::kOld); |
3377 String& value = String::Handle(); | 3303 String& value = String::Handle(); |
3378 value ^= OneByteString::New("value", Heap::kNew); | 3304 value ^= OneByteString::New("value", Heap::kNew); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3474 value ^= OneByteString::null(); | 3400 value ^= OneByteString::null(); |
3475 } | 3401 } |
3476 isolate->heap()->CollectGarbage(Heap::kNew); | 3402 isolate->heap()->CollectGarbage(Heap::kNew); |
3477 isolate->heap()->CollectGarbage(Heap::kOld); | 3403 isolate->heap()->CollectGarbage(Heap::kOld); |
3478 // Weak property key and value should survive due to cross-generation | 3404 // Weak property key and value should survive due to cross-generation |
3479 // pointers. | 3405 // pointers. |
3480 EXPECT(weak.key() != Object::null()); | 3406 EXPECT(weak.key() != Object::null()); |
3481 EXPECT(weak.value() != Object::null()); | 3407 EXPECT(weak.value() != Object::null()); |
3482 } | 3408 } |
3483 | 3409 |
3484 | |
3485 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveRecurse) { | 3410 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveRecurse) { |
3486 // This used to end in an infinite recursion. Caused by scavenging the weak | 3411 // This used to end in an infinite recursion. Caused by scavenging the weak |
3487 // property before scavenging the key. | 3412 // property before scavenging the key. |
3488 Isolate* isolate = Isolate::Current(); | 3413 Isolate* isolate = Isolate::Current(); |
3489 WeakProperty& weak = WeakProperty::Handle(); | 3414 WeakProperty& weak = WeakProperty::Handle(); |
3490 Array& arr = Array::Handle(Array::New(1)); | 3415 Array& arr = Array::Handle(Array::New(1)); |
3491 { | 3416 { |
3492 HANDLESCOPE(thread); | 3417 HANDLESCOPE(thread); |
3493 String& key = String::Handle(); | 3418 String& key = String::Handle(); |
3494 key ^= OneByteString::New("key"); | 3419 key ^= OneByteString::New("key"); |
3495 arr.SetAt(0, key); | 3420 arr.SetAt(0, key); |
3496 String& value = String::Handle(); | 3421 String& value = String::Handle(); |
3497 value ^= OneByteString::New("value"); | 3422 value ^= OneByteString::New("value"); |
3498 weak ^= WeakProperty::New(); | 3423 weak ^= WeakProperty::New(); |
3499 weak.set_key(key); | 3424 weak.set_key(key); |
3500 weak.set_value(value); | 3425 weak.set_value(value); |
3501 } | 3426 } |
3502 isolate->heap()->CollectAllGarbage(); | 3427 isolate->heap()->CollectAllGarbage(); |
3503 EXPECT(weak.key() != Object::null()); | 3428 EXPECT(weak.key() != Object::null()); |
3504 EXPECT(weak.value() != Object::null()); | 3429 EXPECT(weak.value() != Object::null()); |
3505 } | 3430 } |
3506 | 3431 |
3507 | |
3508 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveOne_NewSpace) { | 3432 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveOne_NewSpace) { |
3509 Isolate* isolate = Isolate::Current(); | 3433 Isolate* isolate = Isolate::Current(); |
3510 WeakProperty& weak = WeakProperty::Handle(); | 3434 WeakProperty& weak = WeakProperty::Handle(); |
3511 String& key = String::Handle(); | 3435 String& key = String::Handle(); |
3512 key ^= OneByteString::New("key"); | 3436 key ^= OneByteString::New("key"); |
3513 { | 3437 { |
3514 HANDLESCOPE(thread); | 3438 HANDLESCOPE(thread); |
3515 String& value = String::Handle(); | 3439 String& value = String::Handle(); |
3516 value ^= OneByteString::New("value"); | 3440 value ^= OneByteString::New("value"); |
3517 weak ^= WeakProperty::New(); | 3441 weak ^= WeakProperty::New(); |
3518 weak.set_key(key); | 3442 weak.set_key(key); |
3519 weak.set_value(value); | 3443 weak.set_value(value); |
3520 } | 3444 } |
3521 isolate->heap()->CollectAllGarbage(); | 3445 isolate->heap()->CollectAllGarbage(); |
3522 EXPECT(weak.key() != Object::null()); | 3446 EXPECT(weak.key() != Object::null()); |
3523 EXPECT(weak.value() != Object::null()); | 3447 EXPECT(weak.value() != Object::null()); |
3524 } | 3448 } |
3525 | 3449 |
3526 | |
3527 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveTwo_NewSpace) { | 3450 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveTwo_NewSpace) { |
3528 Isolate* isolate = Isolate::Current(); | 3451 Isolate* isolate = Isolate::Current(); |
3529 WeakProperty& weak1 = WeakProperty::Handle(); | 3452 WeakProperty& weak1 = WeakProperty::Handle(); |
3530 String& key1 = String::Handle(); | 3453 String& key1 = String::Handle(); |
3531 key1 ^= OneByteString::New("key1"); | 3454 key1 ^= OneByteString::New("key1"); |
3532 WeakProperty& weak2 = WeakProperty::Handle(); | 3455 WeakProperty& weak2 = WeakProperty::Handle(); |
3533 String& key2 = String::Handle(); | 3456 String& key2 = String::Handle(); |
3534 key2 ^= OneByteString::New("key2"); | 3457 key2 ^= OneByteString::New("key2"); |
3535 { | 3458 { |
3536 HANDLESCOPE(thread); | 3459 HANDLESCOPE(thread); |
3537 String& value1 = String::Handle(); | 3460 String& value1 = String::Handle(); |
3538 value1 ^= OneByteString::New("value1"); | 3461 value1 ^= OneByteString::New("value1"); |
3539 weak1 ^= WeakProperty::New(); | 3462 weak1 ^= WeakProperty::New(); |
3540 weak1.set_key(key1); | 3463 weak1.set_key(key1); |
3541 weak1.set_value(value1); | 3464 weak1.set_value(value1); |
3542 String& value2 = String::Handle(); | 3465 String& value2 = String::Handle(); |
3543 value2 ^= OneByteString::New("value2"); | 3466 value2 ^= OneByteString::New("value2"); |
3544 weak2 ^= WeakProperty::New(); | 3467 weak2 ^= WeakProperty::New(); |
3545 weak2.set_key(key2); | 3468 weak2.set_key(key2); |
3546 weak2.set_value(value2); | 3469 weak2.set_value(value2); |
3547 } | 3470 } |
3548 isolate->heap()->CollectAllGarbage(); | 3471 isolate->heap()->CollectAllGarbage(); |
3549 EXPECT(weak1.key() != Object::null()); | 3472 EXPECT(weak1.key() != Object::null()); |
3550 EXPECT(weak1.value() != Object::null()); | 3473 EXPECT(weak1.value() != Object::null()); |
3551 EXPECT(weak2.key() != Object::null()); | 3474 EXPECT(weak2.key() != Object::null()); |
3552 EXPECT(weak2.value() != Object::null()); | 3475 EXPECT(weak2.value() != Object::null()); |
3553 } | 3476 } |
3554 | 3477 |
3555 | |
3556 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveTwoShared_NewSpace) { | 3478 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveTwoShared_NewSpace) { |
3557 Isolate* isolate = Isolate::Current(); | 3479 Isolate* isolate = Isolate::Current(); |
3558 WeakProperty& weak1 = WeakProperty::Handle(); | 3480 WeakProperty& weak1 = WeakProperty::Handle(); |
3559 WeakProperty& weak2 = WeakProperty::Handle(); | 3481 WeakProperty& weak2 = WeakProperty::Handle(); |
3560 String& key = String::Handle(); | 3482 String& key = String::Handle(); |
3561 key ^= OneByteString::New("key"); | 3483 key ^= OneByteString::New("key"); |
3562 { | 3484 { |
3563 HANDLESCOPE(thread); | 3485 HANDLESCOPE(thread); |
3564 String& value1 = String::Handle(); | 3486 String& value1 = String::Handle(); |
3565 value1 ^= OneByteString::New("value1"); | 3487 value1 ^= OneByteString::New("value1"); |
3566 weak1 ^= WeakProperty::New(); | 3488 weak1 ^= WeakProperty::New(); |
3567 weak1.set_key(key); | 3489 weak1.set_key(key); |
3568 weak1.set_value(value1); | 3490 weak1.set_value(value1); |
3569 String& value2 = String::Handle(); | 3491 String& value2 = String::Handle(); |
3570 value2 ^= OneByteString::New("value2"); | 3492 value2 ^= OneByteString::New("value2"); |
3571 weak2 ^= WeakProperty::New(); | 3493 weak2 ^= WeakProperty::New(); |
3572 weak2.set_key(key); | 3494 weak2.set_key(key); |
3573 weak2.set_value(value2); | 3495 weak2.set_value(value2); |
3574 } | 3496 } |
3575 isolate->heap()->CollectAllGarbage(); | 3497 isolate->heap()->CollectAllGarbage(); |
3576 EXPECT(weak1.key() != Object::null()); | 3498 EXPECT(weak1.key() != Object::null()); |
3577 EXPECT(weak1.value() != Object::null()); | 3499 EXPECT(weak1.value() != Object::null()); |
3578 EXPECT(weak2.key() != Object::null()); | 3500 EXPECT(weak2.key() != Object::null()); |
3579 EXPECT(weak2.value() != Object::null()); | 3501 EXPECT(weak2.value() != Object::null()); |
3580 } | 3502 } |
3581 | 3503 |
3582 | |
3583 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveOne_OldSpace) { | 3504 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveOne_OldSpace) { |
3584 Isolate* isolate = Isolate::Current(); | 3505 Isolate* isolate = Isolate::Current(); |
3585 WeakProperty& weak = WeakProperty::Handle(); | 3506 WeakProperty& weak = WeakProperty::Handle(); |
3586 String& key = String::Handle(); | 3507 String& key = String::Handle(); |
3587 key ^= OneByteString::New("key", Heap::kOld); | 3508 key ^= OneByteString::New("key", Heap::kOld); |
3588 { | 3509 { |
3589 HANDLESCOPE(thread); | 3510 HANDLESCOPE(thread); |
3590 String& value = String::Handle(); | 3511 String& value = String::Handle(); |
3591 value ^= OneByteString::New("value", Heap::kOld); | 3512 value ^= OneByteString::New("value", Heap::kOld); |
3592 weak ^= WeakProperty::New(Heap::kOld); | 3513 weak ^= WeakProperty::New(Heap::kOld); |
3593 weak.set_key(key); | 3514 weak.set_key(key); |
3594 weak.set_value(value); | 3515 weak.set_value(value); |
3595 } | 3516 } |
3596 isolate->heap()->CollectAllGarbage(); | 3517 isolate->heap()->CollectAllGarbage(); |
3597 EXPECT(weak.key() != Object::null()); | 3518 EXPECT(weak.key() != Object::null()); |
3598 EXPECT(weak.value() != Object::null()); | 3519 EXPECT(weak.value() != Object::null()); |
3599 } | 3520 } |
3600 | 3521 |
3601 | |
3602 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveTwo_OldSpace) { | 3522 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveTwo_OldSpace) { |
3603 Isolate* isolate = Isolate::Current(); | 3523 Isolate* isolate = Isolate::Current(); |
3604 WeakProperty& weak1 = WeakProperty::Handle(); | 3524 WeakProperty& weak1 = WeakProperty::Handle(); |
3605 String& key1 = String::Handle(); | 3525 String& key1 = String::Handle(); |
3606 key1 ^= OneByteString::New("key1", Heap::kOld); | 3526 key1 ^= OneByteString::New("key1", Heap::kOld); |
3607 WeakProperty& weak2 = WeakProperty::Handle(); | 3527 WeakProperty& weak2 = WeakProperty::Handle(); |
3608 String& key2 = String::Handle(); | 3528 String& key2 = String::Handle(); |
3609 key2 ^= OneByteString::New("key2", Heap::kOld); | 3529 key2 ^= OneByteString::New("key2", Heap::kOld); |
3610 { | 3530 { |
3611 HANDLESCOPE(thread); | 3531 HANDLESCOPE(thread); |
3612 String& value1 = String::Handle(); | 3532 String& value1 = String::Handle(); |
3613 value1 ^= OneByteString::New("value1", Heap::kOld); | 3533 value1 ^= OneByteString::New("value1", Heap::kOld); |
3614 weak1 ^= WeakProperty::New(Heap::kOld); | 3534 weak1 ^= WeakProperty::New(Heap::kOld); |
3615 weak1.set_key(key1); | 3535 weak1.set_key(key1); |
3616 weak1.set_value(value1); | 3536 weak1.set_value(value1); |
3617 String& value2 = String::Handle(); | 3537 String& value2 = String::Handle(); |
3618 value2 ^= OneByteString::New("value2", Heap::kOld); | 3538 value2 ^= OneByteString::New("value2", Heap::kOld); |
3619 weak2 ^= WeakProperty::New(Heap::kOld); | 3539 weak2 ^= WeakProperty::New(Heap::kOld); |
3620 weak2.set_key(key2); | 3540 weak2.set_key(key2); |
3621 weak2.set_value(value2); | 3541 weak2.set_value(value2); |
3622 } | 3542 } |
3623 isolate->heap()->CollectAllGarbage(); | 3543 isolate->heap()->CollectAllGarbage(); |
3624 EXPECT(weak1.key() != Object::null()); | 3544 EXPECT(weak1.key() != Object::null()); |
3625 EXPECT(weak1.value() != Object::null()); | 3545 EXPECT(weak1.value() != Object::null()); |
3626 EXPECT(weak2.key() != Object::null()); | 3546 EXPECT(weak2.key() != Object::null()); |
3627 EXPECT(weak2.value() != Object::null()); | 3547 EXPECT(weak2.value() != Object::null()); |
3628 } | 3548 } |
3629 | 3549 |
3630 | |
3631 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveTwoShared_OldSpace) { | 3550 ISOLATE_UNIT_TEST_CASE(WeakProperty_PreserveTwoShared_OldSpace) { |
3632 Isolate* isolate = Isolate::Current(); | 3551 Isolate* isolate = Isolate::Current(); |
3633 WeakProperty& weak1 = WeakProperty::Handle(); | 3552 WeakProperty& weak1 = WeakProperty::Handle(); |
3634 WeakProperty& weak2 = WeakProperty::Handle(); | 3553 WeakProperty& weak2 = WeakProperty::Handle(); |
3635 String& key = String::Handle(); | 3554 String& key = String::Handle(); |
3636 key ^= OneByteString::New("key", Heap::kOld); | 3555 key ^= OneByteString::New("key", Heap::kOld); |
3637 { | 3556 { |
3638 HANDLESCOPE(thread); | 3557 HANDLESCOPE(thread); |
3639 String& value1 = String::Handle(); | 3558 String& value1 = String::Handle(); |
3640 value1 ^= OneByteString::New("value1", Heap::kOld); | 3559 value1 ^= OneByteString::New("value1", Heap::kOld); |
3641 weak1 ^= WeakProperty::New(Heap::kOld); | 3560 weak1 ^= WeakProperty::New(Heap::kOld); |
3642 weak1.set_key(key); | 3561 weak1.set_key(key); |
3643 weak1.set_value(value1); | 3562 weak1.set_value(value1); |
3644 String& value2 = String::Handle(); | 3563 String& value2 = String::Handle(); |
3645 value2 ^= OneByteString::New("value2", Heap::kOld); | 3564 value2 ^= OneByteString::New("value2", Heap::kOld); |
3646 weak2 ^= WeakProperty::New(Heap::kOld); | 3565 weak2 ^= WeakProperty::New(Heap::kOld); |
3647 weak2.set_key(key); | 3566 weak2.set_key(key); |
3648 weak2.set_value(value2); | 3567 weak2.set_value(value2); |
3649 } | 3568 } |
3650 isolate->heap()->CollectAllGarbage(); | 3569 isolate->heap()->CollectAllGarbage(); |
3651 EXPECT(weak1.key() != Object::null()); | 3570 EXPECT(weak1.key() != Object::null()); |
3652 EXPECT(weak1.value() != Object::null()); | 3571 EXPECT(weak1.value() != Object::null()); |
3653 EXPECT(weak2.key() != Object::null()); | 3572 EXPECT(weak2.key() != Object::null()); |
3654 EXPECT(weak2.value() != Object::null()); | 3573 EXPECT(weak2.value() != Object::null()); |
3655 } | 3574 } |
3656 | 3575 |
3657 | |
3658 ISOLATE_UNIT_TEST_CASE(WeakProperty_ClearOne_NewSpace) { | 3576 ISOLATE_UNIT_TEST_CASE(WeakProperty_ClearOne_NewSpace) { |
3659 Isolate* isolate = Isolate::Current(); | 3577 Isolate* isolate = Isolate::Current(); |
3660 WeakProperty& weak = WeakProperty::Handle(); | 3578 WeakProperty& weak = WeakProperty::Handle(); |
3661 { | 3579 { |
3662 HANDLESCOPE(thread); | 3580 HANDLESCOPE(thread); |
3663 String& key = String::Handle(); | 3581 String& key = String::Handle(); |
3664 key ^= OneByteString::New("key"); | 3582 key ^= OneByteString::New("key"); |
3665 String& value = String::Handle(); | 3583 String& value = String::Handle(); |
3666 value ^= OneByteString::New("value"); | 3584 value ^= OneByteString::New("value"); |
3667 weak ^= WeakProperty::New(); | 3585 weak ^= WeakProperty::New(); |
3668 weak.set_key(key); | 3586 weak.set_key(key); |
3669 weak.set_value(value); | 3587 weak.set_value(value); |
3670 key ^= OneByteString::null(); | 3588 key ^= OneByteString::null(); |
3671 value ^= OneByteString::null(); | 3589 value ^= OneByteString::null(); |
3672 } | 3590 } |
3673 isolate->heap()->CollectAllGarbage(); | 3591 isolate->heap()->CollectAllGarbage(); |
3674 EXPECT(weak.key() == Object::null()); | 3592 EXPECT(weak.key() == Object::null()); |
3675 EXPECT(weak.value() == Object::null()); | 3593 EXPECT(weak.value() == Object::null()); |
3676 } | 3594 } |
3677 | 3595 |
3678 | |
3679 ISOLATE_UNIT_TEST_CASE(WeakProperty_ClearTwoShared_NewSpace) { | 3596 ISOLATE_UNIT_TEST_CASE(WeakProperty_ClearTwoShared_NewSpace) { |
3680 Isolate* isolate = Isolate::Current(); | 3597 Isolate* isolate = Isolate::Current(); |
3681 WeakProperty& weak1 = WeakProperty::Handle(); | 3598 WeakProperty& weak1 = WeakProperty::Handle(); |
3682 WeakProperty& weak2 = WeakProperty::Handle(); | 3599 WeakProperty& weak2 = WeakProperty::Handle(); |
3683 { | 3600 { |
3684 HANDLESCOPE(thread); | 3601 HANDLESCOPE(thread); |
3685 String& key = String::Handle(); | 3602 String& key = String::Handle(); |
3686 key ^= OneByteString::New("key"); | 3603 key ^= OneByteString::New("key"); |
3687 String& value1 = String::Handle(); | 3604 String& value1 = String::Handle(); |
3688 value1 ^= OneByteString::New("value1"); | 3605 value1 ^= OneByteString::New("value1"); |
3689 weak1 ^= WeakProperty::New(); | 3606 weak1 ^= WeakProperty::New(); |
3690 weak1.set_key(key); | 3607 weak1.set_key(key); |
3691 weak1.set_value(value1); | 3608 weak1.set_value(value1); |
3692 String& value2 = String::Handle(); | 3609 String& value2 = String::Handle(); |
3693 value2 ^= OneByteString::New("value2"); | 3610 value2 ^= OneByteString::New("value2"); |
3694 weak2 ^= WeakProperty::New(); | 3611 weak2 ^= WeakProperty::New(); |
3695 weak2.set_key(key); | 3612 weak2.set_key(key); |
3696 weak2.set_value(value2); | 3613 weak2.set_value(value2); |
3697 } | 3614 } |
3698 isolate->heap()->CollectAllGarbage(); | 3615 isolate->heap()->CollectAllGarbage(); |
3699 EXPECT(weak1.key() == Object::null()); | 3616 EXPECT(weak1.key() == Object::null()); |
3700 EXPECT(weak1.value() == Object::null()); | 3617 EXPECT(weak1.value() == Object::null()); |
3701 EXPECT(weak2.key() == Object::null()); | 3618 EXPECT(weak2.key() == Object::null()); |
3702 EXPECT(weak2.value() == Object::null()); | 3619 EXPECT(weak2.value() == Object::null()); |
3703 } | 3620 } |
3704 | 3621 |
3705 | |
3706 ISOLATE_UNIT_TEST_CASE(WeakProperty_ClearOne_OldSpace) { | 3622 ISOLATE_UNIT_TEST_CASE(WeakProperty_ClearOne_OldSpace) { |
3707 Isolate* isolate = Isolate::Current(); | 3623 Isolate* isolate = Isolate::Current(); |
3708 WeakProperty& weak = WeakProperty::Handle(); | 3624 WeakProperty& weak = WeakProperty::Handle(); |
3709 { | 3625 { |
3710 HANDLESCOPE(thread); | 3626 HANDLESCOPE(thread); |
3711 String& key = String::Handle(); | 3627 String& key = String::Handle(); |
3712 key ^= OneByteString::New("key", Heap::kOld); | 3628 key ^= OneByteString::New("key", Heap::kOld); |
3713 String& value = String::Handle(); | 3629 String& value = String::Handle(); |
3714 value ^= OneByteString::New("value", Heap::kOld); | 3630 value ^= OneByteString::New("value", Heap::kOld); |
3715 weak ^= WeakProperty::New(Heap::kOld); | 3631 weak ^= WeakProperty::New(Heap::kOld); |
3716 weak.set_key(key); | 3632 weak.set_key(key); |
3717 weak.set_value(value); | 3633 weak.set_value(value); |
3718 key ^= OneByteString::null(); | 3634 key ^= OneByteString::null(); |
3719 value ^= OneByteString::null(); | 3635 value ^= OneByteString::null(); |
3720 } | 3636 } |
3721 isolate->heap()->CollectAllGarbage(); | 3637 isolate->heap()->CollectAllGarbage(); |
3722 EXPECT(weak.key() == Object::null()); | 3638 EXPECT(weak.key() == Object::null()); |
3723 EXPECT(weak.value() == Object::null()); | 3639 EXPECT(weak.value() == Object::null()); |
3724 } | 3640 } |
3725 | 3641 |
3726 | |
3727 ISOLATE_UNIT_TEST_CASE(WeakProperty_ClearTwoShared_OldSpace) { | 3642 ISOLATE_UNIT_TEST_CASE(WeakProperty_ClearTwoShared_OldSpace) { |
3728 Isolate* isolate = Isolate::Current(); | 3643 Isolate* isolate = Isolate::Current(); |
3729 WeakProperty& weak1 = WeakProperty::Handle(); | 3644 WeakProperty& weak1 = WeakProperty::Handle(); |
3730 WeakProperty& weak2 = WeakProperty::Handle(); | 3645 WeakProperty& weak2 = WeakProperty::Handle(); |
3731 { | 3646 { |
3732 HANDLESCOPE(thread); | 3647 HANDLESCOPE(thread); |
3733 String& key = String::Handle(); | 3648 String& key = String::Handle(); |
3734 key ^= OneByteString::New("key", Heap::kOld); | 3649 key ^= OneByteString::New("key", Heap::kOld); |
3735 String& value1 = String::Handle(); | 3650 String& value1 = String::Handle(); |
3736 value1 ^= OneByteString::New("value1"); | 3651 value1 ^= OneByteString::New("value1"); |
3737 weak1 ^= WeakProperty::New(Heap::kOld); | 3652 weak1 ^= WeakProperty::New(Heap::kOld); |
3738 weak1.set_key(key); | 3653 weak1.set_key(key); |
3739 weak1.set_value(value1); | 3654 weak1.set_value(value1); |
3740 String& value2 = String::Handle(); | 3655 String& value2 = String::Handle(); |
3741 value2 ^= OneByteString::New("value2", Heap::kOld); | 3656 value2 ^= OneByteString::New("value2", Heap::kOld); |
3742 weak2 ^= WeakProperty::New(Heap::kOld); | 3657 weak2 ^= WeakProperty::New(Heap::kOld); |
3743 weak2.set_key(key); | 3658 weak2.set_key(key); |
3744 weak2.set_value(value2); | 3659 weak2.set_value(value2); |
3745 } | 3660 } |
3746 isolate->heap()->CollectAllGarbage(); | 3661 isolate->heap()->CollectAllGarbage(); |
3747 EXPECT(weak1.key() == Object::null()); | 3662 EXPECT(weak1.key() == Object::null()); |
3748 EXPECT(weak1.value() == Object::null()); | 3663 EXPECT(weak1.value() == Object::null()); |
3749 EXPECT(weak2.key() == Object::null()); | 3664 EXPECT(weak2.key() == Object::null()); |
3750 EXPECT(weak2.value() == Object::null()); | 3665 EXPECT(weak2.value() == Object::null()); |
3751 } | 3666 } |
3752 | 3667 |
3753 | |
3754 ISOLATE_UNIT_TEST_CASE(MirrorReference) { | 3668 ISOLATE_UNIT_TEST_CASE(MirrorReference) { |
3755 const MirrorReference& reference = | 3669 const MirrorReference& reference = |
3756 MirrorReference::Handle(MirrorReference::New(Object::Handle())); | 3670 MirrorReference::Handle(MirrorReference::New(Object::Handle())); |
3757 Object& initial_referent = Object::Handle(reference.referent()); | 3671 Object& initial_referent = Object::Handle(reference.referent()); |
3758 EXPECT(initial_referent.IsNull()); | 3672 EXPECT(initial_referent.IsNull()); |
3759 | 3673 |
3760 Library& library = Library::Handle(Library::CoreLibrary()); | 3674 Library& library = Library::Handle(Library::CoreLibrary()); |
3761 EXPECT(!library.IsNull()); | 3675 EXPECT(!library.IsNull()); |
3762 EXPECT(library.IsLibrary()); | 3676 EXPECT(library.IsLibrary()); |
3763 reference.set_referent(library); | 3677 reference.set_referent(library); |
3764 const Object& returned_referent = Object::Handle(reference.referent()); | 3678 const Object& returned_referent = Object::Handle(reference.referent()); |
3765 EXPECT(returned_referent.IsLibrary()); | 3679 EXPECT(returned_referent.IsLibrary()); |
3766 EXPECT_EQ(returned_referent.raw(), library.raw()); | 3680 EXPECT_EQ(returned_referent.raw(), library.raw()); |
3767 | 3681 |
3768 const MirrorReference& other_reference = | 3682 const MirrorReference& other_reference = |
3769 MirrorReference::Handle(MirrorReference::New(Object::Handle())); | 3683 MirrorReference::Handle(MirrorReference::New(Object::Handle())); |
3770 EXPECT_NE(reference.raw(), other_reference.raw()); | 3684 EXPECT_NE(reference.raw(), other_reference.raw()); |
3771 other_reference.set_referent(library); | 3685 other_reference.set_referent(library); |
3772 EXPECT_NE(reference.raw(), other_reference.raw()); | 3686 EXPECT_NE(reference.raw(), other_reference.raw()); |
3773 EXPECT_EQ(reference.referent(), other_reference.referent()); | 3687 EXPECT_EQ(reference.referent(), other_reference.referent()); |
3774 | 3688 |
3775 Object& obj = Object::Handle(reference.raw()); | 3689 Object& obj = Object::Handle(reference.raw()); |
3776 EXPECT(obj.IsMirrorReference()); | 3690 EXPECT(obj.IsMirrorReference()); |
3777 } | 3691 } |
3778 | 3692 |
3779 | |
3780 static RawFunction* GetFunction(const Class& cls, const char* name) { | 3693 static RawFunction* GetFunction(const Class& cls, const char* name) { |
3781 const Function& result = Function::Handle( | 3694 const Function& result = Function::Handle( |
3782 cls.LookupDynamicFunction(String::Handle(String::New(name)))); | 3695 cls.LookupDynamicFunction(String::Handle(String::New(name)))); |
3783 EXPECT(!result.IsNull()); | 3696 EXPECT(!result.IsNull()); |
3784 return result.raw(); | 3697 return result.raw(); |
3785 } | 3698 } |
3786 | 3699 |
3787 | |
3788 static RawFunction* GetStaticFunction(const Class& cls, const char* name) { | 3700 static RawFunction* GetStaticFunction(const Class& cls, const char* name) { |
3789 const Function& result = Function::Handle( | 3701 const Function& result = Function::Handle( |
3790 cls.LookupStaticFunction(String::Handle(String::New(name)))); | 3702 cls.LookupStaticFunction(String::Handle(String::New(name)))); |
3791 EXPECT(!result.IsNull()); | 3703 EXPECT(!result.IsNull()); |
3792 return result.raw(); | 3704 return result.raw(); |
3793 } | 3705 } |
3794 | 3706 |
3795 | |
3796 static RawField* GetField(const Class& cls, const char* name) { | 3707 static RawField* GetField(const Class& cls, const char* name) { |
3797 const Field& field = | 3708 const Field& field = |
3798 Field::Handle(cls.LookupField(String::Handle(String::New(name)))); | 3709 Field::Handle(cls.LookupField(String::Handle(String::New(name)))); |
3799 EXPECT(!field.IsNull()); | 3710 EXPECT(!field.IsNull()); |
3800 return field.raw(); | 3711 return field.raw(); |
3801 } | 3712 } |
3802 | 3713 |
3803 | |
3804 static RawClass* GetClass(const Library& lib, const char* name) { | 3714 static RawClass* GetClass(const Library& lib, const char* name) { |
3805 const Class& cls = Class::Handle( | 3715 const Class& cls = Class::Handle( |
3806 lib.LookupClass(String::Handle(Symbols::New(Thread::Current(), name)))); | 3716 lib.LookupClass(String::Handle(Symbols::New(Thread::Current(), name)))); |
3807 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 3717 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
3808 return cls.raw(); | 3718 return cls.raw(); |
3809 } | 3719 } |
3810 | 3720 |
3811 | |
3812 ISOLATE_UNIT_TEST_CASE(FindClosureIndex) { | 3721 ISOLATE_UNIT_TEST_CASE(FindClosureIndex) { |
3813 // Allocate the class first. | 3722 // Allocate the class first. |
3814 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); | 3723 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); |
3815 const Script& script = Script::Handle(); | 3724 const Script& script = Script::Handle(); |
3816 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 3725 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
3817 const Array& functions = Array::Handle(Array::New(1)); | 3726 const Array& functions = Array::Handle(Array::New(1)); |
3818 const Isolate* iso = Isolate::Current(); | 3727 const Isolate* iso = Isolate::Current(); |
3819 | 3728 |
3820 Function& parent = Function::Handle(); | 3729 Function& parent = Function::Handle(); |
3821 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); | 3730 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); |
(...skipping 17 matching lines...) Expand all Loading... |
3839 intptr_t bad_closure_index = iso->FindClosureIndex(parent); | 3748 intptr_t bad_closure_index = iso->FindClosureIndex(parent); |
3840 EXPECT_EQ(bad_closure_index, -1); | 3749 EXPECT_EQ(bad_closure_index, -1); |
3841 | 3750 |
3842 // Retrieve closure function via index. | 3751 // Retrieve closure function via index. |
3843 Function& func_from_index = Function::Handle(); | 3752 Function& func_from_index = Function::Handle(); |
3844 func_from_index ^= iso->ClosureFunctionFromIndex(good_closure_index); | 3753 func_from_index ^= iso->ClosureFunctionFromIndex(good_closure_index); |
3845 // Same closure function. | 3754 // Same closure function. |
3846 EXPECT_EQ(func_from_index.raw(), function.raw()); | 3755 EXPECT_EQ(func_from_index.raw(), function.raw()); |
3847 } | 3756 } |
3848 | 3757 |
3849 | |
3850 ISOLATE_UNIT_TEST_CASE(FindInvocationDispatcherFunctionIndex) { | 3758 ISOLATE_UNIT_TEST_CASE(FindInvocationDispatcherFunctionIndex) { |
3851 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); | 3759 const String& class_name = String::Handle(Symbols::New(thread, "MyClass")); |
3852 const Script& script = Script::Handle(); | 3760 const Script& script = Script::Handle(); |
3853 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); | 3761 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
3854 ClassFinalizer::FinalizeTypesInClass(cls); | 3762 ClassFinalizer::FinalizeTypesInClass(cls); |
3855 | 3763 |
3856 const Array& functions = Array::Handle(Array::New(1)); | 3764 const Array& functions = Array::Handle(Array::New(1)); |
3857 Function& parent = Function::Handle(); | 3765 Function& parent = Function::Handle(); |
3858 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); | 3766 const String& parent_name = String::Handle(Symbols::New(thread, "foo_papa")); |
3859 parent = | 3767 parent = |
(...skipping 24 matching lines...) Expand all Loading... |
3884 // Same function. | 3792 // Same function. |
3885 EXPECT_EQ(invocation_dispatcher.raw(), | 3793 EXPECT_EQ(invocation_dispatcher.raw(), |
3886 invocation_dispatcher_from_index.raw()); | 3794 invocation_dispatcher_from_index.raw()); |
3887 // Test function not found case. | 3795 // Test function not found case. |
3888 const Function& bad_function = Function::Handle(Function::null()); | 3796 const Function& bad_function = Function::Handle(Function::null()); |
3889 intptr_t bad_invocation_dispatcher_index = | 3797 intptr_t bad_invocation_dispatcher_index = |
3890 cls.FindInvocationDispatcherFunctionIndex(bad_function); | 3798 cls.FindInvocationDispatcherFunctionIndex(bad_function); |
3891 EXPECT_EQ(bad_invocation_dispatcher_index, -1); | 3799 EXPECT_EQ(bad_invocation_dispatcher_index, -1); |
3892 } | 3800 } |
3893 | 3801 |
3894 | |
3895 static void PrintMetadata(const char* name, const Object& data) { | 3802 static void PrintMetadata(const char* name, const Object& data) { |
3896 if (data.IsError()) { | 3803 if (data.IsError()) { |
3897 OS::Print("Error in metadata evaluation for %s: '%s'\n", name, | 3804 OS::Print("Error in metadata evaluation for %s: '%s'\n", name, |
3898 Error::Cast(data).ToErrorCString()); | 3805 Error::Cast(data).ToErrorCString()); |
3899 } | 3806 } |
3900 EXPECT(data.IsArray()); | 3807 EXPECT(data.IsArray()); |
3901 const Array& metadata = Array::Cast(data); | 3808 const Array& metadata = Array::Cast(data); |
3902 OS::Print("Metadata for %s has %" Pd " values:\n", name, metadata.Length()); | 3809 OS::Print("Metadata for %s has %" Pd " values:\n", name, metadata.Length()); |
3903 Object& elem = Object::Handle(); | 3810 Object& elem = Object::Handle(); |
3904 for (int i = 0; i < metadata.Length(); i++) { | 3811 for (int i = 0; i < metadata.Length(); i++) { |
3905 elem = metadata.At(i); | 3812 elem = metadata.At(i); |
3906 OS::Print(" %d: %s\n", i, elem.ToCString()); | 3813 OS::Print(" %d: %s\n", i, elem.ToCString()); |
3907 } | 3814 } |
3908 } | 3815 } |
3909 | 3816 |
3910 | |
3911 TEST_CASE(Metadata) { | 3817 TEST_CASE(Metadata) { |
3912 const char* kScriptChars = | 3818 const char* kScriptChars = |
3913 "@metafoo \n" | 3819 "@metafoo \n" |
3914 "class Meta { \n" | 3820 "class Meta { \n" |
3915 " final m; \n" | 3821 " final m; \n" |
3916 " const Meta(this.m); \n" | 3822 " const Meta(this.m); \n" |
3917 "} \n" | 3823 "} \n" |
3918 " \n" | 3824 " \n" |
3919 "const metafoo = 'metafoo'; \n" | 3825 "const metafoo = 'metafoo'; \n" |
3920 "const metabar = 'meta' 'bar'; \n" | 3826 "const metabar = 'meta' 'bar'; \n" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3974 EXPECT(!func.IsNull()); | 3880 EXPECT(!func.IsNull()); |
3975 res = lib.GetMetadata(func); | 3881 res = lib.GetMetadata(func); |
3976 PrintMetadata("tlGetter", res); | 3882 PrintMetadata("tlGetter", res); |
3977 | 3883 |
3978 field = lib.LookupLocalField(String::Handle(Symbols::New(thread, "gVar"))); | 3884 field = lib.LookupLocalField(String::Handle(Symbols::New(thread, "gVar"))); |
3979 EXPECT(!field.IsNull()); | 3885 EXPECT(!field.IsNull()); |
3980 res = lib.GetMetadata(field); | 3886 res = lib.GetMetadata(field); |
3981 PrintMetadata("gVar", res); | 3887 PrintMetadata("gVar", res); |
3982 } | 3888 } |
3983 | 3889 |
3984 | |
3985 TEST_CASE(FunctionSourceFingerprint) { | 3890 TEST_CASE(FunctionSourceFingerprint) { |
3986 const char* kScriptChars = | 3891 const char* kScriptChars = |
3987 "class A {\n" | 3892 "class A {\n" |
3988 " static void test1(int a) {\n" | 3893 " static void test1(int a) {\n" |
3989 " return a > 1 ? a + 1 : a;\n" | 3894 " return a > 1 ? a + 1 : a;\n" |
3990 " }\n" | 3895 " }\n" |
3991 " static void test2(a) {\n" | 3896 " static void test2(a) {\n" |
3992 " return a > 1 ? a + 1 : a;\n" | 3897 " return a > 1 ? a + 1 : a;\n" |
3993 " }\n" | 3898 " }\n" |
3994 " static void test3(b) {\n" | 3899 " static void test3(b) {\n" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4053 EXPECT_NE(a_test3.SourceFingerprint(), a_test4.SourceFingerprint()); | 3958 EXPECT_NE(a_test3.SourceFingerprint(), a_test4.SourceFingerprint()); |
4054 EXPECT_NE(a_test4.SourceFingerprint(), a_test5.SourceFingerprint()); | 3959 EXPECT_NE(a_test4.SourceFingerprint(), a_test5.SourceFingerprint()); |
4055 EXPECT_EQ(a_test5.SourceFingerprint(), b_test5.SourceFingerprint()); | 3960 EXPECT_EQ(a_test5.SourceFingerprint(), b_test5.SourceFingerprint()); |
4056 // Although a_test6's receiver type is different than b_test6's receiver type, | 3961 // Although a_test6's receiver type is different than b_test6's receiver type, |
4057 // the fingerprints are identical. The token stream does not reflect the | 3962 // the fingerprints are identical. The token stream does not reflect the |
4058 // receiver's type. This is not a problem, since we recognize functions | 3963 // receiver's type. This is not a problem, since we recognize functions |
4059 // of a given class and of a given name. | 3964 // of a given class and of a given name. |
4060 EXPECT_EQ(a_test6.SourceFingerprint(), b_test6.SourceFingerprint()); | 3965 EXPECT_EQ(a_test6.SourceFingerprint(), b_test6.SourceFingerprint()); |
4061 } | 3966 } |
4062 | 3967 |
4063 | |
4064 TEST_CASE(FunctionWithBreakpointNotInlined) { | 3968 TEST_CASE(FunctionWithBreakpointNotInlined) { |
4065 if (!FLAG_support_debugger) { | 3969 if (!FLAG_support_debugger) { |
4066 return; | 3970 return; |
4067 } | 3971 } |
4068 const char* kScriptChars = | 3972 const char* kScriptChars = |
4069 "class A {\n" | 3973 "class A {\n" |
4070 " a() {\n" | 3974 " a() {\n" |
4071 " }\n" | 3975 " }\n" |
4072 " b() {\n" | 3976 " b() {\n" |
4073 " a();\n" // This is line 5. | 3977 " a();\n" // This is line 5. |
(...skipping 18 matching lines...) Expand all Loading... |
4092 vmlib.LookupClass(String::Handle(Symbols::New(thread, "A")))); | 3996 vmlib.LookupClass(String::Handle(Symbols::New(thread, "A")))); |
4093 const Function& func_b = Function::Handle(GetFunction(class_a, "b")); | 3997 const Function& func_b = Function::Handle(GetFunction(class_a, "b")); |
4094 EXPECT(func_b.CanBeInlined()); | 3998 EXPECT(func_b.CanBeInlined()); |
4095 | 3999 |
4096 // After setting a breakpoint in a function A.b, it is no longer inlineable. | 4000 // After setting a breakpoint in a function A.b, it is no longer inlineable. |
4097 result = Dart_SetBreakpoint(NewString(TestCase::url()), kBreakpointLine); | 4001 result = Dart_SetBreakpoint(NewString(TestCase::url()), kBreakpointLine); |
4098 EXPECT_VALID(result); | 4002 EXPECT_VALID(result); |
4099 EXPECT(!func_b.CanBeInlined()); | 4003 EXPECT(!func_b.CanBeInlined()); |
4100 } | 4004 } |
4101 | 4005 |
4102 | |
4103 ISOLATE_UNIT_TEST_CASE(SpecialClassesHaveEmptyArrays) { | 4006 ISOLATE_UNIT_TEST_CASE(SpecialClassesHaveEmptyArrays) { |
4104 ObjectStore* object_store = Isolate::Current()->object_store(); | 4007 ObjectStore* object_store = Isolate::Current()->object_store(); |
4105 Class& cls = Class::Handle(); | 4008 Class& cls = Class::Handle(); |
4106 Object& array = Object::Handle(); | 4009 Object& array = Object::Handle(); |
4107 | 4010 |
4108 cls = object_store->null_class(); | 4011 cls = object_store->null_class(); |
4109 array = cls.fields(); | 4012 array = cls.fields(); |
4110 EXPECT(!array.IsNull()); | 4013 EXPECT(!array.IsNull()); |
4111 EXPECT(array.IsArray()); | 4014 EXPECT(array.IsArray()); |
4112 array = cls.functions(); | 4015 array = cls.functions(); |
(...skipping 10 matching lines...) Expand all Loading... |
4123 | 4026 |
4124 cls = Object::dynamic_class(); | 4027 cls = Object::dynamic_class(); |
4125 array = cls.fields(); | 4028 array = cls.fields(); |
4126 EXPECT(!array.IsNull()); | 4029 EXPECT(!array.IsNull()); |
4127 EXPECT(array.IsArray()); | 4030 EXPECT(array.IsArray()); |
4128 array = cls.functions(); | 4031 array = cls.functions(); |
4129 EXPECT(!array.IsNull()); | 4032 EXPECT(!array.IsNull()); |
4130 EXPECT(array.IsArray()); | 4033 EXPECT(array.IsArray()); |
4131 } | 4034 } |
4132 | 4035 |
4133 | |
4134 #ifndef PRODUCT | 4036 #ifndef PRODUCT |
4135 | 4037 |
4136 | |
4137 class ObjectAccumulator : public ObjectVisitor { | 4038 class ObjectAccumulator : public ObjectVisitor { |
4138 public: | 4039 public: |
4139 explicit ObjectAccumulator(GrowableArray<Object*>* objects) | 4040 explicit ObjectAccumulator(GrowableArray<Object*>* objects) |
4140 : objects_(objects) {} | 4041 : objects_(objects) {} |
4141 virtual ~ObjectAccumulator() {} | 4042 virtual ~ObjectAccumulator() {} |
4142 virtual void VisitObject(RawObject* obj) { | 4043 virtual void VisitObject(RawObject* obj) { |
4143 if (obj->IsPseudoObject()) { | 4044 if (obj->IsPseudoObject()) { |
4144 return; // Cannot be wrapped in handles. | 4045 return; // Cannot be wrapped in handles. |
4145 } | 4046 } |
4146 Object& handle = Object::Handle(obj); | 4047 Object& handle = Object::Handle(obj); |
4147 // Skip some common simple objects to run in reasonable time. | 4048 // Skip some common simple objects to run in reasonable time. |
4148 if (handle.IsString() || handle.IsArray() || handle.IsLiteralToken()) { | 4049 if (handle.IsString() || handle.IsArray() || handle.IsLiteralToken()) { |
4149 return; | 4050 return; |
4150 } | 4051 } |
4151 objects_->Add(&handle); | 4052 objects_->Add(&handle); |
4152 } | 4053 } |
4153 | 4054 |
4154 private: | 4055 private: |
4155 GrowableArray<Object*>* objects_; | 4056 GrowableArray<Object*>* objects_; |
4156 }; | 4057 }; |
4157 | 4058 |
4158 | |
4159 ISOLATE_UNIT_TEST_CASE(PrintJSON) { | 4059 ISOLATE_UNIT_TEST_CASE(PrintJSON) { |
4160 Heap* heap = Isolate::Current()->heap(); | 4060 Heap* heap = Isolate::Current()->heap(); |
4161 heap->CollectAllGarbage(); | 4061 heap->CollectAllGarbage(); |
4162 GrowableArray<Object*> objects; | 4062 GrowableArray<Object*> objects; |
4163 ObjectAccumulator acc(&objects); | 4063 ObjectAccumulator acc(&objects); |
4164 heap->IterateObjects(&acc); | 4064 heap->IterateObjects(&acc); |
4165 for (intptr_t i = 0; i < objects.length(); ++i) { | 4065 for (intptr_t i = 0; i < objects.length(); ++i) { |
4166 JSONStream js; | 4066 JSONStream js; |
4167 objects[i]->PrintJSON(&js, false); | 4067 objects[i]->PrintJSON(&js, false); |
4168 EXPECT_SUBSTRING("\"type\":", js.ToCString()); | 4068 EXPECT_SUBSTRING("\"type\":", js.ToCString()); |
4169 } | 4069 } |
4170 } | 4070 } |
4171 | 4071 |
4172 | |
4173 ISOLATE_UNIT_TEST_CASE(PrintJSONPrimitives) { | 4072 ISOLATE_UNIT_TEST_CASE(PrintJSONPrimitives) { |
4174 char buffer[1024]; | 4073 char buffer[1024]; |
4175 Isolate* isolate = Isolate::Current(); | 4074 Isolate* isolate = Isolate::Current(); |
4176 | 4075 |
4177 // Class reference | 4076 // Class reference |
4178 { | 4077 { |
4179 JSONStream js; | 4078 JSONStream js; |
4180 Class& cls = Class::Handle(isolate->object_store()->bool_class()); | 4079 Class& cls = Class::Handle(isolate->object_store()->bool_class()); |
4181 cls.PrintJSON(&js, true); | 4080 cls.PrintJSON(&js, true); |
4182 ElideJSONSubstring("classes", js.ToCString(), buffer); | 4081 ElideJSONSubstring("classes", js.ToCString(), buffer); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4452 JSONStream js; | 4351 JSONStream js; |
4453 LiteralToken& tok = LiteralToken::Handle(LiteralToken::New()); | 4352 LiteralToken& tok = LiteralToken::Handle(LiteralToken::New()); |
4454 tok.PrintJSON(&js, true); | 4353 tok.PrintJSON(&js, true); |
4455 ElideJSONSubstring("objects", js.ToCString(), buffer); | 4354 ElideJSONSubstring("objects", js.ToCString(), buffer); |
4456 EXPECT_STREQ( | 4355 EXPECT_STREQ( |
4457 "{\"type\":\"@Object\",\"_vmType\":\"LiteralToken\",\"id\":\"\"}", | 4356 "{\"type\":\"@Object\",\"_vmType\":\"LiteralToken\",\"id\":\"\"}", |
4458 buffer); | 4357 buffer); |
4459 } | 4358 } |
4460 } | 4359 } |
4461 | 4360 |
4462 | |
4463 #endif // !PRODUCT | 4361 #endif // !PRODUCT |
4464 | 4362 |
4465 | |
4466 TEST_CASE(InstanceEquality) { | 4363 TEST_CASE(InstanceEquality) { |
4467 // Test that Instance::OperatorEquals can call a user-defined operator==. | 4364 // Test that Instance::OperatorEquals can call a user-defined operator==. |
4468 const char* kScript = | 4365 const char* kScript = |
4469 "class A {\n" | 4366 "class A {\n" |
4470 " bool operator==(A other) { return true; }\n" | 4367 " bool operator==(A other) { return true; }\n" |
4471 "}\n" | 4368 "}\n" |
4472 "main() {\n" | 4369 "main() {\n" |
4473 " A a = new A();\n" | 4370 " A a = new A();\n" |
4474 "}"; | 4371 "}"; |
4475 | 4372 |
4476 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | 4373 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
4477 EXPECT_VALID(h_lib); | 4374 EXPECT_VALID(h_lib); |
4478 Library& lib = Library::Handle(); | 4375 Library& lib = Library::Handle(); |
4479 lib ^= Api::UnwrapHandle(h_lib); | 4376 lib ^= Api::UnwrapHandle(h_lib); |
4480 EXPECT(!lib.IsNull()); | 4377 EXPECT(!lib.IsNull()); |
4481 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | 4378 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
4482 EXPECT_VALID(result); | 4379 EXPECT_VALID(result); |
4483 const Class& clazz = Class::Handle(GetClass(lib, "A")); | 4380 const Class& clazz = Class::Handle(GetClass(lib, "A")); |
4484 EXPECT(!clazz.IsNull()); | 4381 EXPECT(!clazz.IsNull()); |
4485 const Instance& a0 = Instance::Handle(Instance::New(clazz)); | 4382 const Instance& a0 = Instance::Handle(Instance::New(clazz)); |
4486 const Instance& a1 = Instance::Handle(Instance::New(clazz)); | 4383 const Instance& a1 = Instance::Handle(Instance::New(clazz)); |
4487 EXPECT(a0.raw() != a1.raw()); | 4384 EXPECT(a0.raw() != a1.raw()); |
4488 EXPECT(a0.OperatorEquals(a0)); | 4385 EXPECT(a0.OperatorEquals(a0)); |
4489 EXPECT(a0.OperatorEquals(a1)); | 4386 EXPECT(a0.OperatorEquals(a1)); |
4490 EXPECT(a0.IsIdenticalTo(a0)); | 4387 EXPECT(a0.IsIdenticalTo(a0)); |
4491 EXPECT(!a0.IsIdenticalTo(a1)); | 4388 EXPECT(!a0.IsIdenticalTo(a1)); |
4492 } | 4389 } |
4493 | 4390 |
4494 | |
4495 TEST_CASE(HashCode) { | 4391 TEST_CASE(HashCode) { |
4496 // Ensure C++ overrides of Instance::HashCode match the Dart implementations. | 4392 // Ensure C++ overrides of Instance::HashCode match the Dart implementations. |
4497 const char* kScript = | 4393 const char* kScript = |
4498 "foo() {\n" | 4394 "foo() {\n" |
4499 " return \"foo\".hashCode;\n" | 4395 " return \"foo\".hashCode;\n" |
4500 "}"; | 4396 "}"; |
4501 | 4397 |
4502 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | 4398 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
4503 EXPECT_VALID(h_lib); | 4399 EXPECT_VALID(h_lib); |
4504 Library& lib = Library::Handle(); | 4400 Library& lib = Library::Handle(); |
4505 lib ^= Api::UnwrapHandle(h_lib); | 4401 lib ^= Api::UnwrapHandle(h_lib); |
4506 EXPECT(!lib.IsNull()); | 4402 EXPECT(!lib.IsNull()); |
4507 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("foo"), 0, NULL); | 4403 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("foo"), 0, NULL); |
4508 EXPECT_VALID(h_result); | 4404 EXPECT_VALID(h_result); |
4509 Integer& result = Integer::Handle(); | 4405 Integer& result = Integer::Handle(); |
4510 result ^= Api::UnwrapHandle(h_result); | 4406 result ^= Api::UnwrapHandle(h_result); |
4511 String& foo = String::Handle(String::New("foo")); | 4407 String& foo = String::Handle(String::New("foo")); |
4512 Integer& expected = Integer::Handle(); | 4408 Integer& expected = Integer::Handle(); |
4513 expected ^= foo.HashCode(); | 4409 expected ^= foo.HashCode(); |
4514 EXPECT(result.IsIdenticalTo(expected)); | 4410 EXPECT(result.IsIdenticalTo(expected)); |
4515 } | 4411 } |
4516 | 4412 |
4517 | |
4518 static void CheckIdenticalHashStructure(const Instance& a, const Instance& b) { | 4413 static void CheckIdenticalHashStructure(const Instance& a, const Instance& b) { |
4519 const char* kScript = | 4414 const char* kScript = |
4520 "(a, b) {\n" | 4415 "(a, b) {\n" |
4521 " if (a._usedData != b._usedData ||\n" | 4416 " if (a._usedData != b._usedData ||\n" |
4522 " a._deletedKeys != b._deletedKeys ||\n" | 4417 " a._deletedKeys != b._deletedKeys ||\n" |
4523 " a._hashMask != b._hashMask ||\n" | 4418 " a._hashMask != b._hashMask ||\n" |
4524 " a._index.length != b._index.length ||\n" | 4419 " a._index.length != b._index.length ||\n" |
4525 " a._data.length != b._data.length) {\n" | 4420 " a._data.length != b._data.length) {\n" |
4526 " return false;\n" | 4421 " return false;\n" |
4527 " }\n" | 4422 " }\n" |
(...skipping 18 matching lines...) Expand all Loading... |
4546 name = String::New("b"); | 4441 name = String::New("b"); |
4547 param_names.SetAt(1, name); | 4442 param_names.SetAt(1, name); |
4548 Array& param_values = Array::Handle(Array::New(2)); | 4443 Array& param_values = Array::Handle(Array::New(2)); |
4549 param_values.SetAt(0, a); | 4444 param_values.SetAt(0, a); |
4550 param_values.SetAt(1, b); | 4445 param_values.SetAt(1, b); |
4551 name = String::New(kScript); | 4446 name = String::New(kScript); |
4552 Library& lib = Library::Handle(Library::CollectionLibrary()); | 4447 Library& lib = Library::Handle(Library::CollectionLibrary()); |
4553 EXPECT(lib.Evaluate(name, param_names, param_values) == Bool::True().raw()); | 4448 EXPECT(lib.Evaluate(name, param_names, param_values) == Bool::True().raw()); |
4554 } | 4449 } |
4555 | 4450 |
4556 | |
4557 TEST_CASE(LinkedHashMap) { | 4451 TEST_CASE(LinkedHashMap) { |
4558 // Check that initial index size and hash mask match in Dart vs. C++. | 4452 // Check that initial index size and hash mask match in Dart vs. C++. |
4559 // 1. Create an empty custom linked hash map in Dart. | 4453 // 1. Create an empty custom linked hash map in Dart. |
4560 const char* kScript = | 4454 const char* kScript = |
4561 "import 'dart:collection';\n" | 4455 "import 'dart:collection';\n" |
4562 "makeMap() {\n" | 4456 "makeMap() {\n" |
4563 " Function eq = (a, b) => true;\n" | 4457 " Function eq = (a, b) => true;\n" |
4564 " Function hc = (a) => 42;\n" | 4458 " Function hc = (a) => 42;\n" |
4565 " return new LinkedHashMap(equals: eq, hashCode: hc);\n" | 4459 " return new LinkedHashMap(equals: eq, hashCode: hc);\n" |
4566 "}"; | 4460 "}"; |
4567 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | 4461 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
4568 EXPECT_VALID(h_lib); | 4462 EXPECT_VALID(h_lib); |
4569 Library& lib = Library::Handle(); | 4463 Library& lib = Library::Handle(); |
4570 lib ^= Api::UnwrapHandle(h_lib); | 4464 lib ^= Api::UnwrapHandle(h_lib); |
4571 EXPECT(!lib.IsNull()); | 4465 EXPECT(!lib.IsNull()); |
4572 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("makeMap"), 0, NULL); | 4466 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("makeMap"), 0, NULL); |
4573 EXPECT_VALID(h_result); | 4467 EXPECT_VALID(h_result); |
4574 | 4468 |
4575 // 2. Create an empty internalized LinkedHashMap in C++. | 4469 // 2. Create an empty internalized LinkedHashMap in C++. |
4576 Instance& dart_map = Instance::Handle(); | 4470 Instance& dart_map = Instance::Handle(); |
4577 dart_map ^= Api::UnwrapHandle(h_result); | 4471 dart_map ^= Api::UnwrapHandle(h_result); |
4578 LinkedHashMap& cc_map = LinkedHashMap::Handle(LinkedHashMap::NewDefault()); | 4472 LinkedHashMap& cc_map = LinkedHashMap::Handle(LinkedHashMap::NewDefault()); |
4579 | 4473 |
4580 // 3. Expect them to have identical structure. | 4474 // 3. Expect them to have identical structure. |
4581 CheckIdenticalHashStructure(dart_map, cc_map); | 4475 CheckIdenticalHashStructure(dart_map, cc_map); |
4582 } | 4476 } |
4583 | 4477 |
4584 | |
4585 TEST_CASE(LinkedHashMap_iteration) { | 4478 TEST_CASE(LinkedHashMap_iteration) { |
4586 const char* kScript = | 4479 const char* kScript = |
4587 "makeMap() {\n" | 4480 "makeMap() {\n" |
4588 " var map = {'x': 3, 'y': 4, 'z': 5, 'w': 6};\n" | 4481 " var map = {'x': 3, 'y': 4, 'z': 5, 'w': 6};\n" |
4589 " map.remove('y');\n" | 4482 " map.remove('y');\n" |
4590 " map.remove('w');\n" | 4483 " map.remove('w');\n" |
4591 " return map;\n" | 4484 " return map;\n" |
4592 "}"; | 4485 "}"; |
4593 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | 4486 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
4594 EXPECT_VALID(h_lib); | 4487 EXPECT_VALID(h_lib); |
(...skipping 21 matching lines...) Expand all Loading... |
4616 | 4509 |
4617 EXPECT(iterator.MoveNext()); | 4510 EXPECT(iterator.MoveNext()); |
4618 object = iterator.CurrentKey(); | 4511 object = iterator.CurrentKey(); |
4619 EXPECT_STREQ("z", object.ToCString()); | 4512 EXPECT_STREQ("z", object.ToCString()); |
4620 object = iterator.CurrentValue(); | 4513 object = iterator.CurrentValue(); |
4621 EXPECT_STREQ("5", object.ToCString()); | 4514 EXPECT_STREQ("5", object.ToCString()); |
4622 | 4515 |
4623 EXPECT(!iterator.MoveNext()); | 4516 EXPECT(!iterator.MoveNext()); |
4624 } | 4517 } |
4625 | 4518 |
4626 | |
4627 static void CheckConcatAll(const String* data[], intptr_t n) { | 4519 static void CheckConcatAll(const String* data[], intptr_t n) { |
4628 Thread* thread = Thread::Current(); | 4520 Thread* thread = Thread::Current(); |
4629 Zone* zone = thread->zone(); | 4521 Zone* zone = thread->zone(); |
4630 GrowableHandlePtrArray<const String> pieces(zone, n); | 4522 GrowableHandlePtrArray<const String> pieces(zone, n); |
4631 const Array& array = Array::Handle(zone, Array::New(n)); | 4523 const Array& array = Array::Handle(zone, Array::New(n)); |
4632 for (int i = 0; i < n; i++) { | 4524 for (int i = 0; i < n; i++) { |
4633 pieces.Add(*data[i]); | 4525 pieces.Add(*data[i]); |
4634 array.SetAt(i, *data[i]); | 4526 array.SetAt(i, *data[i]); |
4635 } | 4527 } |
4636 const String& res1 = | 4528 const String& res1 = |
4637 String::Handle(zone, Symbols::FromConcatAll(thread, pieces)); | 4529 String::Handle(zone, Symbols::FromConcatAll(thread, pieces)); |
4638 const String& res2 = String::Handle(zone, String::ConcatAll(array)); | 4530 const String& res2 = String::Handle(zone, String::ConcatAll(array)); |
4639 EXPECT(res1.Equals(res2)); | 4531 EXPECT(res1.Equals(res2)); |
4640 } | 4532 } |
4641 | 4533 |
4642 | |
4643 ISOLATE_UNIT_TEST_CASE(Symbols_FromConcatAll) { | 4534 ISOLATE_UNIT_TEST_CASE(Symbols_FromConcatAll) { |
4644 { | 4535 { |
4645 const String* data[3] = {&Symbols::FallThroughError(), &Symbols::Dot(), | 4536 const String* data[3] = {&Symbols::FallThroughError(), &Symbols::Dot(), |
4646 &Symbols::isPaused()}; | 4537 &Symbols::isPaused()}; |
4647 CheckConcatAll(data, 3); | 4538 CheckConcatAll(data, 3); |
4648 } | 4539 } |
4649 | 4540 |
4650 { | 4541 { |
4651 const intptr_t kWideCharsLen = 7; | 4542 const intptr_t kWideCharsLen = 7; |
4652 uint16_t wide_chars[kWideCharsLen] = {'H', 'e', 'l', 'l', 'o', 256, '!'}; | 4543 uint16_t wide_chars[kWideCharsLen] = {'H', 'e', 'l', 'l', 'o', 256, '!'}; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4696 } | 4587 } |
4697 | 4588 |
4698 { | 4589 { |
4699 const String& empty = String::Handle(String::New("")); | 4590 const String& empty = String::Handle(String::New("")); |
4700 const String* data[3] = {&Symbols::FallThroughError(), &empty, | 4591 const String* data[3] = {&Symbols::FallThroughError(), &empty, |
4701 &Symbols::isPaused()}; | 4592 &Symbols::isPaused()}; |
4702 CheckConcatAll(data, 3); | 4593 CheckConcatAll(data, 3); |
4703 } | 4594 } |
4704 } | 4595 } |
4705 | 4596 |
4706 | |
4707 struct TestResult { | 4597 struct TestResult { |
4708 const char* in; | 4598 const char* in; |
4709 const char* out; | 4599 const char* out; |
4710 }; | 4600 }; |
4711 | 4601 |
4712 | |
4713 ISOLATE_UNIT_TEST_CASE(String_ScrubName) { | 4602 ISOLATE_UNIT_TEST_CASE(String_ScrubName) { |
4714 TestResult tests[] = { | 4603 TestResult tests[] = { |
4715 {"(dynamic, dynamic) => void", "(dynamic, dynamic) => void"}, | 4604 {"(dynamic, dynamic) => void", "(dynamic, dynamic) => void"}, |
4716 {"_List@915557746", "_List"}, | 4605 {"_List@915557746", "_List"}, |
4717 {"_HashMap@600006304<K, V>(dynamic) => V", | 4606 {"_HashMap@600006304<K, V>(dynamic) => V", |
4718 "_HashMap<K, V>(dynamic) => V"}, | 4607 "_HashMap<K, V>(dynamic) => V"}, |
4719 {"set:foo", "foo="}, | 4608 {"set:foo", "foo="}, |
4720 {"get:foo", "foo"}, | 4609 {"get:foo", "foo"}, |
4721 {"_ReceivePortImpl@709387912", "_ReceivePortImpl"}, | 4610 {"_ReceivePortImpl@709387912", "_ReceivePortImpl"}, |
4722 {"_ReceivePortImpl@709387912._internal@709387912", | 4611 {"_ReceivePortImpl@709387912._internal@709387912", |
4723 "_ReceivePortImpl._internal"}, | 4612 "_ReceivePortImpl._internal"}, |
4724 {"_C@6328321&_E@6328321&_F@6328321", "_C&_E&_F"}, | 4613 {"_C@6328321&_E@6328321&_F@6328321", "_C&_E&_F"}, |
4725 {"List.", "List"}, | 4614 {"List.", "List"}, |
4726 {"get:foo@6328321", "foo"}, | 4615 {"get:foo@6328321", "foo"}, |
4727 {"_MyClass@6328321.", "_MyClass"}, | 4616 {"_MyClass@6328321.", "_MyClass"}, |
4728 {"_MyClass@6328321.named", "_MyClass.named"}, | 4617 {"_MyClass@6328321.named", "_MyClass.named"}, |
4729 }; | 4618 }; |
4730 String& test = String::Handle(); | 4619 String& test = String::Handle(); |
4731 String& result = String::Handle(); | 4620 String& result = String::Handle(); |
4732 for (size_t i = 0; i < ARRAY_SIZE(tests); i++) { | 4621 for (size_t i = 0; i < ARRAY_SIZE(tests); i++) { |
4733 test = String::New(tests[i].in); | 4622 test = String::New(tests[i].in); |
4734 result = String::ScrubName(test); | 4623 result = String::ScrubName(test); |
4735 EXPECT_STREQ(tests[i].out, result.ToCString()); | 4624 EXPECT_STREQ(tests[i].out, result.ToCString()); |
4736 } | 4625 } |
4737 } | 4626 } |
4738 | 4627 |
4739 | |
4740 ISOLATE_UNIT_TEST_CASE(String_EqualsUTF32) { | 4628 ISOLATE_UNIT_TEST_CASE(String_EqualsUTF32) { |
4741 // Regression test for Issue 27433. Checks that comparisons between Strings | 4629 // Regression test for Issue 27433. Checks that comparisons between Strings |
4742 // and utf32 arrays happens after conversion to utf16 instead of utf32, as | 4630 // and utf32 arrays happens after conversion to utf16 instead of utf32, as |
4743 // required for proper canonicalization of string literals with a lossy | 4631 // required for proper canonicalization of string literals with a lossy |
4744 // utf32->utf16 conversion. | 4632 // utf32->utf16 conversion. |
4745 int32_t char_codes[] = {0, 0x0a, 0x0d, 0x7f, 0xff, | 4633 int32_t char_codes[] = {0, 0x0a, 0x0d, 0x7f, 0xff, |
4746 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff}; | 4634 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff}; |
4747 | 4635 |
4748 const String& str = | 4636 const String& str = |
4749 String::Handle(String::FromUTF32(char_codes, ARRAY_SIZE(char_codes))); | 4637 String::Handle(String::FromUTF32(char_codes, ARRAY_SIZE(char_codes))); |
4750 EXPECT(str.Equals(char_codes, ARRAY_SIZE(char_codes))); | 4638 EXPECT(str.Equals(char_codes, ARRAY_SIZE(char_codes))); |
4751 } | 4639 } |
4752 | 4640 |
4753 } // namespace dart | 4641 } // namespace dart |
OLD | NEW |