Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: runtime/vm/object_test.cc

Issue 1541073002: Implement safepointing of threads (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix-typo Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/object_id_ring_test.cc ('k') | runtime/vm/os_thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 17 matching lines...) Expand all
28 28
29 static RawClass* CreateDummyClass(const String& class_name, 29 static RawClass* CreateDummyClass(const String& class_name,
30 const Script& script) { 30 const Script& script) {
31 const Class& cls = Class::Handle( 31 const Class& cls = Class::Handle(
32 Class::New(class_name, script, Token::kNoSourcePos)); 32 Class::New(class_name, script, Token::kNoSourcePos));
33 cls.set_is_synthesized_class(); // Dummy class for testing. 33 cls.set_is_synthesized_class(); // Dummy class for testing.
34 return cls.raw(); 34 return cls.raw();
35 } 35 }
36 36
37 37
38 TEST_CASE(Class) { 38 VM_TEST_CASE(Class) {
39 // Allocate the class first. 39 // Allocate the class first.
40 const String& class_name = String::Handle(Symbols::New("MyClass")); 40 const String& class_name = String::Handle(Symbols::New("MyClass"));
41 const Script& script = Script::Handle(); 41 const Script& script = Script::Handle();
42 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); 42 const Class& cls = Class::Handle(CreateDummyClass(class_name, script));
43 43
44 // Class has no fields and no functions yet. 44 // Class has no fields and no functions yet.
45 EXPECT_EQ(Array::Handle(cls.fields()).Length(), 0); 45 EXPECT_EQ(Array::Handle(cls.fields()).Length(), 0);
46 EXPECT_EQ(Array::Handle(cls.functions()).Length(), 0); 46 EXPECT_EQ(Array::Handle(cls.functions()).Length(), 0);
47 47
48 // Setup the interfaces in the class. 48 // Setup the interfaces in the class.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 EXPECT(!function.HasOptionalParameters()); 136 EXPECT(!function.HasOptionalParameters());
137 137
138 function_name = String::New("bar"); 138 function_name = String::New("bar");
139 function = cls.LookupDynamicFunction(function_name); 139 function = cls.LookupDynamicFunction(function_name);
140 EXPECT(!function.IsNull()); 140 EXPECT(!function.IsNull());
141 EXPECT_EQ(kNumFixedParameters, function.num_fixed_parameters()); 141 EXPECT_EQ(kNumFixedParameters, function.num_fixed_parameters());
142 EXPECT_EQ(kNumOptionalParameters, function.NumOptionalParameters()); 142 EXPECT_EQ(kNumOptionalParameters, function.NumOptionalParameters());
143 } 143 }
144 144
145 145
146 TEST_CASE(TypeArguments) { 146 VM_TEST_CASE(TypeArguments) {
147 const Type& type1 = Type::Handle(Type::Double()); 147 const Type& type1 = Type::Handle(Type::Double());
148 const Type& type2 = Type::Handle(Type::StringType()); 148 const Type& type2 = Type::Handle(Type::StringType());
149 const TypeArguments& type_arguments1 = TypeArguments::Handle( 149 const TypeArguments& type_arguments1 = TypeArguments::Handle(
150 TypeArguments::New(2)); 150 TypeArguments::New(2));
151 type_arguments1.SetTypeAt(0, type1); 151 type_arguments1.SetTypeAt(0, type1);
152 type_arguments1.SetTypeAt(1, type2); 152 type_arguments1.SetTypeAt(1, type2);
153 const TypeArguments& type_arguments2 = TypeArguments::Handle( 153 const TypeArguments& type_arguments2 = TypeArguments::Handle(
154 TypeArguments::New(2)); 154 TypeArguments::New(2));
155 type_arguments2.SetTypeAt(0, type1); 155 type_arguments2.SetTypeAt(0, type1);
156 type_arguments2.SetTypeAt(1, type2); 156 type_arguments2.SetTypeAt(1, type2);
157 EXPECT_NE(type_arguments1.raw(), type_arguments2.raw()); 157 EXPECT_NE(type_arguments1.raw(), type_arguments2.raw());
158 OS::Print("1: %s\n", type_arguments1.ToCString()); 158 OS::Print("1: %s\n", type_arguments1.ToCString());
159 OS::Print("2: %s\n", type_arguments2.ToCString()); 159 OS::Print("2: %s\n", type_arguments2.ToCString());
160 EXPECT(type_arguments1.Equals(type_arguments2)); 160 EXPECT(type_arguments1.Equals(type_arguments2));
161 TypeArguments& type_arguments3 = TypeArguments::Handle(); 161 TypeArguments& type_arguments3 = TypeArguments::Handle();
162 type_arguments1.Canonicalize(); 162 type_arguments1.Canonicalize();
163 type_arguments3 ^= type_arguments2.Canonicalize(); 163 type_arguments3 ^= type_arguments2.Canonicalize();
164 EXPECT_EQ(type_arguments1.raw(), type_arguments3.raw()); 164 EXPECT_EQ(type_arguments1.raw(), type_arguments3.raw());
165 } 165 }
166 166
167 167
168 TEST_CASE(TokenStream) { 168 VM_TEST_CASE(TokenStream) {
169 String& source = String::Handle(String::New("= ( 9 , .")); 169 String& source = String::Handle(String::New("= ( 9 , ."));
170 String& private_key = String::Handle(String::New("")); 170 String& private_key = String::Handle(String::New(""));
171 Scanner scanner(source, private_key); 171 Scanner scanner(source, private_key);
172 const Scanner::GrowableTokenStream& ts = scanner.GetStream(); 172 const Scanner::GrowableTokenStream& ts = scanner.GetStream();
173 EXPECT_EQ(6, ts.length()); 173 EXPECT_EQ(6, ts.length());
174 EXPECT_EQ(Token::kLPAREN, ts[1].kind); 174 EXPECT_EQ(Token::kLPAREN, ts[1].kind);
175 const TokenStream& token_stream = TokenStream::Handle( 175 const TokenStream& token_stream = TokenStream::Handle(
176 TokenStream::New(ts, private_key, false)); 176 TokenStream::New(ts, private_key, false));
177 TokenStream::Iterator iterator(token_stream, 0); 177 TokenStream::Iterator iterator(token_stream, 0);
178 // EXPECT_EQ(6, token_stream.Length()); 178 // EXPECT_EQ(6, token_stream.Length());
179 iterator.Advance(); // Advance to '(' token. 179 iterator.Advance(); // Advance to '(' token.
180 EXPECT_EQ(Token::kLPAREN, iterator.CurrentTokenKind()); 180 EXPECT_EQ(Token::kLPAREN, iterator.CurrentTokenKind());
181 iterator.Advance(); 181 iterator.Advance();
182 iterator.Advance(); 182 iterator.Advance();
183 iterator.Advance(); // Advance to '.' token. 183 iterator.Advance(); // Advance to '.' token.
184 EXPECT_EQ(Token::kPERIOD, iterator.CurrentTokenKind()); 184 EXPECT_EQ(Token::kPERIOD, iterator.CurrentTokenKind());
185 iterator.Advance(); // Advance to end of stream. 185 iterator.Advance(); // Advance to end of stream.
186 EXPECT_EQ(Token::kEOS, iterator.CurrentTokenKind()); 186 EXPECT_EQ(Token::kEOS, iterator.CurrentTokenKind());
187 } 187 }
188 188
189 189
190 TEST_CASE(GenerateExactSource) { 190 VM_TEST_CASE(GenerateExactSource) {
191 // Verify the exact formatting of generated sources. 191 // Verify the exact formatting of generated sources.
192 const char* kScriptChars = 192 const char* kScriptChars =
193 "\n" 193 "\n"
194 "class A {\n" 194 "class A {\n"
195 " static bar() { return 42; }\n" 195 " static bar() { return 42; }\n"
196 " static fly() { return 5; }\n" 196 " static fly() { return 5; }\n"
197 " void catcher(x) {\n" 197 " void catcher(x) {\n"
198 " try {\n" 198 " try {\n"
199 " if (x) {\n" 199 " if (x) {\n"
200 " fly();\n" 200 " fly();\n"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 EXPECT(!cls.IsNull()); 243 EXPECT(!cls.IsNull());
244 const intptr_t end_token_pos = cls.ComputeEndTokenPos(); 244 const intptr_t end_token_pos = cls.ComputeEndTokenPos();
245 const Script& scr = Script::Handle(cls.script()); 245 const Script& scr = Script::Handle(cls.script());
246 intptr_t line; 246 intptr_t line;
247 intptr_t col; 247 intptr_t col;
248 scr.GetTokenLocation(end_token_pos, &line, &col); 248 scr.GetTokenLocation(end_token_pos, &line, &col);
249 EXPECT(line == 10 && col == 1); 249 EXPECT(line == 10 && col == 1);
250 } 250 }
251 251
252 252
253 TEST_CASE(InstanceClass) { 253 VM_TEST_CASE(InstanceClass) {
254 // Allocate the class first. 254 // Allocate the class first.
255 String& class_name = String::Handle(Symbols::New("EmptyClass")); 255 String& class_name = String::Handle(Symbols::New("EmptyClass"));
256 Script& script = Script::Handle(); 256 Script& script = Script::Handle();
257 const Class& empty_class = 257 const Class& empty_class =
258 Class::Handle(CreateDummyClass(class_name, script)); 258 Class::Handle(CreateDummyClass(class_name, script));
259 259
260 // EmptyClass has no fields and no functions. 260 // EmptyClass has no fields and no functions.
261 EXPECT_EQ(Array::Handle(empty_class.fields()).Length(), 0); 261 EXPECT_EQ(Array::Handle(empty_class.fields()).Length(), 0);
262 EXPECT_EQ(Array::Handle(empty_class.functions()).Length(), 0); 262 EXPECT_EQ(Array::Handle(empty_class.functions()).Length(), 0);
263 263
(...skipping 25 matching lines...) Expand all
289 intptr_t header_size = sizeof(RawObject); 289 intptr_t header_size = sizeof(RawObject);
290 EXPECT_EQ(Utils::RoundUp((header_size + (1 * kWordSize)), kObjectAlignment), 290 EXPECT_EQ(Utils::RoundUp((header_size + (1 * kWordSize)), kObjectAlignment),
291 one_field_class.instance_size()); 291 one_field_class.instance_size());
292 EXPECT_EQ(header_size, field.Offset()); 292 EXPECT_EQ(header_size, field.Offset());
293 EXPECT(!one_field_class.is_implemented()); 293 EXPECT(!one_field_class.is_implemented());
294 one_field_class.set_is_implemented(); 294 one_field_class.set_is_implemented();
295 EXPECT(one_field_class.is_implemented()); 295 EXPECT(one_field_class.is_implemented());
296 } 296 }
297 297
298 298
299 TEST_CASE(Smi) { 299 VM_TEST_CASE(Smi) {
300 const Smi& smi = Smi::Handle(Smi::New(5)); 300 const Smi& smi = Smi::Handle(Smi::New(5));
301 Object& smi_object = Object::Handle(smi.raw()); 301 Object& smi_object = Object::Handle(smi.raw());
302 EXPECT(smi.IsSmi()); 302 EXPECT(smi.IsSmi());
303 EXPECT(smi_object.IsSmi()); 303 EXPECT(smi_object.IsSmi());
304 EXPECT_EQ(5, smi.Value()); 304 EXPECT_EQ(5, smi.Value());
305 const Object& object = Object::Handle(); 305 const Object& object = Object::Handle();
306 EXPECT(!object.IsSmi()); 306 EXPECT(!object.IsSmi());
307 smi_object = Object::null(); 307 smi_object = Object::null();
308 EXPECT(!smi_object.IsSmi()); 308 EXPECT(!smi_object.IsSmi());
309 309
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 "10000000000000000000")); 351 "10000000000000000000"));
352 Bigint& big2 = Bigint::Handle(Bigint::NewFromCString( 352 Bigint& big2 = Bigint::Handle(Bigint::NewFromCString(
353 "-10000000000000000000")); 353 "-10000000000000000000"));
354 EXPECT_EQ(-1, a.CompareWith(big1)); 354 EXPECT_EQ(-1, a.CompareWith(big1));
355 EXPECT_EQ(1, a.CompareWith(big2)); 355 EXPECT_EQ(1, a.CompareWith(big2));
356 EXPECT_EQ(-1, c.CompareWith(big1)); 356 EXPECT_EQ(-1, c.CompareWith(big1));
357 EXPECT_EQ(1, c.CompareWith(big2)); 357 EXPECT_EQ(1, c.CompareWith(big2));
358 } 358 }
359 359
360 360
361 TEST_CASE(StringCompareTo) { 361 VM_TEST_CASE(StringCompareTo) {
362 const String& abcd = String::Handle(String::New("abcd")); 362 const String& abcd = String::Handle(String::New("abcd"));
363 const String& abce = String::Handle(String::New("abce")); 363 const String& abce = String::Handle(String::New("abce"));
364 EXPECT_EQ(0, abcd.CompareTo(abcd)); 364 EXPECT_EQ(0, abcd.CompareTo(abcd));
365 EXPECT_EQ(0, abce.CompareTo(abce)); 365 EXPECT_EQ(0, abce.CompareTo(abce));
366 EXPECT(abcd.CompareTo(abce) < 0); 366 EXPECT(abcd.CompareTo(abce) < 0);
367 EXPECT(abce.CompareTo(abcd) > 0); 367 EXPECT(abce.CompareTo(abcd) > 0);
368 368
369 const int kMonkeyLen = 4; 369 const int kMonkeyLen = 4;
370 const uint8_t monkey_utf8[kMonkeyLen] = { 0xf0, 0x9f, 0x90, 0xb5 }; 370 const uint8_t monkey_utf8[kMonkeyLen] = { 0xf0, 0x9f, 0x90, 0xb5 };
371 const String& monkey_face = 371 const String& monkey_face =
(...skipping 23 matching lines...) Expand all
395 EXPECT(abce.CompareTo(monkey_face) < 0); 395 EXPECT(abce.CompareTo(monkey_face) < 0);
396 EXPECT(abcd.CompareTo(domino) < 0); 396 EXPECT(abcd.CompareTo(domino) < 0);
397 EXPECT(abce.CompareTo(domino) < 0); 397 EXPECT(abce.CompareTo(domino) < 0);
398 EXPECT(domino.CompareTo(abcd) > 0); 398 EXPECT(domino.CompareTo(abcd) > 0);
399 EXPECT(domino.CompareTo(abcd) > 0); 399 EXPECT(domino.CompareTo(abcd) > 0);
400 EXPECT(monkey_face.CompareTo(abce) > 0); 400 EXPECT(monkey_face.CompareTo(abce) > 0);
401 EXPECT(monkey_face.CompareTo(abce) > 0); 401 EXPECT(monkey_face.CompareTo(abce) > 0);
402 } 402 }
403 403
404 404
405 TEST_CASE(StringEncodeIRI) { 405 VM_TEST_CASE(StringEncodeIRI) {
406 const char* kInput = 406 const char* kInput =
407 "file:///usr/local/johnmccutchan/workspace/dart-repo/dart/test.dart"; 407 "file:///usr/local/johnmccutchan/workspace/dart-repo/dart/test.dart";
408 const char* kOutput = 408 const char* kOutput =
409 "file%3A%2F%2F%2Fusr%2Flocal%2Fjohnmccutchan%2Fworkspace%2F" 409 "file%3A%2F%2F%2Fusr%2Flocal%2Fjohnmccutchan%2Fworkspace%2F"
410 "dart-repo%2Fdart%2Ftest.dart"; 410 "dart-repo%2Fdart%2Ftest.dart";
411 const String& input = String::Handle(String::New(kInput)); 411 const String& input = String::Handle(String::New(kInput));
412 const String& output = String::Handle(String::New(kOutput)); 412 const String& output = String::Handle(String::New(kOutput));
413 const String& encoded = String::Handle(String::EncodeIRI(input)); 413 const String& encoded = String::Handle(String::EncodeIRI(input));
414 EXPECT(output.Equals(encoded)); 414 EXPECT(output.Equals(encoded));
415 } 415 }
416 416
417 417
418 TEST_CASE(StringDecodeIRI) { 418 VM_TEST_CASE(StringDecodeIRI) {
419 const char* kOutput = 419 const char* kOutput =
420 "file:///usr/local/johnmccutchan/workspace/dart-repo/dart/test.dart"; 420 "file:///usr/local/johnmccutchan/workspace/dart-repo/dart/test.dart";
421 const char* kInput = 421 const char* kInput =
422 "file%3A%2F%2F%2Fusr%2Flocal%2Fjohnmccutchan%2Fworkspace%2F" 422 "file%3A%2F%2F%2Fusr%2Flocal%2Fjohnmccutchan%2Fworkspace%2F"
423 "dart-repo%2Fdart%2Ftest.dart"; 423 "dart-repo%2Fdart%2Ftest.dart";
424 const String& input = String::Handle(String::New(kInput)); 424 const String& input = String::Handle(String::New(kInput));
425 const String& output = String::Handle(String::New(kOutput)); 425 const String& output = String::Handle(String::New(kOutput));
426 const String& decoded = String::Handle(String::DecodeIRI(input)); 426 const String& decoded = String::Handle(String::DecodeIRI(input));
427 EXPECT(output.Equals(decoded)); 427 EXPECT(output.Equals(decoded));
428 } 428 }
429 429
430 430
431 TEST_CASE(StringDecodeIRIInvalid) { 431 VM_TEST_CASE(StringDecodeIRIInvalid) {
432 String& input = String::Handle(); 432 String& input = String::Handle();
433 input = String::New("file%"); 433 input = String::New("file%");
434 String& decoded = String::Handle(); 434 String& decoded = String::Handle();
435 decoded = String::DecodeIRI(input); 435 decoded = String::DecodeIRI(input);
436 EXPECT(decoded.IsNull()); 436 EXPECT(decoded.IsNull());
437 input = String::New("file%3"); 437 input = String::New("file%3");
438 decoded = String::DecodeIRI(input); 438 decoded = String::DecodeIRI(input);
439 EXPECT(decoded.IsNull()); 439 EXPECT(decoded.IsNull());
440 input = String::New("file%3g"); 440 input = String::New("file%3g");
441 decoded = String::DecodeIRI(input); 441 decoded = String::DecodeIRI(input);
442 EXPECT(decoded.IsNull()); 442 EXPECT(decoded.IsNull());
443 } 443 }
444 444
445 445
446 TEST_CASE(StringIRITwoByte) { 446 VM_TEST_CASE(StringIRITwoByte) {
447 const intptr_t kInputLen = 3; 447 const intptr_t kInputLen = 3;
448 const uint16_t kInput[kInputLen] = { 'x', '/', 256 }; 448 const uint16_t kInput[kInputLen] = { 'x', '/', 256 };
449 const String& input = String::Handle(String::FromUTF16(kInput, kInputLen)); 449 const String& input = String::Handle(String::FromUTF16(kInput, kInputLen));
450 const intptr_t kOutputLen = 10; 450 const intptr_t kOutputLen = 10;
451 const uint16_t kOutput[kOutputLen] = 451 const uint16_t kOutput[kOutputLen] =
452 { 'x', '%', '2', 'F', '%', 'C', '4', '%', '8', '0' }; 452 { 'x', '%', '2', 'F', '%', 'C', '4', '%', '8', '0' };
453 const String& output = String::Handle(String::FromUTF16(kOutput, kOutputLen)); 453 const String& output = String::Handle(String::FromUTF16(kOutput, kOutputLen));
454 const String& encoded = String::Handle(String::EncodeIRI(input)); 454 const String& encoded = String::Handle(String::EncodeIRI(input));
455 EXPECT(output.Equals(encoded)); 455 EXPECT(output.Equals(encoded));
456 const String& decoded = String::Handle(String::DecodeIRI(output)); 456 const String& decoded = String::Handle(String::DecodeIRI(output));
457 EXPECT(input.Equals(decoded)); 457 EXPECT(input.Equals(decoded));
458 } 458 }
459 459
460 460
461 TEST_CASE(Mint) { 461 VM_TEST_CASE(Mint) {
462 // On 64-bit architectures a Smi is stored in a 64 bit word. A Midint cannot 462 // On 64-bit architectures a Smi is stored in a 64 bit word. A Midint cannot
463 // be allocated if it does fit into a Smi. 463 // be allocated if it does fit into a Smi.
464 #if !defined(ARCH_IS_64_BIT) 464 #if !defined(ARCH_IS_64_BIT)
465 { Mint& med = Mint::Handle(); 465 { Mint& med = Mint::Handle();
466 EXPECT(med.IsNull()); 466 EXPECT(med.IsNull());
467 int64_t v = DART_2PART_UINT64_C(1, 0); 467 int64_t v = DART_2PART_UINT64_C(1, 0);
468 med ^= Integer::New(v); 468 med ^= Integer::New(v);
469 EXPECT_EQ(v, med.value()); 469 EXPECT_EQ(v, med.value());
470 const String& smi_str = String::Handle(String::New("1")); 470 const String& smi_str = String::Handle(String::New("1"));
471 const String& mint1_str = String::Handle(String::New("2147419168")); 471 const String& mint1_str = String::Handle(String::New("2147419168"));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 mint1 ^= Integer::NewCanonical(mint_string); 525 mint1 ^= Integer::NewCanonical(mint_string);
526 Mint& mint2 = Mint::Handle(); 526 Mint& mint2 = Mint::Handle();
527 mint2 ^= Integer::NewCanonical(mint_string); 527 mint2 ^= Integer::NewCanonical(mint_string);
528 EXPECT_EQ(mint1.value(), mint_value); 528 EXPECT_EQ(mint1.value(), mint_value);
529 EXPECT_EQ(mint2.value(), mint_value); 529 EXPECT_EQ(mint2.value(), mint_value);
530 EXPECT_EQ(mint1.raw(), mint2.raw()); 530 EXPECT_EQ(mint1.raw(), mint2.raw());
531 #endif 531 #endif
532 } 532 }
533 533
534 534
535 TEST_CASE(Double) { 535 VM_TEST_CASE(Double) {
536 { 536 {
537 const double dbl_const = 5.0; 537 const double dbl_const = 5.0;
538 const Double& dbl = Double::Handle(Double::New(dbl_const)); 538 const Double& dbl = Double::Handle(Double::New(dbl_const));
539 Object& dbl_object = Object::Handle(dbl.raw()); 539 Object& dbl_object = Object::Handle(dbl.raw());
540 EXPECT(dbl.IsDouble()); 540 EXPECT(dbl.IsDouble());
541 EXPECT(dbl_object.IsDouble()); 541 EXPECT(dbl_object.IsDouble());
542 EXPECT_EQ(dbl_const, dbl.value()); 542 EXPECT_EQ(dbl_const, dbl.value());
543 } 543 }
544 544
545 { 545 {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 EXPECT_EQ(2.0, dbl1.value()); 609 EXPECT_EQ(2.0, dbl1.value());
610 610
611 // Disallow legacy form. 611 // Disallow legacy form.
612 const String& dbl_str2 = String::Handle(String::New("2.0d")); 612 const String& dbl_str2 = String::Handle(String::New("2.0d"));
613 const Double& dbl2 = Double::Handle(Double::New(dbl_str2)); 613 const Double& dbl2 = Double::Handle(Double::New(dbl_str2));
614 EXPECT(dbl2.IsNull()); 614 EXPECT(dbl2.IsNull());
615 } 615 }
616 } 616 }
617 617
618 618
619 TEST_CASE(Bigint) { 619 VM_TEST_CASE(Bigint) {
620 Bigint& b = Bigint::Handle(); 620 Bigint& b = Bigint::Handle();
621 EXPECT(b.IsNull()); 621 EXPECT(b.IsNull());
622 const char* cstr = "18446744073709551615000"; 622 const char* cstr = "18446744073709551615000";
623 const String& test = String::Handle(String::New(cstr)); 623 const String& test = String::Handle(String::New(cstr));
624 b ^= Integer::NewCanonical(test); 624 b ^= Integer::NewCanonical(test);
625 const char* str = b.ToCString(); 625 const char* str = b.ToCString();
626 EXPECT_STREQ(cstr, str); 626 EXPECT_STREQ(cstr, str);
627 627
628 int64_t t64 = DART_2PART_UINT64_C(1, 0); 628 int64_t t64 = DART_2PART_UINT64_C(1, 0);
629 Bigint& big = Bigint::Handle(Bigint::NewFromInt64(t64)); 629 Bigint& big = Bigint::Handle(Bigint::NewFromInt64(t64));
(...skipping 18 matching lines...) Expand all
648 Smi& smi2 = Smi::Handle(Smi::New(-2)); 648 Smi& smi2 = Smi::Handle(Smi::New(-2));
649 649
650 EXPECT_EQ(-1, smi1.CompareWith(big1)); 650 EXPECT_EQ(-1, smi1.CompareWith(big1));
651 EXPECT_EQ(-1, smi2.CompareWith(big1)); 651 EXPECT_EQ(-1, smi2.CompareWith(big1));
652 652
653 EXPECT_EQ(1, smi1.CompareWith(big3)); 653 EXPECT_EQ(1, smi1.CompareWith(big3));
654 EXPECT_EQ(1, smi2.CompareWith(big3)); 654 EXPECT_EQ(1, smi2.CompareWith(big3));
655 } 655 }
656 656
657 657
658 TEST_CASE(Integer) { 658 VM_TEST_CASE(Integer) {
659 Integer& i = Integer::Handle(); 659 Integer& i = Integer::Handle();
660 i = Integer::NewCanonical(String::Handle(String::New("12"))); 660 i = Integer::NewCanonical(String::Handle(String::New("12")));
661 EXPECT(i.IsSmi()); 661 EXPECT(i.IsSmi());
662 i = Integer::NewCanonical(String::Handle(String::New("-120"))); 662 i = Integer::NewCanonical(String::Handle(String::New("-120")));
663 EXPECT(i.IsSmi()); 663 EXPECT(i.IsSmi());
664 i = Integer::NewCanonical(String::Handle(String::New("0"))); 664 i = Integer::NewCanonical(String::Handle(String::New("0")));
665 EXPECT(i.IsSmi()); 665 EXPECT(i.IsSmi());
666 i = Integer::NewCanonical( 666 i = Integer::NewCanonical(
667 String::Handle(String::New("12345678901234567890"))); 667 String::Handle(String::New("12345678901234567890")));
668 EXPECT(i.IsBigint()); 668 EXPECT(i.IsBigint());
669 i = Integer::NewCanonical( 669 i = Integer::NewCanonical(
670 String::Handle(String::New("-12345678901234567890111222"))); 670 String::Handle(String::New("-12345678901234567890111222")));
671 EXPECT(i.IsBigint()); 671 EXPECT(i.IsBigint());
672 } 672 }
673 673
674 674
675 TEST_CASE(String) { 675 VM_TEST_CASE(String) {
676 const char* kHello = "Hello World!"; 676 const char* kHello = "Hello World!";
677 int32_t hello_len = strlen(kHello); 677 int32_t hello_len = strlen(kHello);
678 const String& str = String::Handle(String::New(kHello)); 678 const String& str = String::Handle(String::New(kHello));
679 EXPECT(str.IsInstance()); 679 EXPECT(str.IsInstance());
680 EXPECT(str.IsString()); 680 EXPECT(str.IsString());
681 EXPECT(str.IsOneByteString()); 681 EXPECT(str.IsOneByteString());
682 EXPECT(!str.IsTwoByteString()); 682 EXPECT(!str.IsTwoByteString());
683 EXPECT(!str.IsNumber()); 683 EXPECT(!str.IsNumber());
684 EXPECT_EQ(hello_len, str.Length()); 684 EXPECT_EQ(hello_len, str.Length());
685 EXPECT_EQ('H', str.CharAt(0)); 685 EXPECT_EQ('H', str.CharAt(0));
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 const String& str16 = String::Handle(String::FromUTF32(char32, 3)); 812 const String& str16 = String::Handle(String::FromUTF32(char32, 3));
813 EXPECT(!str16.IsOneByteString()); 813 EXPECT(!str16.IsOneByteString());
814 EXPECT(str16.IsTwoByteString()); 814 EXPECT(str16.IsTwoByteString());
815 EXPECT_EQ(0x0000, str16.CharAt(0)); 815 EXPECT_EQ(0x0000, str16.CharAt(0));
816 EXPECT_EQ(0x7FFF, str16.CharAt(1)); 816 EXPECT_EQ(0x7FFF, str16.CharAt(1));
817 EXPECT_EQ(0xFFFF, str16.CharAt(2)); 817 EXPECT_EQ(0xFFFF, str16.CharAt(2));
818 } 818 }
819 } 819 }
820 820
821 821
822 TEST_CASE(StringFormat) { 822 VM_TEST_CASE(StringFormat) {
823 const char* hello_str = "Hello World!"; 823 const char* hello_str = "Hello World!";
824 const String& str = 824 const String& str =
825 String::Handle(String::NewFormatted("Hello %s!", "World")); 825 String::Handle(String::NewFormatted("Hello %s!", "World"));
826 EXPECT(str.IsInstance()); 826 EXPECT(str.IsInstance());
827 EXPECT(str.IsString()); 827 EXPECT(str.IsString());
828 EXPECT(str.IsOneByteString()); 828 EXPECT(str.IsOneByteString());
829 EXPECT(!str.IsTwoByteString()); 829 EXPECT(!str.IsTwoByteString());
830 EXPECT(!str.IsNumber()); 830 EXPECT(!str.IsNumber());
831 EXPECT(str.Equals(hello_str)); 831 EXPECT(str.Equals(hello_str));
832 } 832 }
833 833
834 834
835 TEST_CASE(StringConcat) { 835 VM_TEST_CASE(StringConcat) {
836 // Create strings from concatenated 1-byte empty strings. 836 // Create strings from concatenated 1-byte empty strings.
837 { 837 {
838 const String& empty1 = String::Handle(String::New("")); 838 const String& empty1 = String::Handle(String::New(""));
839 EXPECT(empty1.IsOneByteString()); 839 EXPECT(empty1.IsOneByteString());
840 EXPECT_EQ(0, empty1.Length()); 840 EXPECT_EQ(0, empty1.Length());
841 841
842 const String& empty2 = String::Handle(String::New("")); 842 const String& empty2 = String::Handle(String::New(""));
843 EXPECT(empty2.IsOneByteString()); 843 EXPECT(empty2.IsOneByteString());
844 EXPECT_EQ(0, empty2.Length()); 844 EXPECT_EQ(0, empty2.Length());
845 845
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 EXPECT_EQ(twostr.Length()*2 + onestr.Length(), two_one_two_str.Length()); 1359 EXPECT_EQ(twostr.Length()*2 + onestr.Length(), two_one_two_str.Length());
1360 uint16_t two_one_two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, 1360 uint16_t two_one_two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9,
1361 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e', 1361 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
1362 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 }; 1362 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
1363 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); 1363 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]);
1364 EXPECT(two_one_two_str.Equals(two_one_two, two_one_two_len)); 1364 EXPECT(two_one_two_str.Equals(two_one_two, two_one_two_len));
1365 } 1365 }
1366 } 1366 }
1367 1367
1368 1368
1369 TEST_CASE(StringHashConcat) { 1369 VM_TEST_CASE(StringHashConcat) {
1370 EXPECT_EQ(String::Handle(String::New("onebyte")).Hash(), 1370 EXPECT_EQ(String::Handle(String::New("onebyte")).Hash(),
1371 String::HashConcat(String::Handle(String::New("one")), 1371 String::HashConcat(String::Handle(String::New("one")),
1372 String::Handle(String::New("byte")))); 1372 String::Handle(String::New("byte"))));
1373 uint16_t clef_utf16[] = { 0xD834, 0xDD1E }; 1373 uint16_t clef_utf16[] = { 0xD834, 0xDD1E };
1374 const String& clef = String::Handle(String::FromUTF16(clef_utf16, 2)); 1374 const String& clef = String::Handle(String::FromUTF16(clef_utf16, 2));
1375 int32_t clef_utf32[] = { 0x1D11E }; 1375 int32_t clef_utf32[] = { 0x1D11E };
1376 EXPECT(clef.Equals(clef_utf32, 1)); 1376 EXPECT(clef.Equals(clef_utf32, 1));
1377 intptr_t hash32 = String::Hash(clef_utf32, 1); 1377 intptr_t hash32 = String::Hash(clef_utf32, 1);
1378 EXPECT_EQ(hash32, clef.Hash()); 1378 EXPECT_EQ(hash32, clef.Hash());
1379 EXPECT_EQ(hash32, String::HashConcat( 1379 EXPECT_EQ(hash32, String::HashConcat(
1380 String::Handle(String::FromUTF16(clef_utf16, 1)), 1380 String::Handle(String::FromUTF16(clef_utf16, 1)),
1381 String::Handle(String::FromUTF16(clef_utf16 + 1, 1)))); 1381 String::Handle(String::FromUTF16(clef_utf16 + 1, 1))));
1382 } 1382 }
1383 1383
1384 1384
1385 TEST_CASE(StringSubStringDifferentWidth) { 1385 VM_TEST_CASE(StringSubStringDifferentWidth) {
1386 // Create 1-byte substring from a 1-byte source string. 1386 // Create 1-byte substring from a 1-byte source string.
1387 const char* onechars = 1387 const char* onechars =
1388 "\xC3\xB6\xC3\xB1\xC3\xA9"; 1388 "\xC3\xB6\xC3\xB1\xC3\xA9";
1389 1389
1390 const String& onestr = String::Handle(String::New(onechars)); 1390 const String& onestr = String::Handle(String::New(onechars));
1391 EXPECT(!onestr.IsNull()); 1391 EXPECT(!onestr.IsNull());
1392 EXPECT(onestr.IsOneByteString()); 1392 EXPECT(onestr.IsOneByteString());
1393 EXPECT(!onestr.IsTwoByteString()); 1393 EXPECT(!onestr.IsTwoByteString());
1394 1394
1395 const String& onesub = String::Handle(String::SubString(onestr, 0)); 1395 const String& onesub = String::Handle(String::SubString(onestr, 0));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 EXPECT(foursub2.IsTwoByteString()); 1437 EXPECT(foursub2.IsTwoByteString());
1438 EXPECT_EQ(foursub2.Length(), 3); 1438 EXPECT_EQ(foursub2.Length(), 3);
1439 1439
1440 const String& foursub4 = String::Handle(String::SubString(fourstr, 6)); 1440 const String& foursub4 = String::Handle(String::SubString(fourstr, 6));
1441 EXPECT_EQ(foursub4.Length(), 8); 1441 EXPECT_EQ(foursub4.Length(), 8);
1442 EXPECT(!foursub4.IsNull()); 1442 EXPECT(!foursub4.IsNull());
1443 EXPECT(foursub4.IsTwoByteString()); 1443 EXPECT(foursub4.IsTwoByteString());
1444 } 1444 }
1445 1445
1446 1446
1447 TEST_CASE(StringFromUtf8Literal) { 1447 VM_TEST_CASE(StringFromUtf8Literal) {
1448 // Create a 1-byte string from a UTF-8 encoded string literal. 1448 // Create a 1-byte string from a UTF-8 encoded string literal.
1449 { 1449 {
1450 const char* src = 1450 const char* src =
1451 "\xC2\xA0\xC2\xA1\xC2\xA2\xC2\xA3" 1451 "\xC2\xA0\xC2\xA1\xC2\xA2\xC2\xA3"
1452 "\xC2\xA4\xC2\xA5\xC2\xA6\xC2\xA7" 1452 "\xC2\xA4\xC2\xA5\xC2\xA6\xC2\xA7"
1453 "\xC2\xA8\xC2\xA9\xC2\xAA\xC2\xAB" 1453 "\xC2\xA8\xC2\xA9\xC2\xAA\xC2\xAB"
1454 "\xC2\xAC\xC2\xAD\xC2\xAE\xC2\xAF" 1454 "\xC2\xAC\xC2\xAD\xC2\xAE\xC2\xAF"
1455 "\xC2\xB0\xC2\xB1\xC2\xB2\xC2\xB3" 1455 "\xC2\xB0\xC2\xB1\xC2\xB2\xC2\xB3"
1456 "\xC2\xB4\xC2\xB5\xC2\xB6\xC2\xB7" 1456 "\xC2\xB4\xC2\xB5\xC2\xB6\xC2\xB7"
1457 "\xC2\xB8\xC2\xB9\xC2\xBA\xC2\xBB" 1457 "\xC2\xB8\xC2\xB9\xC2\xBA\xC2\xBB"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 EXPECT(str.IsTwoByteString()); 1605 EXPECT(str.IsTwoByteString());
1606 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); 1606 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
1607 EXPECT_EQ(expected_size, str.Length()); 1607 EXPECT_EQ(expected_size, str.Length());
1608 for (int i = 0; i < str.Length(); ++i) { 1608 for (int i = 0; i < str.Length(); ++i) {
1609 EXPECT_EQ(expected[i], str.CharAt(i)); 1609 EXPECT_EQ(expected[i], str.CharAt(i));
1610 } 1610 }
1611 } 1611 }
1612 } 1612 }
1613 1613
1614 1614
1615 TEST_CASE(StringEqualsUtf8) { 1615 VM_TEST_CASE(StringEqualsUtf8) {
1616 const char* onesrc = "abc"; 1616 const char* onesrc = "abc";
1617 const String& onestr = String::Handle(String::New(onesrc)); 1617 const String& onestr = String::Handle(String::New(onesrc));
1618 EXPECT(onestr.IsOneByteString()); 1618 EXPECT(onestr.IsOneByteString());
1619 EXPECT(!onestr.Equals("")); 1619 EXPECT(!onestr.Equals(""));
1620 EXPECT(!onestr.Equals("a")); 1620 EXPECT(!onestr.Equals("a"));
1621 EXPECT(!onestr.Equals("ab")); 1621 EXPECT(!onestr.Equals("ab"));
1622 EXPECT(onestr.Equals("abc")); 1622 EXPECT(onestr.Equals("abc"));
1623 EXPECT(!onestr.Equals("abcd")); 1623 EXPECT(!onestr.Equals("abcd"));
1624 1624
1625 const char* twosrc = "\xD7\x90\xD7\x91\xD7\x92"; 1625 const char* twosrc = "\xD7\x90\xD7\x91\xD7\x92";
(...skipping 10 matching lines...) Expand all
1636 EXPECT(fourstr.IsTwoByteString()); 1636 EXPECT(fourstr.IsTwoByteString());
1637 EXPECT(!fourstr.Equals("")); 1637 EXPECT(!fourstr.Equals(""));
1638 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0")); 1638 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0"));
1639 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1")); 1639 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1"));
1640 EXPECT(fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1\xF0\x90\x8E\xA2")); 1640 EXPECT(fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1\xF0\x90\x8E\xA2"));
1641 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1" 1641 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1"
1642 "\xF0\x90\x8E\xA2\xF0\x90\x8E\xA3")); 1642 "\xF0\x90\x8E\xA2\xF0\x90\x8E\xA3"));
1643 } 1643 }
1644 1644
1645 1645
1646 TEST_CASE(StringEqualsUTF32) { 1646 VM_TEST_CASE(StringEqualsUTF32) {
1647 const String& empty = String::Handle(String::New("")); 1647 const String& empty = String::Handle(String::New(""));
1648 const String& t_str = String::Handle(String::New("t")); 1648 const String& t_str = String::Handle(String::New("t"));
1649 const String& th_str = String::Handle(String::New("th")); 1649 const String& th_str = String::Handle(String::New("th"));
1650 const int32_t chars[] = {'t', 'h', 'i', 's'}; 1650 const int32_t chars[] = {'t', 'h', 'i', 's'};
1651 EXPECT(!empty.Equals(chars, -1)); 1651 EXPECT(!empty.Equals(chars, -1));
1652 EXPECT(empty.Equals(chars, 0)); 1652 EXPECT(empty.Equals(chars, 0));
1653 EXPECT(!empty.Equals(chars, 1)); 1653 EXPECT(!empty.Equals(chars, 1));
1654 EXPECT(!t_str.Equals(chars, 0)); 1654 EXPECT(!t_str.Equals(chars, 0));
1655 EXPECT(t_str.Equals(chars, 1)); 1655 EXPECT(t_str.Equals(chars, 1));
1656 EXPECT(!t_str.Equals(chars, 2)); 1656 EXPECT(!t_str.Equals(chars, 2));
1657 EXPECT(!th_str.Equals(chars, 1)); 1657 EXPECT(!th_str.Equals(chars, 1));
1658 EXPECT(th_str.Equals(chars, 2)); 1658 EXPECT(th_str.Equals(chars, 2));
1659 EXPECT(!th_str.Equals(chars, 3)); 1659 EXPECT(!th_str.Equals(chars, 3));
1660 } 1660 }
1661 1661
1662 1662
1663 TEST_CASE(ExternalOneByteString) { 1663 VM_TEST_CASE(ExternalOneByteString) {
1664 uint8_t characters[] = { 0xF6, 0xF1, 0xE9 }; 1664 uint8_t characters[] = { 0xF6, 0xF1, 0xE9 };
1665 intptr_t len = ARRAY_SIZE(characters); 1665 intptr_t len = ARRAY_SIZE(characters);
1666 1666
1667 const String& str = 1667 const String& str =
1668 String::Handle( 1668 String::Handle(
1669 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); 1669 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew));
1670 EXPECT(!str.IsOneByteString()); 1670 EXPECT(!str.IsOneByteString());
1671 EXPECT(str.IsExternalOneByteString()); 1671 EXPECT(str.IsExternalOneByteString());
1672 EXPECT_EQ(str.Length(), len); 1672 EXPECT_EQ(str.Length(), len);
1673 EXPECT(str.Equals("\xC3\xB6\xC3\xB1\xC3\xA9")); 1673 EXPECT(str.Equals("\xC3\xB6\xC3\xB1\xC3\xA9"));
(...skipping 11 matching lines...) Expand all
1685 EXPECT(concat.Equals("\xC3\xB6\xC3\xB1\xC3\xA9\xC3\xB6\xC3\xB1\xC3\xA9")); 1685 EXPECT(concat.Equals("\xC3\xB6\xC3\xB1\xC3\xA9\xC3\xB6\xC3\xB1\xC3\xA9"));
1686 1686
1687 const String& substr = String::Handle(String::SubString(str, 1, 1)); 1687 const String& substr = String::Handle(String::SubString(str, 1, 1));
1688 EXPECT(!substr.IsExternalOneByteString()); 1688 EXPECT(!substr.IsExternalOneByteString());
1689 EXPECT(substr.IsOneByteString()); 1689 EXPECT(substr.IsOneByteString());
1690 EXPECT_EQ(1, substr.Length()); 1690 EXPECT_EQ(1, substr.Length());
1691 EXPECT(substr.Equals("\xC3\xB1")); 1691 EXPECT(substr.Equals("\xC3\xB1"));
1692 } 1692 }
1693 1693
1694 1694
1695 TEST_CASE(EscapeSpecialCharactersOneByteString) { 1695 VM_TEST_CASE(EscapeSpecialCharactersOneByteString) {
1696 uint8_t characters[] = 1696 uint8_t characters[] =
1697 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' }; 1697 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' };
1698 intptr_t len = ARRAY_SIZE(characters); 1698 intptr_t len = ARRAY_SIZE(characters);
1699 1699
1700 const String& str = 1700 const String& str =
1701 String::Handle( 1701 String::Handle(
1702 OneByteString::New(characters, len, Heap::kNew)); 1702 OneByteString::New(characters, len, Heap::kNew));
1703 EXPECT(str.IsOneByteString()); 1703 EXPECT(str.IsOneByteString());
1704 EXPECT_EQ(str.Length(), len); 1704 EXPECT_EQ(str.Length(), len);
1705 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); 1705 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z"));
1706 const String& escaped_str = 1706 const String& escaped_str =
1707 String::Handle(String::EscapeSpecialCharacters(str)); 1707 String::Handle(String::EscapeSpecialCharacters(str));
1708 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); 1708 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z"));
1709 1709
1710 const String& escaped_empty_str = 1710 const String& escaped_empty_str =
1711 String::Handle(String::EscapeSpecialCharacters(Symbols::Empty())); 1711 String::Handle(String::EscapeSpecialCharacters(Symbols::Empty()));
1712 EXPECT_EQ(escaped_empty_str.Length(), 0); 1712 EXPECT_EQ(escaped_empty_str.Length(), 0);
1713 } 1713 }
1714 1714
1715 1715
1716 TEST_CASE(EscapeSpecialCharactersExternalOneByteString) { 1716 VM_TEST_CASE(EscapeSpecialCharactersExternalOneByteString) {
1717 uint8_t characters[] = 1717 uint8_t characters[] =
1718 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' }; 1718 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' };
1719 intptr_t len = ARRAY_SIZE(characters); 1719 intptr_t len = ARRAY_SIZE(characters);
1720 1720
1721 const String& str = 1721 const String& str =
1722 String::Handle( 1722 String::Handle(
1723 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); 1723 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew));
1724 EXPECT(!str.IsOneByteString()); 1724 EXPECT(!str.IsOneByteString());
1725 EXPECT(str.IsExternalOneByteString()); 1725 EXPECT(str.IsExternalOneByteString());
1726 EXPECT_EQ(str.Length(), len); 1726 EXPECT_EQ(str.Length(), len);
1727 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); 1727 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z"));
1728 const String& escaped_str = 1728 const String& escaped_str =
1729 String::Handle(String::EscapeSpecialCharacters(str)); 1729 String::Handle(String::EscapeSpecialCharacters(str));
1730 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); 1730 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z"));
1731 1731
1732 const String& empty_str = 1732 const String& empty_str =
1733 String::Handle( 1733 String::Handle(
1734 ExternalOneByteString::New(characters, 0, NULL, NULL, Heap::kNew)); 1734 ExternalOneByteString::New(characters, 0, NULL, NULL, Heap::kNew));
1735 const String& escaped_empty_str = 1735 const String& escaped_empty_str =
1736 String::Handle(String::EscapeSpecialCharacters(empty_str)); 1736 String::Handle(String::EscapeSpecialCharacters(empty_str));
1737 EXPECT_EQ(empty_str.Length(), 0); 1737 EXPECT_EQ(empty_str.Length(), 0);
1738 EXPECT_EQ(escaped_empty_str.Length(), 0); 1738 EXPECT_EQ(escaped_empty_str.Length(), 0);
1739 } 1739 }
1740 1740
1741 TEST_CASE(EscapeSpecialCharactersTwoByteString) { 1741 VM_TEST_CASE(EscapeSpecialCharactersTwoByteString) {
1742 uint16_t characters[] = 1742 uint16_t characters[] =
1743 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' }; 1743 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' };
1744 intptr_t len = ARRAY_SIZE(characters); 1744 intptr_t len = ARRAY_SIZE(characters);
1745 1745
1746 const String& str = 1746 const String& str =
1747 String::Handle(TwoByteString::New(characters, len, Heap::kNew)); 1747 String::Handle(TwoByteString::New(characters, len, Heap::kNew));
1748 EXPECT(str.IsTwoByteString()); 1748 EXPECT(str.IsTwoByteString());
1749 EXPECT_EQ(str.Length(), len); 1749 EXPECT_EQ(str.Length(), len);
1750 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); 1750 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z"));
1751 const String& escaped_str = 1751 const String& escaped_str =
1752 String::Handle(String::EscapeSpecialCharacters(str)); 1752 String::Handle(String::EscapeSpecialCharacters(str));
1753 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); 1753 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z"));
1754 1754
1755 const String& empty_str = 1755 const String& empty_str =
1756 String::Handle(TwoByteString::New(static_cast<intptr_t>(0), Heap::kNew)); 1756 String::Handle(TwoByteString::New(static_cast<intptr_t>(0), Heap::kNew));
1757 const String& escaped_empty_str = 1757 const String& escaped_empty_str =
1758 String::Handle(String::EscapeSpecialCharacters(empty_str)); 1758 String::Handle(String::EscapeSpecialCharacters(empty_str));
1759 EXPECT_EQ(empty_str.Length(), 0); 1759 EXPECT_EQ(empty_str.Length(), 0);
1760 EXPECT_EQ(escaped_empty_str.Length(), 0); 1760 EXPECT_EQ(escaped_empty_str.Length(), 0);
1761 } 1761 }
1762 1762
1763 1763
1764 TEST_CASE(EscapeSpecialCharactersExternalTwoByteString) { 1764 VM_TEST_CASE(EscapeSpecialCharactersExternalTwoByteString) {
1765 uint16_t characters[] = 1765 uint16_t characters[] =
1766 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' }; 1766 { 'a', '\n', '\f', '\b', '\t', '\v', '\r', '\\', '$', 'z' };
1767 intptr_t len = ARRAY_SIZE(characters); 1767 intptr_t len = ARRAY_SIZE(characters);
1768 1768
1769 const String& str = 1769 const String& str =
1770 String::Handle( 1770 String::Handle(
1771 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew)); 1771 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew));
1772 EXPECT(str.IsExternalTwoByteString()); 1772 EXPECT(str.IsExternalTwoByteString());
1773 EXPECT_EQ(str.Length(), len); 1773 EXPECT_EQ(str.Length(), len);
1774 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z")); 1774 EXPECT(str.Equals("a\n\f\b\t\v\r\\$z"));
1775 const String& escaped_str = 1775 const String& escaped_str =
1776 String::Handle(String::EscapeSpecialCharacters(str)); 1776 String::Handle(String::EscapeSpecialCharacters(str));
1777 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z")); 1777 EXPECT(escaped_str.Equals("a\\n\\f\\b\\t\\v\\r\\\\\\$z"));
1778 1778
1779 const String& empty_str = 1779 const String& empty_str =
1780 String::Handle( 1780 String::Handle(
1781 ExternalTwoByteString::New(characters, 0, NULL, NULL, Heap::kNew)); 1781 ExternalTwoByteString::New(characters, 0, NULL, NULL, Heap::kNew));
1782 const String& escaped_empty_str = 1782 const String& escaped_empty_str =
1783 String::Handle(String::EscapeSpecialCharacters(empty_str)); 1783 String::Handle(String::EscapeSpecialCharacters(empty_str));
1784 EXPECT_EQ(empty_str.Length(), 0); 1784 EXPECT_EQ(empty_str.Length(), 0);
1785 EXPECT_EQ(escaped_empty_str.Length(), 0); 1785 EXPECT_EQ(escaped_empty_str.Length(), 0);
1786 } 1786 }
1787 1787
1788 1788
1789 TEST_CASE(ExternalTwoByteString) { 1789 VM_TEST_CASE(ExternalTwoByteString) {
1790 uint16_t characters[] = { 0x1E6B, 0x1E85, 0x1E53 }; 1790 uint16_t characters[] = { 0x1E6B, 0x1E85, 0x1E53 };
1791 intptr_t len = ARRAY_SIZE(characters); 1791 intptr_t len = ARRAY_SIZE(characters);
1792 1792
1793 const String& str = 1793 const String& str =
1794 String::Handle( 1794 String::Handle(
1795 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew)); 1795 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew));
1796 EXPECT(!str.IsTwoByteString()); 1796 EXPECT(!str.IsTwoByteString());
1797 EXPECT(str.IsExternalTwoByteString()); 1797 EXPECT(str.IsExternalTwoByteString());
1798 EXPECT_EQ(str.Length(), len); 1798 EXPECT_EQ(str.Length(), len);
1799 EXPECT(str.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93")); 1799 EXPECT(str.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"));
(...skipping 12 matching lines...) Expand all
1812 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93")); 1812 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"));
1813 1813
1814 const String& substr = String::Handle(String::SubString(str, 1, 1)); 1814 const String& substr = String::Handle(String::SubString(str, 1, 1));
1815 EXPECT(!substr.IsExternalTwoByteString()); 1815 EXPECT(!substr.IsExternalTwoByteString());
1816 EXPECT(substr.IsTwoByteString()); 1816 EXPECT(substr.IsTwoByteString());
1817 EXPECT_EQ(1, substr.Length()); 1817 EXPECT_EQ(1, substr.Length());
1818 EXPECT(substr.Equals("\xE1\xBA\x85")); 1818 EXPECT(substr.Equals("\xE1\xBA\x85"));
1819 } 1819 }
1820 1820
1821 1821
1822 TEST_CASE(Symbol) { 1822 VM_TEST_CASE(Symbol) {
1823 const String& one = String::Handle(Symbols::New("Eins")); 1823 const String& one = String::Handle(Symbols::New("Eins"));
1824 EXPECT(one.IsSymbol()); 1824 EXPECT(one.IsSymbol());
1825 const String& two = String::Handle(Symbols::New("Zwei")); 1825 const String& two = String::Handle(Symbols::New("Zwei"));
1826 const String& three = String::Handle(Symbols::New("Drei")); 1826 const String& three = String::Handle(Symbols::New("Drei"));
1827 const String& four = String::Handle(Symbols::New("Vier")); 1827 const String& four = String::Handle(Symbols::New("Vier"));
1828 const String& five = String::Handle(Symbols::New("Fuenf")); 1828 const String& five = String::Handle(Symbols::New("Fuenf"));
1829 const String& six = String::Handle(Symbols::New("Sechs")); 1829 const String& six = String::Handle(Symbols::New("Sechs"));
1830 const String& seven = String::Handle(Symbols::New("Sieben")); 1830 const String& seven = String::Handle(Symbols::New("Sieben"));
1831 const String& eight = String::Handle(Symbols::New("Acht")); 1831 const String& eight = String::Handle(Symbols::New("Acht"));
1832 const String& nine = String::Handle(Symbols::New("Neun")); 1832 const String& nine = String::Handle(Symbols::New("Neun"));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 String& elf1 = String::Handle(Symbols::FromUTF16(char16, 3)); 1874 String& elf1 = String::Handle(Symbols::FromUTF16(char16, 3));
1875 int32_t char32[] = { 'E', 'l', 'f' }; 1875 int32_t char32[] = { 'E', 'l', 'f' };
1876 String& elf2 = String::Handle(Symbols::FromUTF32(char32, 3)); 1876 String& elf2 = String::Handle(Symbols::FromUTF32(char32, 3));
1877 EXPECT(elf1.IsSymbol()); 1877 EXPECT(elf1.IsSymbol());
1878 EXPECT(elf2.IsSymbol()); 1878 EXPECT(elf2.IsSymbol());
1879 EXPECT_EQ(elf1.raw(), Symbols::New("Elf")); 1879 EXPECT_EQ(elf1.raw(), Symbols::New("Elf"));
1880 EXPECT_EQ(elf2.raw(), Symbols::New("Elf")); 1880 EXPECT_EQ(elf2.raw(), Symbols::New("Elf"));
1881 } 1881 }
1882 1882
1883 1883
1884 TEST_CASE(SymbolUnicode) { 1884 VM_TEST_CASE(SymbolUnicode) {
1885 uint16_t monkey_utf16[] = { 0xd83d, 0xdc35 }; // Unicode Monkey Face. 1885 uint16_t monkey_utf16[] = { 0xd83d, 0xdc35 }; // Unicode Monkey Face.
1886 String& monkey = String::Handle(Symbols::FromUTF16(monkey_utf16, 2)); 1886 String& monkey = String::Handle(Symbols::FromUTF16(monkey_utf16, 2));
1887 EXPECT(monkey.IsSymbol()); 1887 EXPECT(monkey.IsSymbol());
1888 const char monkey_utf8[] = {'\xf0', '\x9f', '\x90', '\xb5', 0}; 1888 const char monkey_utf8[] = {'\xf0', '\x9f', '\x90', '\xb5', 0};
1889 EXPECT_EQ(monkey.raw(), Symbols::New(monkey_utf8)); 1889 EXPECT_EQ(monkey.raw(), Symbols::New(monkey_utf8));
1890 1890
1891 int32_t kMonkeyFace = 0x1f435; 1891 int32_t kMonkeyFace = 0x1f435;
1892 String& monkey2 = String::Handle(Symbols::FromCharCode(kMonkeyFace)); 1892 String& monkey2 = String::Handle(Symbols::FromCharCode(kMonkeyFace));
1893 EXPECT_EQ(monkey.raw(), monkey2.raw()); 1893 EXPECT_EQ(monkey.raw(), monkey2.raw());
1894 1894
1895 // Unicode cat face with tears of joy. 1895 // Unicode cat face with tears of joy.
1896 int32_t kCatFaceWithTearsOfJoy = 0x1f639; 1896 int32_t kCatFaceWithTearsOfJoy = 0x1f639;
1897 String& cat = String::Handle(Symbols::FromCharCode(kCatFaceWithTearsOfJoy)); 1897 String& cat = String::Handle(Symbols::FromCharCode(kCatFaceWithTearsOfJoy));
1898 1898
1899 uint16_t cat_utf16[] = { 0xd83d, 0xde39 }; 1899 uint16_t cat_utf16[] = { 0xd83d, 0xde39 };
1900 String& cat2 = String::Handle(Symbols::FromUTF16(cat_utf16, 2)); 1900 String& cat2 = String::Handle(Symbols::FromUTF16(cat_utf16, 2));
1901 EXPECT(cat2.IsSymbol()); 1901 EXPECT(cat2.IsSymbol());
1902 EXPECT_EQ(cat2.raw(), cat.raw()); 1902 EXPECT_EQ(cat2.raw(), cat.raw());
1903 } 1903 }
1904 1904
1905 1905
1906 TEST_CASE(Bool) { 1906 VM_TEST_CASE(Bool) {
1907 EXPECT(Bool::True().value()); 1907 EXPECT(Bool::True().value());
1908 EXPECT(!Bool::False().value()); 1908 EXPECT(!Bool::False().value());
1909 } 1909 }
1910 1910
1911 1911
1912 TEST_CASE(Array) { 1912 VM_TEST_CASE(Array) {
1913 const int kArrayLen = 5; 1913 const int kArrayLen = 5;
1914 const Array& array = Array::Handle(Array::New(kArrayLen)); 1914 const Array& array = Array::Handle(Array::New(kArrayLen));
1915 EXPECT_EQ(kArrayLen, array.Length()); 1915 EXPECT_EQ(kArrayLen, array.Length());
1916 Object& element = Object::Handle(array.At(0)); 1916 Object& element = Object::Handle(array.At(0));
1917 EXPECT(element.IsNull()); 1917 EXPECT(element.IsNull());
1918 element = array.At(kArrayLen - 1); 1918 element = array.At(kArrayLen - 1);
1919 EXPECT(element.IsNull()); 1919 EXPECT(element.IsNull());
1920 array.SetAt(0, array); 1920 array.SetAt(0, array);
1921 array.SetAt(2, array); 1921 array.SetAt(2, array);
1922 element = array.At(0); 1922 element = array.At(0);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 if (Dart_IsError(result)) { 2049 if (Dart_IsError(result)) {
2050 EXPECT_ERROR(result, "Out of Memory"); 2050 EXPECT_ERROR(result, "Out of Memory");
2051 } else { 2051 } else {
2052 intptr_t actual = 0; 2052 intptr_t actual = 0;
2053 EXPECT_VALID(Dart_ListLength(result, &actual)); 2053 EXPECT_VALID(Dart_ListLength(result, &actual));
2054 EXPECT_EQ(max_elements, actual); 2054 EXPECT_EQ(max_elements, actual);
2055 } 2055 }
2056 } 2056 }
2057 2057
2058 2058
2059 TEST_CASE(StringCodePointIterator) { 2059 VM_TEST_CASE(StringCodePointIterator) {
2060 const String& str0 = String::Handle(String::New("")); 2060 const String& str0 = String::Handle(String::New(""));
2061 String::CodePointIterator it0(str0); 2061 String::CodePointIterator it0(str0);
2062 EXPECT(!it0.Next()); 2062 EXPECT(!it0.Next());
2063 2063
2064 const String& str1 = String::Handle(String::New(" \xc3\xa7 ")); 2064 const String& str1 = String::Handle(String::New(" \xc3\xa7 "));
2065 String::CodePointIterator it1(str1); 2065 String::CodePointIterator it1(str1);
2066 EXPECT(it1.Next()); 2066 EXPECT(it1.Next());
2067 EXPECT_EQ(' ', it1.Current()); 2067 EXPECT_EQ(' ', it1.Current());
2068 EXPECT(it1.Next()); 2068 EXPECT(it1.Next());
2069 EXPECT_EQ(0xE7, it1.Current()); 2069 EXPECT_EQ(0xE7, it1.Current());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 EXPECT(it3.Next()); 2104 EXPECT(it3.Next());
2105 EXPECT_EQ(0x1D461, it3.Current()); 2105 EXPECT_EQ(0x1D461, it3.Current());
2106 EXPECT(it3.Next()); 2106 EXPECT(it3.Next());
2107 EXPECT_EQ(0x1D462, it3.Current()); 2107 EXPECT_EQ(0x1D462, it3.Current());
2108 EXPECT(it3.Next()); 2108 EXPECT(it3.Next());
2109 EXPECT_EQ(0x1D463, it3.Current()); 2109 EXPECT_EQ(0x1D463, it3.Current());
2110 EXPECT(!it3.Next()); 2110 EXPECT(!it3.Next());
2111 } 2111 }
2112 2112
2113 2113
2114 TEST_CASE(StringCodePointIteratorRange) { 2114 VM_TEST_CASE(StringCodePointIteratorRange) {
2115 const String& str = String::Handle(String::New("foo bar baz")); 2115 const String& str = String::Handle(String::New("foo bar baz"));
2116 2116
2117 String::CodePointIterator it0(str, 3, 0); 2117 String::CodePointIterator it0(str, 3, 0);
2118 EXPECT(!it0.Next()); 2118 EXPECT(!it0.Next());
2119 2119
2120 String::CodePointIterator it1(str, 4, 3); 2120 String::CodePointIterator it1(str, 4, 3);
2121 EXPECT(it1.Next()); 2121 EXPECT(it1.Next());
2122 EXPECT_EQ('b', it1.Current()); 2122 EXPECT_EQ('b', it1.Current());
2123 EXPECT(it1.Next()); 2123 EXPECT(it1.Next());
2124 EXPECT_EQ('a', it1.Current()); 2124 EXPECT_EQ('a', it1.Current());
2125 EXPECT(it1.Next()); 2125 EXPECT(it1.Next());
2126 EXPECT_EQ('r', it1.Current()); 2126 EXPECT_EQ('r', it1.Current());
2127 EXPECT(!it1.Next()); 2127 EXPECT(!it1.Next());
2128 } 2128 }
2129 2129
2130 2130
2131 TEST_CASE(GrowableObjectArray) { 2131 VM_TEST_CASE(GrowableObjectArray) {
2132 const int kArrayLen = 5; 2132 const int kArrayLen = 5;
2133 Smi& value = Smi::Handle(); 2133 Smi& value = Smi::Handle();
2134 Smi& expected_value = Smi::Handle(); 2134 Smi& expected_value = Smi::Handle();
2135 GrowableObjectArray& array = GrowableObjectArray::Handle(); 2135 GrowableObjectArray& array = GrowableObjectArray::Handle();
2136 2136
2137 // Test basic growing functionality. 2137 // Test basic growing functionality.
2138 array = GrowableObjectArray::New(kArrayLen); 2138 array = GrowableObjectArray::New(kArrayLen);
2139 EXPECT_EQ(kArrayLen, array.Capacity()); 2139 EXPECT_EQ(kArrayLen, array.Capacity());
2140 EXPECT_EQ(0, array.Length()); 2140 EXPECT_EQ(0, array.Length());
2141 for (intptr_t i = 0; i < 10; i++) { 2141 for (intptr_t i = 0; i < 10; i++) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 new_array = Array::MakeArray(array); 2243 new_array = Array::MakeArray(array);
2244 EXPECT_EQ(1, new_array.Length()); 2244 EXPECT_EQ(1, new_array.Length());
2245 heap->CollectAllGarbage(); 2245 heap->CollectAllGarbage();
2246 intptr_t capacity_after = heap->CapacityInWords(Heap::kOld); 2246 intptr_t capacity_after = heap->CapacityInWords(Heap::kOld);
2247 // Page should shrink. 2247 // Page should shrink.
2248 EXPECT_LT(capacity_after, capacity_before); 2248 EXPECT_LT(capacity_after, capacity_before);
2249 EXPECT_EQ(1, new_array.Length()); 2249 EXPECT_EQ(1, new_array.Length());
2250 } 2250 }
2251 2251
2252 2252
2253 TEST_CASE(InternalTypedData) { 2253 VM_TEST_CASE(InternalTypedData) {
2254 uint8_t data[] = { 253, 254, 255, 0, 1, 2, 3, 4 }; 2254 uint8_t data[] = { 253, 254, 255, 0, 1, 2, 3, 4 };
2255 intptr_t data_length = ARRAY_SIZE(data); 2255 intptr_t data_length = ARRAY_SIZE(data);
2256 2256
2257 const TypedData& int8_array = 2257 const TypedData& int8_array =
2258 TypedData::Handle(TypedData::New(kTypedDataInt8ArrayCid, data_length)); 2258 TypedData::Handle(TypedData::New(kTypedDataInt8ArrayCid, data_length));
2259 EXPECT(!int8_array.IsNull()); 2259 EXPECT(!int8_array.IsNull());
2260 EXPECT_EQ(data_length, int8_array.Length()); 2260 EXPECT_EQ(data_length, int8_array.Length());
2261 for (intptr_t i = 0; i < data_length; ++i) { 2261 for (intptr_t i = 0; i < data_length; ++i) {
2262 int8_array.SetInt8(i, data[i]); 2262 int8_array.SetInt8(i, data[i]);
2263 } 2263 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2299 } 2299 }
2300 for (intptr_t i = 0; i < data_length; ++i) { 2300 for (intptr_t i = 0; i < data_length; ++i) {
2301 int8_array.SetInt8(i, 123 + i); 2301 int8_array.SetInt8(i, 123 + i);
2302 } 2302 }
2303 for (intptr_t i = 0; i < data_length; ++i) { 2303 for (intptr_t i = 0; i < data_length; ++i) {
2304 EXPECT(int8_array.GetInt8(i) != int8_array2.GetInt8(i)); 2304 EXPECT(int8_array.GetInt8(i) != int8_array2.GetInt8(i));
2305 } 2305 }
2306 } 2306 }
2307 2307
2308 2308
2309 TEST_CASE(ExternalTypedData) { 2309 VM_TEST_CASE(ExternalTypedData) {
2310 uint8_t data[] = { 253, 254, 255, 0, 1, 2, 3, 4 }; 2310 uint8_t data[] = { 253, 254, 255, 0, 1, 2, 3, 4 };
2311 intptr_t data_length = ARRAY_SIZE(data); 2311 intptr_t data_length = ARRAY_SIZE(data);
2312 2312
2313 const ExternalTypedData& int8_array = 2313 const ExternalTypedData& int8_array =
2314 ExternalTypedData::Handle( 2314 ExternalTypedData::Handle(
2315 ExternalTypedData::New(kExternalTypedDataInt8ArrayCid, 2315 ExternalTypedData::New(kExternalTypedDataInt8ArrayCid,
2316 data, 2316 data,
2317 data_length)); 2317 data_length));
2318 EXPECT(!int8_array.IsNull()); 2318 EXPECT(!int8_array.IsNull());
2319 EXPECT_EQ(data_length, int8_array.Length()); 2319 EXPECT_EQ(data_length, int8_array.Length());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2400 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 2400 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
2401 EXPECT_VALID(h_lib); 2401 EXPECT_VALID(h_lib);
2402 Library& lib = Library::Handle(); 2402 Library& lib = Library::Handle();
2403 lib ^= Api::UnwrapHandle(h_lib); 2403 lib ^= Api::UnwrapHandle(h_lib);
2404 EXPECT(!lib.IsNull()); 2404 EXPECT(!lib.IsNull());
2405 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); 2405 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
2406 EXPECT_VALID(result); 2406 EXPECT_VALID(result);
2407 } 2407 }
2408 2408
2409 2409
2410 TEST_CASE(EmbeddedScript) { 2410 VM_TEST_CASE(EmbeddedScript) {
2411 const char* url_chars = "builtin:test-case"; 2411 const char* url_chars = "builtin:test-case";
2412 const char* text = 2412 const char* text =
2413 /* 1 */ "<!DOCTYPE html>\n" 2413 /* 1 */ "<!DOCTYPE html>\n"
2414 /* 2 */ " ... more junk ...\n" 2414 /* 2 */ " ... more junk ...\n"
2415 /* 3 */ " <script type='application/dart'>main() {\n" 2415 /* 3 */ " <script type='application/dart'>main() {\n"
2416 /* 4 */ " return 'foo';\n" 2416 /* 4 */ " return 'foo';\n"
2417 /* 5 */ " }\n" 2417 /* 5 */ " }\n"
2418 /* 6 */ "</script>\n"; 2418 /* 6 */ "</script>\n";
2419 const char* line1 = text; 2419 const char* line1 = text;
2420 const char* line2 = strstr(line1, "\n") + 1; 2420 const char* line2 = strstr(line1, "\n") + 1;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2495 EXPECT_EQ(3, last_idx); 2495 EXPECT_EQ(3, last_idx);
2496 script.TokenRangeAtLine(6, &first_idx, &last_idx); 2496 script.TokenRangeAtLine(6, &first_idx, &last_idx);
2497 EXPECT_EQ(-1, first_idx); 2497 EXPECT_EQ(-1, first_idx);
2498 EXPECT_EQ(-1, last_idx); 2498 EXPECT_EQ(-1, last_idx);
2499 script.TokenRangeAtLine(1000, &first_idx, &last_idx); 2499 script.TokenRangeAtLine(1000, &first_idx, &last_idx);
2500 EXPECT_EQ(-1, first_idx); 2500 EXPECT_EQ(-1, first_idx);
2501 EXPECT_EQ(-1, last_idx); 2501 EXPECT_EQ(-1, last_idx);
2502 } 2502 }
2503 2503
2504 2504
2505 TEST_CASE(Context) { 2505 VM_TEST_CASE(Context) {
2506 const int kNumVariables = 5; 2506 const int kNumVariables = 5;
2507 const Context& parent_context = Context::Handle(Context::New(0)); 2507 const Context& parent_context = Context::Handle(Context::New(0));
2508 const Context& context = Context::Handle(Context::New(kNumVariables)); 2508 const Context& context = Context::Handle(Context::New(kNumVariables));
2509 context.set_parent(parent_context); 2509 context.set_parent(parent_context);
2510 EXPECT_EQ(kNumVariables, context.num_variables()); 2510 EXPECT_EQ(kNumVariables, context.num_variables());
2511 EXPECT(Context::Handle(context.parent()).raw() == parent_context.raw()); 2511 EXPECT(Context::Handle(context.parent()).raw() == parent_context.raw());
2512 EXPECT_EQ(0, Context::Handle(context.parent()).num_variables()); 2512 EXPECT_EQ(0, Context::Handle(context.parent()).num_variables());
2513 EXPECT(Context::Handle(Context::Handle(context.parent()).parent()).IsNull()); 2513 EXPECT(Context::Handle(Context::Handle(context.parent()).parent()).IsNull());
2514 Object& variable = Object::Handle(context.At(0)); 2514 Object& variable = Object::Handle(context.At(0));
2515 EXPECT(variable.IsNull()); 2515 EXPECT(variable.IsNull());
2516 variable = context.At(kNumVariables - 1); 2516 variable = context.At(kNumVariables - 1);
2517 EXPECT(variable.IsNull()); 2517 EXPECT(variable.IsNull());
2518 context.SetAt(0, Smi::Handle(Smi::New(2))); 2518 context.SetAt(0, Smi::Handle(Smi::New(2)));
2519 context.SetAt(2, Smi::Handle(Smi::New(3))); 2519 context.SetAt(2, Smi::Handle(Smi::New(3)));
2520 Smi& smi = Smi::Handle(); 2520 Smi& smi = Smi::Handle();
2521 smi ^= context.At(0); 2521 smi ^= context.At(0);
2522 EXPECT_EQ(2, smi.Value()); 2522 EXPECT_EQ(2, smi.Value());
2523 smi ^= context.At(2); 2523 smi ^= context.At(2);
2524 EXPECT_EQ(3, smi.Value()); 2524 EXPECT_EQ(3, smi.Value());
2525 } 2525 }
2526 2526
2527 2527
2528 TEST_CASE(ContextScope) { 2528 VM_TEST_CASE(ContextScope) {
2529 const intptr_t parent_scope_function_level = 0; 2529 const intptr_t parent_scope_function_level = 0;
2530 LocalScope* parent_scope = 2530 LocalScope* parent_scope =
2531 new LocalScope(NULL, parent_scope_function_level, 0); 2531 new LocalScope(NULL, parent_scope_function_level, 0);
2532 2532
2533 const intptr_t local_scope_function_level = 1; 2533 const intptr_t local_scope_function_level = 1;
2534 LocalScope* local_scope = 2534 LocalScope* local_scope =
2535 new LocalScope(parent_scope, local_scope_function_level, 0); 2535 new LocalScope(parent_scope, local_scope_function_level, 0);
2536 2536
2537 const Type& dynamic_type = Type::ZoneHandle(Type::DynamicType()); 2537 const Type& dynamic_type = Type::ZoneHandle(Type::DynamicType());
2538 const String& a = String::ZoneHandle(Symbols::New("a")); 2538 const String& a = String::ZoneHandle(Symbols::New("a"));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2605 EXPECT(outer_scope->LocalLookupVariable(b) == NULL); 2605 EXPECT(outer_scope->LocalLookupVariable(b) == NULL);
2606 2606
2607 var_c = outer_scope->LocalLookupVariable(c); 2607 var_c = outer_scope->LocalLookupVariable(c);
2608 EXPECT(var_c->is_captured()); 2608 EXPECT(var_c->is_captured());
2609 EXPECT_EQ(1, var_c->index()); 2609 EXPECT_EQ(1, var_c->index());
2610 EXPECT_EQ(parent_scope_context_level - local_scope_context_level, 2610 EXPECT_EQ(parent_scope_context_level - local_scope_context_level,
2611 var_c->owner()->context_level()); // Adjusted context level. 2611 var_c->owner()->context_level()); // Adjusted context level.
2612 } 2612 }
2613 2613
2614 2614
2615 TEST_CASE(Closure) { 2615 VM_TEST_CASE(Closure) {
2616 // Allocate the class first. 2616 // Allocate the class first.
2617 const String& class_name = String::Handle(Symbols::New("MyClass")); 2617 const String& class_name = String::Handle(Symbols::New("MyClass"));
2618 const Script& script = Script::Handle(); 2618 const Script& script = Script::Handle();
2619 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); 2619 const Class& cls = Class::Handle(CreateDummyClass(class_name, script));
2620 const Array& functions = Array::Handle(Array::New(1)); 2620 const Array& functions = Array::Handle(Array::New(1));
2621 2621
2622 const Context& context = Context::Handle(Context::New(0)); 2622 const Context& context = Context::Handle(Context::New(0));
2623 Function& parent = Function::Handle(); 2623 Function& parent = Function::Handle();
2624 const String& parent_name = String::Handle(Symbols::New("foo_papa")); 2624 const String& parent_name = String::Handle(Symbols::New("foo_papa"));
2625 parent = Function::New(parent_name, RawFunction::kRegularFunction, 2625 parent = Function::New(parent_name, RawFunction::kRegularFunction,
2626 false, false, false, false, false, cls, 0); 2626 false, false, false, false, false, cls, 0);
2627 functions.SetAt(0, parent); 2627 functions.SetAt(0, parent);
2628 cls.SetFunctions(functions); 2628 cls.SetFunctions(functions);
2629 2629
2630 Function& function = Function::Handle(); 2630 Function& function = Function::Handle();
2631 const String& function_name = String::Handle(Symbols::New("foo")); 2631 const String& function_name = String::Handle(Symbols::New("foo"));
2632 function = Function::NewClosureFunction(function_name, parent, 0); 2632 function = Function::NewClosureFunction(function_name, parent, 0);
2633 const Closure& closure = Closure::Handle(Closure::New(function, context)); 2633 const Closure& closure = Closure::Handle(Closure::New(function, context));
2634 const Class& closure_class = Class::Handle(closure.clazz()); 2634 const Class& closure_class = Class::Handle(closure.clazz());
2635 EXPECT_EQ(closure_class.id(), kClosureCid); 2635 EXPECT_EQ(closure_class.id(), kClosureCid);
2636 const Function& closure_function = Function::Handle(closure.function()); 2636 const Function& closure_function = Function::Handle(closure.function());
2637 EXPECT_EQ(closure_function.raw(), function.raw()); 2637 EXPECT_EQ(closure_function.raw(), function.raw());
2638 const Context& closure_context = Context::Handle(closure.context()); 2638 const Context& closure_context = Context::Handle(closure.context());
2639 EXPECT_EQ(closure_context.raw(), context.raw()); 2639 EXPECT_EQ(closure_context.raw(), context.raw());
2640 } 2640 }
2641 2641
2642 2642
2643 TEST_CASE(ObjectPrinting) { 2643 VM_TEST_CASE(ObjectPrinting) {
2644 // Simple Smis. 2644 // Simple Smis.
2645 EXPECT_STREQ("2", Smi::Handle(Smi::New(2)).ToCString()); 2645 EXPECT_STREQ("2", Smi::Handle(Smi::New(2)).ToCString());
2646 EXPECT_STREQ("-15", Smi::Handle(Smi::New(-15)).ToCString()); 2646 EXPECT_STREQ("-15", Smi::Handle(Smi::New(-15)).ToCString());
2647 2647
2648 // bool class and true/false values. 2648 // bool class and true/false values.
2649 ObjectStore* object_store = Isolate::Current()->object_store(); 2649 ObjectStore* object_store = Isolate::Current()->object_store();
2650 const Class& bool_class = Class::Handle(object_store->bool_class()); 2650 const Class& bool_class = Class::Handle(object_store->bool_class());
2651 EXPECT_STREQ("Library:'dart:core' Class: bool", 2651 EXPECT_STREQ("Library:'dart:core' Class: bool",
2652 bool_class.ToCString()); 2652 bool_class.ToCString());
2653 EXPECT_STREQ("true", Bool::True().ToCString()); 2653 EXPECT_STREQ("true", Bool::True().ToCString());
2654 EXPECT_STREQ("false", Bool::False().ToCString()); 2654 EXPECT_STREQ("false", Bool::False().ToCString());
2655 2655
2656 // Strings. 2656 // Strings.
2657 EXPECT_STREQ("Sugarbowl", 2657 EXPECT_STREQ("Sugarbowl",
2658 String::Handle(String::New("Sugarbowl")).ToCString()); 2658 String::Handle(String::New("Sugarbowl")).ToCString());
2659 } 2659 }
2660 2660
2661 2661
2662 TEST_CASE(CheckedHandle) { 2662 VM_TEST_CASE(CheckedHandle) {
2663 // Ensure that null handles have the correct C++ vtable setup. 2663 // Ensure that null handles have the correct C++ vtable setup.
2664 const String& str1 = String::Handle(); 2664 const String& str1 = String::Handle();
2665 EXPECT(str1.IsString()); 2665 EXPECT(str1.IsString());
2666 EXPECT(str1.IsNull()); 2666 EXPECT(str1.IsNull());
2667 const String& str2 = String::CheckedHandle(Object::null()); 2667 const String& str2 = String::CheckedHandle(Object::null());
2668 EXPECT(str2.IsString()); 2668 EXPECT(str2.IsString());
2669 EXPECT(str2.IsNull()); 2669 EXPECT(str2.IsNull());
2670 String& str3 = String::Handle(); 2670 String& str3 = String::Handle();
2671 str3 ^= Object::null(); 2671 str3 ^= Object::null();
2672 EXPECT(str3.IsString()); 2672 EXPECT(str3.IsString());
(...skipping 17 matching lines...) Expand all
2690 const Library& owner_library = 2690 const Library& owner_library =
2691 Library::Handle(CreateDummyLibrary(lib_name)); 2691 Library::Handle(CreateDummyLibrary(lib_name));
2692 owner_class.set_library(owner_library); 2692 owner_class.set_library(owner_library);
2693 const String& function_name = String::ZoneHandle(Symbols::New(name)); 2693 const String& function_name = String::ZoneHandle(Symbols::New(name));
2694 return Function::New(function_name, RawFunction::kRegularFunction, 2694 return Function::New(function_name, RawFunction::kRegularFunction,
2695 true, false, false, false, false, owner_class, 0); 2695 true, false, false, false, false, owner_class, 0);
2696 } 2696 }
2697 2697
2698 2698
2699 // Test for Code and Instruction object creation. 2699 // Test for Code and Instruction object creation.
2700 TEST_CASE(Code) { 2700 VM_TEST_CASE(Code) {
2701 extern void GenerateIncrement(Assembler* assembler); 2701 extern void GenerateIncrement(Assembler* assembler);
2702 Assembler _assembler_; 2702 Assembler _assembler_;
2703 GenerateIncrement(&_assembler_); 2703 GenerateIncrement(&_assembler_);
2704 const Function& function = Function::Handle(CreateFunction("Test_Code")); 2704 const Function& function = Function::Handle(CreateFunction("Test_Code"));
2705 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); 2705 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_));
2706 function.AttachCode(code); 2706 function.AttachCode(code);
2707 const Instructions& instructions = Instructions::Handle(code.instructions()); 2707 const Instructions& instructions = Instructions::Handle(code.instructions());
2708 uword entry_point = instructions.EntryPoint(); 2708 uword entry_point = instructions.EntryPoint();
2709 EXPECT_EQ(instructions.raw(), Instructions::FromEntryPoint(entry_point)); 2709 EXPECT_EQ(instructions.raw(), Instructions::FromEntryPoint(entry_point));
2710 const Object& result = Object::Handle( 2710 const Object& result = Object::Handle(
2711 DartEntry::InvokeFunction(function, Array::empty_array())); 2711 DartEntry::InvokeFunction(function, Array::empty_array()));
2712 EXPECT_EQ(1, Smi::Cast(result).Value()); 2712 EXPECT_EQ(1, Smi::Cast(result).Value());
2713 } 2713 }
2714 2714
2715 2715
2716 // Test for immutability of generated instructions. The test crashes with a 2716 // Test for immutability of generated instructions. The test crashes with a
2717 // segmentation fault when writing into it. 2717 // segmentation fault when writing into it.
2718 TEST_CASE(CodeImmutability) { 2718 VM_TEST_CASE(CodeImmutability) {
2719 extern void GenerateIncrement(Assembler* assembler); 2719 extern void GenerateIncrement(Assembler* assembler);
2720 Assembler _assembler_; 2720 Assembler _assembler_;
2721 GenerateIncrement(&_assembler_); 2721 GenerateIncrement(&_assembler_);
2722 const Function& function = Function::Handle(CreateFunction("Test_Code")); 2722 const Function& function = Function::Handle(CreateFunction("Test_Code"));
2723 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); 2723 Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_));
2724 function.AttachCode(code); 2724 function.AttachCode(code);
2725 Instructions& instructions = Instructions::Handle(code.instructions()); 2725 Instructions& instructions = Instructions::Handle(code.instructions());
2726 uword entry_point = instructions.EntryPoint(); 2726 uword entry_point = instructions.EntryPoint();
2727 EXPECT_EQ(instructions.raw(), Instructions::FromEntryPoint(entry_point)); 2727 EXPECT_EQ(instructions.raw(), Instructions::FromEntryPoint(entry_point));
2728 // Try writing into the generated code, expected to crash. 2728 // Try writing into the generated code, expected to crash.
2729 *(reinterpret_cast<char*>(entry_point) + 1) = 1; 2729 *(reinterpret_cast<char*>(entry_point) + 1) = 1;
2730 if (!FLAG_write_protect_code) { 2730 if (!FLAG_write_protect_code) {
2731 // Since this test is expected to crash, crash if write protection of code 2731 // Since this test is expected to crash, crash if write protection of code
2732 // is switched off. 2732 // is switched off.
2733 // TODO(regis, fschneider): Should this be FATAL() instead? 2733 // TODO(regis, fschneider): Should this be FATAL() instead?
2734 OS::DebugBreak(); 2734 OS::DebugBreak();
2735 } 2735 }
2736 } 2736 }
2737 2737
2738 2738
2739 // Test for Embedded String object in the instructions. 2739 // Test for Embedded String object in the instructions.
2740 TEST_CASE(EmbedStringInCode) { 2740 VM_TEST_CASE(EmbedStringInCode) {
2741 extern void GenerateEmbedStringInCode(Assembler* assembler, const char* str); 2741 extern void GenerateEmbedStringInCode(Assembler* assembler, const char* str);
2742 const char* kHello = "Hello World!"; 2742 const char* kHello = "Hello World!";
2743 word expected_length = static_cast<word>(strlen(kHello)); 2743 word expected_length = static_cast<word>(strlen(kHello));
2744 Assembler _assembler_; 2744 Assembler _assembler_;
2745 GenerateEmbedStringInCode(&_assembler_, kHello); 2745 GenerateEmbedStringInCode(&_assembler_, kHello);
2746 const Function& function = 2746 const Function& function =
2747 Function::Handle(CreateFunction("Test_EmbedStringInCode")); 2747 Function::Handle(CreateFunction("Test_EmbedStringInCode"));
2748 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); 2748 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_));
2749 function.AttachCode(code); 2749 function.AttachCode(code);
2750 const Object& result = 2750 const Object& result =
2751 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); 2751 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array()));
2752 EXPECT(result.raw()->IsHeapObject()); 2752 EXPECT(result.raw()->IsHeapObject());
2753 String& string_object = String::Handle(); 2753 String& string_object = String::Handle();
2754 string_object ^= result.raw(); 2754 string_object ^= result.raw();
2755 EXPECT(string_object.Length() == expected_length); 2755 EXPECT(string_object.Length() == expected_length);
2756 for (int i = 0; i < expected_length; i ++) { 2756 for (int i = 0; i < expected_length; i ++) {
2757 EXPECT(string_object.CharAt(i) == kHello[i]); 2757 EXPECT(string_object.CharAt(i) == kHello[i]);
2758 } 2758 }
2759 } 2759 }
2760 2760
2761 2761
2762 // Test for Embedded Smi object in the instructions. 2762 // Test for Embedded Smi object in the instructions.
2763 TEST_CASE(EmbedSmiInCode) { 2763 VM_TEST_CASE(EmbedSmiInCode) {
2764 extern void GenerateEmbedSmiInCode(Assembler* assembler, intptr_t value); 2764 extern void GenerateEmbedSmiInCode(Assembler* assembler, intptr_t value);
2765 const intptr_t kSmiTestValue = 5; 2765 const intptr_t kSmiTestValue = 5;
2766 Assembler _assembler_; 2766 Assembler _assembler_;
2767 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); 2767 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue);
2768 const Function& function = 2768 const Function& function =
2769 Function::Handle(CreateFunction("Test_EmbedSmiInCode")); 2769 Function::Handle(CreateFunction("Test_EmbedSmiInCode"));
2770 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); 2770 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_));
2771 function.AttachCode(code); 2771 function.AttachCode(code);
2772 const Object& result = 2772 const Object& result =
2773 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); 2773 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array()));
2774 EXPECT(Smi::Cast(result).Value() == kSmiTestValue); 2774 EXPECT(Smi::Cast(result).Value() == kSmiTestValue);
2775 } 2775 }
2776 2776
2777 2777
2778 #if defined(ARCH_IS_64_BIT) 2778 #if defined(ARCH_IS_64_BIT)
2779 // Test for Embedded Smi object in the instructions. 2779 // Test for Embedded Smi object in the instructions.
2780 TEST_CASE(EmbedSmiIn64BitCode) { 2780 VM_TEST_CASE(EmbedSmiIn64BitCode) {
2781 extern void GenerateEmbedSmiInCode(Assembler* assembler, intptr_t value); 2781 extern void GenerateEmbedSmiInCode(Assembler* assembler, intptr_t value);
2782 const intptr_t kSmiTestValue = DART_INT64_C(5) << 32; 2782 const intptr_t kSmiTestValue = DART_INT64_C(5) << 32;
2783 Assembler _assembler_; 2783 Assembler _assembler_;
2784 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); 2784 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue);
2785 const Function& function = 2785 const Function& function =
2786 Function::Handle(CreateFunction("Test_EmbedSmiIn64BitCode")); 2786 Function::Handle(CreateFunction("Test_EmbedSmiIn64BitCode"));
2787 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_)); 2787 const Code& code = Code::Handle(Code::FinalizeCode(function, &_assembler_));
2788 function.AttachCode(code); 2788 function.AttachCode(code);
2789 const Object& result = 2789 const Object& result =
2790 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array())); 2790 Object::Handle(DartEntry::InvokeFunction(function, Array::empty_array()));
2791 EXPECT(Smi::Cast(result).Value() == kSmiTestValue); 2791 EXPECT(Smi::Cast(result).Value() == kSmiTestValue);
2792 } 2792 }
2793 #endif // ARCH_IS_64_BIT 2793 #endif // ARCH_IS_64_BIT
2794 2794
2795 2795
2796 TEST_CASE(ExceptionHandlers) { 2796 VM_TEST_CASE(ExceptionHandlers) {
2797 const int kNumEntries = 4; 2797 const int kNumEntries = 4;
2798 // Add an exception handler table to the code. 2798 // Add an exception handler table to the code.
2799 ExceptionHandlers& exception_handlers = ExceptionHandlers::Handle(); 2799 ExceptionHandlers& exception_handlers = ExceptionHandlers::Handle();
2800 exception_handlers ^= ExceptionHandlers::New(kNumEntries); 2800 exception_handlers ^= ExceptionHandlers::New(kNumEntries);
2801 const bool kNeedsStacktrace = true; 2801 const bool kNeedsStacktrace = true;
2802 const bool kNoStacktrace = false; 2802 const bool kNoStacktrace = false;
2803 exception_handlers.SetHandlerInfo(0, -1, 20u, kNeedsStacktrace, false); 2803 exception_handlers.SetHandlerInfo(0, -1, 20u, kNeedsStacktrace, false);
2804 exception_handlers.SetHandlerInfo(1, 0, 30u, kNeedsStacktrace, false); 2804 exception_handlers.SetHandlerInfo(1, 0, 30u, kNeedsStacktrace, false);
2805 exception_handlers.SetHandlerInfo(2, -1, 40u, kNoStacktrace, true); 2805 exception_handlers.SetHandlerInfo(2, -1, 40u, kNoStacktrace, true);
2806 exception_handlers.SetHandlerInfo(3, 1, 150u, kNoStacktrace, true); 2806 exception_handlers.SetHandlerInfo(3, 1, 150u, kNoStacktrace, true);
(...skipping 17 matching lines...) Expand all
2824 EXPECT(handlers.NeedsStacktrace(0)); 2824 EXPECT(handlers.NeedsStacktrace(0));
2825 EXPECT(!handlers.HasCatchAll(0)); 2825 EXPECT(!handlers.HasCatchAll(0));
2826 EXPECT_EQ(20u, info.handler_pc_offset); 2826 EXPECT_EQ(20u, info.handler_pc_offset);
2827 EXPECT_EQ(1, handlers.OuterTryIndex(3)); 2827 EXPECT_EQ(1, handlers.OuterTryIndex(3));
2828 EXPECT_EQ(150u, handlers.HandlerPCOffset(3)); 2828 EXPECT_EQ(150u, handlers.HandlerPCOffset(3));
2829 EXPECT(!handlers.NeedsStacktrace(3)); 2829 EXPECT(!handlers.NeedsStacktrace(3));
2830 EXPECT(handlers.HasCatchAll(3)); 2830 EXPECT(handlers.HasCatchAll(3));
2831 } 2831 }
2832 2832
2833 2833
2834 TEST_CASE(PcDescriptors) { 2834 VM_TEST_CASE(PcDescriptors) {
2835 DescriptorList* builder = new DescriptorList(0); 2835 DescriptorList* builder = new DescriptorList(0);
2836 2836
2837 // kind, pc_offset, deopt_id, token_pos, try_index 2837 // kind, pc_offset, deopt_id, token_pos, try_index
2838 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 1, 20, 1); 2838 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 1, 20, 1);
2839 builder->AddDescriptor(RawPcDescriptors::kDeopt, 20, 2, 30, 0); 2839 builder->AddDescriptor(RawPcDescriptors::kDeopt, 20, 2, 30, 0);
2840 builder->AddDescriptor(RawPcDescriptors::kOther, 30, 3, 40, 1); 2840 builder->AddDescriptor(RawPcDescriptors::kOther, 30, 3, 40, 1);
2841 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 4, 40, 2); 2841 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 4, 40, 2);
2842 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 5, 80, 3); 2842 builder->AddDescriptor(RawPcDescriptors::kOther, 10, 5, 80, 3);
2843 builder->AddDescriptor(RawPcDescriptors::kOther, 80, 6, 150, 3); 2843 builder->AddDescriptor(RawPcDescriptors::kOther, 80, 6, 150, 3);
2844 2844
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2881 2881
2882 EXPECT_EQ(3, iter.TryIndex()); 2882 EXPECT_EQ(3, iter.TryIndex());
2883 EXPECT_EQ(static_cast<uword>(80), iter.PcOffset()); 2883 EXPECT_EQ(static_cast<uword>(80), iter.PcOffset());
2884 EXPECT_EQ(150, iter.TokenPos()); 2884 EXPECT_EQ(150, iter.TokenPos());
2885 EXPECT_EQ(RawPcDescriptors::kOther, iter.Kind()); 2885 EXPECT_EQ(RawPcDescriptors::kOther, iter.Kind());
2886 2886
2887 EXPECT_EQ(false, iter.MoveNext()); 2887 EXPECT_EQ(false, iter.MoveNext());
2888 } 2888 }
2889 2889
2890 2890
2891 TEST_CASE(PcDescriptorsLargeDeltas) { 2891 VM_TEST_CASE(PcDescriptorsLargeDeltas) {
2892 DescriptorList* builder = new DescriptorList(0); 2892 DescriptorList* builder = new DescriptorList(0);
2893 2893
2894 // kind, pc_offset, deopt_id, token_pos, try_index 2894 // kind, pc_offset, deopt_id, token_pos, try_index
2895 builder->AddDescriptor(RawPcDescriptors::kOther, 100, 1, 200, 1); 2895 builder->AddDescriptor(RawPcDescriptors::kOther, 100, 1, 200, 1);
2896 builder->AddDescriptor(RawPcDescriptors::kDeopt, 200, 2, 300, 0); 2896 builder->AddDescriptor(RawPcDescriptors::kDeopt, 200, 2, 300, 0);
2897 builder->AddDescriptor(RawPcDescriptors::kOther, 300, 3, 400, 1); 2897 builder->AddDescriptor(RawPcDescriptors::kOther, 300, 3, 400, 1);
2898 builder->AddDescriptor(RawPcDescriptors::kOther, 100, 4, 0, 2); 2898 builder->AddDescriptor(RawPcDescriptors::kOther, 100, 4, 0, 2);
2899 builder->AddDescriptor(RawPcDescriptors::kOther, 100, 5, 800, 3); 2899 builder->AddDescriptor(RawPcDescriptors::kOther, 100, 5, 800, 3);
2900 builder->AddDescriptor(RawPcDescriptors::kOther, 800, 6, 150, 3); 2900 builder->AddDescriptor(RawPcDescriptors::kOther, 800, 6, 150, 3);
2901 2901
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2956 static RawField* CreateTestField(const char* name) { 2956 static RawField* CreateTestField(const char* name) {
2957 const Class& cls = Class::Handle(CreateTestClass("global:")); 2957 const Class& cls = Class::Handle(CreateTestClass("global:"));
2958 const String& field_name = String::Handle(Symbols::New(name)); 2958 const String& field_name = String::Handle(Symbols::New(name));
2959 const Field& field = 2959 const Field& field =
2960 Field::Handle(Field::New(field_name, true, false, false, true, cls, 2960 Field::Handle(Field::New(field_name, true, false, false, true, cls,
2961 Object::dynamic_type(), 0)); 2961 Object::dynamic_type(), 0));
2962 return field.raw(); 2962 return field.raw();
2963 } 2963 }
2964 2964
2965 2965
2966 TEST_CASE(ClassDictionaryIterator) { 2966 VM_TEST_CASE(ClassDictionaryIterator) {
2967 Class& ae66 = Class::ZoneHandle(CreateTestClass("Ae6/6")); 2967 Class& ae66 = Class::ZoneHandle(CreateTestClass("Ae6/6"));
2968 Class& re44 = Class::ZoneHandle(CreateTestClass("Re4/4")); 2968 Class& re44 = Class::ZoneHandle(CreateTestClass("Re4/4"));
2969 Field& ce68 = Field::ZoneHandle(CreateTestField("Ce6/8")); 2969 Field& ce68 = Field::ZoneHandle(CreateTestField("Ce6/8"));
2970 Field& tee = Field::ZoneHandle(CreateTestField("TEE")); 2970 Field& tee = Field::ZoneHandle(CreateTestField("TEE"));
2971 String& url = String::ZoneHandle(String::New("SBB")); 2971 String& url = String::ZoneHandle(String::New("SBB"));
2972 Library& lib = Library::Handle(Library::New(url)); 2972 Library& lib = Library::Handle(Library::New(url));
2973 lib.AddClass(ae66); 2973 lib.AddClass(ae66);
2974 lib.AddObject(ce68, String::ZoneHandle(ce68.name())); 2974 lib.AddObject(ce68, String::ZoneHandle(ce68.name()));
2975 lib.AddClass(re44); 2975 lib.AddClass(re44);
2976 lib.AddObject(tee, String::ZoneHandle(tee.name())); 2976 lib.AddObject(tee, String::ZoneHandle(tee.name()));
(...skipping 23 matching lines...) Expand all
3000 is_static, 3000 is_static,
3001 is_const, 3001 is_const,
3002 is_abstract, 3002 is_abstract,
3003 is_external, 3003 is_external,
3004 is_native, 3004 is_native,
3005 cls, 3005 cls,
3006 0); 3006 0);
3007 } 3007 }
3008 3008
3009 3009
3010 TEST_CASE(ICData) { 3010 VM_TEST_CASE(ICData) {
3011 Function& function = Function::Handle(GetDummyTarget("Bern")); 3011 Function& function = Function::Handle(GetDummyTarget("Bern"));
3012 const intptr_t id = 12; 3012 const intptr_t id = 12;
3013 const intptr_t num_args_tested = 1; 3013 const intptr_t num_args_tested = 1;
3014 const String& target_name = String::Handle(Symbols::New("Thun")); 3014 const String& target_name = String::Handle(Symbols::New("Thun"));
3015 const Array& args_descriptor = 3015 const Array& args_descriptor =
3016 Array::Handle(ArgumentsDescriptor::New(1, Object::null_array())); 3016 Array::Handle(ArgumentsDescriptor::New(1, Object::null_array()));
3017 ICData& o1 = ICData::Handle(); 3017 ICData& o1 = ICData::Handle();
3018 o1 = ICData::New(function, target_name, args_descriptor, id, num_args_tested); 3018 o1 = ICData::New(function, target_name, args_descriptor, id, num_args_tested);
3019 EXPECT_EQ(1, o1.NumArgsTested()); 3019 EXPECT_EQ(1, o1.NumArgsTested());
3020 EXPECT_EQ(id, o1.deopt_id()); 3020 EXPECT_EQ(id, o1.deopt_id());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3072 3072
3073 // Check ICData for unoptimized static calls. 3073 // Check ICData for unoptimized static calls.
3074 const intptr_t kNumArgsChecked = 0; 3074 const intptr_t kNumArgsChecked = 0;
3075 const ICData& scall_icdata = ICData::Handle( 3075 const ICData& scall_icdata = ICData::Handle(
3076 ICData::New(function, target_name, args_descriptor, 57, kNumArgsChecked)); 3076 ICData::New(function, target_name, args_descriptor, 57, kNumArgsChecked));
3077 scall_icdata.AddTarget(target1); 3077 scall_icdata.AddTarget(target1);
3078 EXPECT_EQ(target1.raw(), scall_icdata.GetTargetAt(0)); 3078 EXPECT_EQ(target1.raw(), scall_icdata.GetTargetAt(0));
3079 } 3079 }
3080 3080
3081 3081
3082 TEST_CASE(SubtypeTestCache) { 3082 VM_TEST_CASE(SubtypeTestCache) {
3083 String& class_name = String::Handle(Symbols::New("EmptyClass")); 3083 String& class_name = String::Handle(Symbols::New("EmptyClass"));
3084 Script& script = Script::Handle(); 3084 Script& script = Script::Handle();
3085 const Class& empty_class = 3085 const Class& empty_class =
3086 Class::Handle(CreateDummyClass(class_name, script)); 3086 Class::Handle(CreateDummyClass(class_name, script));
3087 SubtypeTestCache& cache = SubtypeTestCache::Handle(SubtypeTestCache::New()); 3087 SubtypeTestCache& cache = SubtypeTestCache::Handle(SubtypeTestCache::New());
3088 EXPECT(!cache.IsNull()); 3088 EXPECT(!cache.IsNull());
3089 EXPECT_EQ(0, cache.NumberOfChecks()); 3089 EXPECT_EQ(0, cache.NumberOfChecks());
3090 const Object& class_id_or_fun = Object::Handle(Smi::New(empty_class.id())); 3090 const Object& class_id_or_fun = Object::Handle(Smi::New(empty_class.id()));
3091 const TypeArguments& targ_0 = TypeArguments::Handle(TypeArguments::New(2)); 3091 const TypeArguments& targ_0 = TypeArguments::Handle(TypeArguments::New(2));
3092 const TypeArguments& targ_1 = TypeArguments::Handle(TypeArguments::New(3)); 3092 const TypeArguments& targ_1 = TypeArguments::Handle(TypeArguments::New(3));
3093 cache.AddCheck(class_id_or_fun, targ_0, targ_1, Bool::True()); 3093 cache.AddCheck(class_id_or_fun, targ_0, targ_1, Bool::True());
3094 EXPECT_EQ(1, cache.NumberOfChecks()); 3094 EXPECT_EQ(1, cache.NumberOfChecks());
3095 Object& test_class_id_or_fun = Object::Handle(); 3095 Object& test_class_id_or_fun = Object::Handle();
3096 TypeArguments& test_targ_0 = TypeArguments::Handle(); 3096 TypeArguments& test_targ_0 = TypeArguments::Handle();
3097 TypeArguments& test_targ_1 = TypeArguments::Handle(); 3097 TypeArguments& test_targ_1 = TypeArguments::Handle();
3098 Bool& test_result = Bool::Handle(); 3098 Bool& test_result = Bool::Handle();
3099 cache.GetCheck( 3099 cache.GetCheck(
3100 0, &test_class_id_or_fun, &test_targ_0, &test_targ_1, &test_result); 3100 0, &test_class_id_or_fun, &test_targ_0, &test_targ_1, &test_result);
3101 EXPECT_EQ(class_id_or_fun.raw(), test_class_id_or_fun.raw()); 3101 EXPECT_EQ(class_id_or_fun.raw(), test_class_id_or_fun.raw());
3102 EXPECT_EQ(targ_0.raw(), test_targ_0.raw()); 3102 EXPECT_EQ(targ_0.raw(), test_targ_0.raw());
3103 EXPECT_EQ(targ_1.raw(), test_targ_1.raw()); 3103 EXPECT_EQ(targ_1.raw(), test_targ_1.raw());
3104 EXPECT_EQ(Bool::True().raw(), test_result.raw()); 3104 EXPECT_EQ(Bool::True().raw(), test_result.raw());
3105 } 3105 }
3106 3106
3107 3107
3108 TEST_CASE(FieldTests) { 3108 VM_TEST_CASE(FieldTests) {
3109 const String& f = String::Handle(String::New("oneField")); 3109 const String& f = String::Handle(String::New("oneField"));
3110 const String& getter_f = String::Handle(Field::GetterName(f)); 3110 const String& getter_f = String::Handle(Field::GetterName(f));
3111 const String& setter_f = String::Handle(Field::SetterName(f)); 3111 const String& setter_f = String::Handle(Field::SetterName(f));
3112 EXPECT(!Field::IsGetterName(f)); 3112 EXPECT(!Field::IsGetterName(f));
3113 EXPECT(!Field::IsSetterName(f)); 3113 EXPECT(!Field::IsSetterName(f));
3114 EXPECT(Field::IsGetterName(getter_f)); 3114 EXPECT(Field::IsGetterName(getter_f));
3115 EXPECT(!Field::IsSetterName(getter_f)); 3115 EXPECT(!Field::IsSetterName(getter_f));
3116 EXPECT(!Field::IsGetterName(setter_f)); 3116 EXPECT(!Field::IsGetterName(setter_f));
3117 EXPECT(Field::IsSetterName(setter_f)); 3117 EXPECT(Field::IsSetterName(setter_f));
3118 EXPECT_STREQ(f.ToCString(), 3118 EXPECT_STREQ(f.ToCString(),
3119 String::Handle(Field::NameFromGetter(getter_f)).ToCString()); 3119 String::Handle(Field::NameFromGetter(getter_f)).ToCString());
3120 EXPECT_STREQ(f.ToCString(), 3120 EXPECT_STREQ(f.ToCString(),
3121 String::Handle(Field::NameFromSetter(setter_f)).ToCString()); 3121 String::Handle(Field::NameFromSetter(setter_f)).ToCString());
3122 } 3122 }
3123 3123
3124 3124
3125 3125
3126 3126
3127 // Expose helper function from object.cc for testing. 3127 // Expose helper function from object.cc for testing.
3128 bool EqualsIgnoringPrivate(const String& name, const String& private_name); 3128 bool EqualsIgnoringPrivate(const String& name, const String& private_name);
3129 3129
3130 3130
3131 TEST_CASE(EqualsIgnoringPrivate) { 3131 VM_TEST_CASE(EqualsIgnoringPrivate) {
3132 String& mangled_name = String::Handle(); 3132 String& mangled_name = String::Handle();
3133 String& bare_name = String::Handle(); 3133 String& bare_name = String::Handle();
3134 3134
3135 // Simple matches. 3135 // Simple matches.
3136 mangled_name = OneByteString::New("foo"); 3136 mangled_name = OneByteString::New("foo");
3137 bare_name = OneByteString::New("foo"); 3137 bare_name = OneByteString::New("foo");
3138 EXPECT(String::EqualsIgnoringPrivateKey(mangled_name, bare_name)); 3138 EXPECT(String::EqualsIgnoringPrivateKey(mangled_name, bare_name));
3139 3139
3140 mangled_name = OneByteString::New("foo."); 3140 mangled_name = OneByteString::New("foo.");
3141 bare_name = OneByteString::New("foo."); 3141 bare_name = OneByteString::New("foo.");
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
3254 // str1 - ExternalOneByteString, str2 - OneByteString. 3254 // str1 - ExternalOneByteString, str2 - OneByteString.
3255 EXPECT(String::EqualsIgnoringPrivateKey(ext_mangled_name, bare_name)); 3255 EXPECT(String::EqualsIgnoringPrivateKey(ext_mangled_name, bare_name));
3256 3256
3257 // str1 - ExternalOneByteString, str2 - ExternalOneByteString. 3257 // str1 - ExternalOneByteString, str2 - ExternalOneByteString.
3258 EXPECT(String::EqualsIgnoringPrivateKey(ext_mangled_name, ext_bare_name)); 3258 EXPECT(String::EqualsIgnoringPrivateKey(ext_mangled_name, ext_bare_name));
3259 EXPECT(!String::EqualsIgnoringPrivateKey(ext_mangled_name, 3259 EXPECT(!String::EqualsIgnoringPrivateKey(ext_mangled_name,
3260 ext_bad_bare_name)); 3260 ext_bad_bare_name));
3261 } 3261 }
3262 3262
3263 3263
3264 TEST_CASE(ArrayNew_Overflow_Crash) { 3264 VM_TEST_CASE(ArrayNew_Overflow_Crash) {
3265 Array::Handle(Array::New(Array::kMaxElements + 1)); 3265 Array::Handle(Array::New(Array::kMaxElements + 1));
3266 } 3266 }
3267 3267
3268 3268
3269 TEST_CASE(StackTraceFormat) { 3269 TEST_CASE(StackTraceFormat) {
3270 const char* kScriptChars = 3270 const char* kScriptChars =
3271 "void baz() {\n" 3271 "void baz() {\n"
3272 " throw 'MyException';\n" 3272 " throw 'MyException';\n"
3273 "}\n" 3273 "}\n"
3274 "\n" 3274 "\n"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3320 "#4 MyClass.field (test-lib:25:5)\n" 3320 "#4 MyClass.field (test-lib:25:5)\n"
3321 "#5 MyClass.foo.fooHelper (test-lib:30:7)\n" 3321 "#5 MyClass.foo.fooHelper (test-lib:30:7)\n"
3322 "#6 MyClass.foo (test-lib:32:14)\n" 3322 "#6 MyClass.foo (test-lib:32:14)\n"
3323 "#7 MyClass.MyClass.<anonymous closure> (test-lib:21:12)\n" 3323 "#7 MyClass.MyClass.<anonymous closure> (test-lib:21:12)\n"
3324 "#8 MyClass.MyClass (test-lib:21:18)\n" 3324 "#8 MyClass.MyClass (test-lib:21:18)\n"
3325 "#9 main.<anonymous closure> (test-lib:37:14)\n" 3325 "#9 main.<anonymous closure> (test-lib:37:14)\n"
3326 "#10 main (test-lib:37:24)"); 3326 "#10 main (test-lib:37:24)");
3327 } 3327 }
3328 3328
3329 3329
3330 TEST_CASE(WeakProperty_PreserveCrossGen) { 3330 VM_TEST_CASE(WeakProperty_PreserveCrossGen) {
3331 Isolate* isolate = Isolate::Current(); 3331 Isolate* isolate = Isolate::Current();
3332 WeakProperty& weak = WeakProperty::Handle(); 3332 WeakProperty& weak = WeakProperty::Handle();
3333 { 3333 {
3334 // Weak property and value in new. Key in old. 3334 // Weak property and value in new. Key in old.
3335 HANDLESCOPE(thread); 3335 HANDLESCOPE(thread);
3336 String& key = String::Handle(); 3336 String& key = String::Handle();
3337 key ^= OneByteString::New("key", Heap::kOld); 3337 key ^= OneByteString::New("key", Heap::kOld);
3338 String& value = String::Handle(); 3338 String& value = String::Handle();
3339 value ^= OneByteString::New("value", Heap::kNew); 3339 value ^= OneByteString::New("value", Heap::kNew);
3340 weak ^= WeakProperty::New(Heap::kNew); 3340 weak ^= WeakProperty::New(Heap::kNew);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
3432 value ^= OneByteString::null(); 3432 value ^= OneByteString::null();
3433 } 3433 }
3434 isolate->heap()->CollectAllGarbage(); 3434 isolate->heap()->CollectAllGarbage();
3435 // Weak property key and value should survive due to cross-generation 3435 // Weak property key and value should survive due to cross-generation
3436 // pointers. 3436 // pointers.
3437 EXPECT(weak.key() != Object::null()); 3437 EXPECT(weak.key() != Object::null());
3438 EXPECT(weak.value() != Object::null()); 3438 EXPECT(weak.value() != Object::null());
3439 } 3439 }
3440 3440
3441 3441
3442 TEST_CASE(WeakProperty_PreserveRecurse) { 3442 VM_TEST_CASE(WeakProperty_PreserveRecurse) {
3443 // This used to end in an infinite recursion. Caused by scavenging the weak 3443 // This used to end in an infinite recursion. Caused by scavenging the weak
3444 // property before scavenging the key. 3444 // property before scavenging the key.
3445 Isolate* isolate = Isolate::Current(); 3445 Isolate* isolate = Isolate::Current();
3446 WeakProperty& weak = WeakProperty::Handle(); 3446 WeakProperty& weak = WeakProperty::Handle();
3447 Array& arr = Array::Handle(Array::New(1)); 3447 Array& arr = Array::Handle(Array::New(1));
3448 { 3448 {
3449 HANDLESCOPE(thread); 3449 HANDLESCOPE(thread);
3450 String& key = String::Handle(); 3450 String& key = String::Handle();
3451 key ^= OneByteString::New("key"); 3451 key ^= OneByteString::New("key");
3452 arr.SetAt(0, key); 3452 arr.SetAt(0, key);
3453 String& value = String::Handle(); 3453 String& value = String::Handle();
3454 value ^= OneByteString::New("value"); 3454 value ^= OneByteString::New("value");
3455 weak ^= WeakProperty::New(); 3455 weak ^= WeakProperty::New();
3456 weak.set_key(key); 3456 weak.set_key(key);
3457 weak.set_value(value); 3457 weak.set_value(value);
3458 } 3458 }
3459 isolate->heap()->CollectAllGarbage(); 3459 isolate->heap()->CollectAllGarbage();
3460 EXPECT(weak.key() != Object::null()); 3460 EXPECT(weak.key() != Object::null());
3461 EXPECT(weak.value() != Object::null()); 3461 EXPECT(weak.value() != Object::null());
3462 } 3462 }
3463 3463
3464 3464
3465 TEST_CASE(WeakProperty_PreserveOne_NewSpace) { 3465 VM_TEST_CASE(WeakProperty_PreserveOne_NewSpace) {
3466 Isolate* isolate = Isolate::Current(); 3466 Isolate* isolate = Isolate::Current();
3467 WeakProperty& weak = WeakProperty::Handle(); 3467 WeakProperty& weak = WeakProperty::Handle();
3468 String& key = String::Handle(); 3468 String& key = String::Handle();
3469 key ^= OneByteString::New("key"); 3469 key ^= OneByteString::New("key");
3470 { 3470 {
3471 HANDLESCOPE(thread); 3471 HANDLESCOPE(thread);
3472 String& value = String::Handle(); 3472 String& value = String::Handle();
3473 value ^= OneByteString::New("value"); 3473 value ^= OneByteString::New("value");
3474 weak ^= WeakProperty::New(); 3474 weak ^= WeakProperty::New();
3475 weak.set_key(key); 3475 weak.set_key(key);
3476 weak.set_value(value); 3476 weak.set_value(value);
3477 } 3477 }
3478 isolate->heap()->CollectAllGarbage(); 3478 isolate->heap()->CollectAllGarbage();
3479 EXPECT(weak.key() != Object::null()); 3479 EXPECT(weak.key() != Object::null());
3480 EXPECT(weak.value() != Object::null()); 3480 EXPECT(weak.value() != Object::null());
3481 } 3481 }
3482 3482
3483 3483
3484 TEST_CASE(WeakProperty_PreserveTwo_NewSpace) { 3484 VM_TEST_CASE(WeakProperty_PreserveTwo_NewSpace) {
3485 Isolate* isolate = Isolate::Current(); 3485 Isolate* isolate = Isolate::Current();
3486 WeakProperty& weak1 = WeakProperty::Handle(); 3486 WeakProperty& weak1 = WeakProperty::Handle();
3487 String& key1 = String::Handle(); 3487 String& key1 = String::Handle();
3488 key1 ^= OneByteString::New("key1"); 3488 key1 ^= OneByteString::New("key1");
3489 WeakProperty& weak2 = WeakProperty::Handle(); 3489 WeakProperty& weak2 = WeakProperty::Handle();
3490 String& key2 = String::Handle(); 3490 String& key2 = String::Handle();
3491 key2 ^= OneByteString::New("key2"); 3491 key2 ^= OneByteString::New("key2");
3492 { 3492 {
3493 HANDLESCOPE(thread); 3493 HANDLESCOPE(thread);
3494 String& value1 = String::Handle(); 3494 String& value1 = String::Handle();
3495 value1 ^= OneByteString::New("value1"); 3495 value1 ^= OneByteString::New("value1");
3496 weak1 ^= WeakProperty::New(); 3496 weak1 ^= WeakProperty::New();
3497 weak1.set_key(key1); 3497 weak1.set_key(key1);
3498 weak1.set_value(value1); 3498 weak1.set_value(value1);
3499 String& value2 = String::Handle(); 3499 String& value2 = String::Handle();
3500 value2 ^= OneByteString::New("value2"); 3500 value2 ^= OneByteString::New("value2");
3501 weak2 ^= WeakProperty::New(); 3501 weak2 ^= WeakProperty::New();
3502 weak2.set_key(key2); 3502 weak2.set_key(key2);
3503 weak2.set_value(value2); 3503 weak2.set_value(value2);
3504 } 3504 }
3505 isolate->heap()->CollectAllGarbage(); 3505 isolate->heap()->CollectAllGarbage();
3506 EXPECT(weak1.key() != Object::null()); 3506 EXPECT(weak1.key() != Object::null());
3507 EXPECT(weak1.value() != Object::null()); 3507 EXPECT(weak1.value() != Object::null());
3508 EXPECT(weak2.key() != Object::null()); 3508 EXPECT(weak2.key() != Object::null());
3509 EXPECT(weak2.value() != Object::null()); 3509 EXPECT(weak2.value() != Object::null());
3510 } 3510 }
3511 3511
3512 3512
3513 TEST_CASE(WeakProperty_PreserveTwoShared_NewSpace) { 3513 VM_TEST_CASE(WeakProperty_PreserveTwoShared_NewSpace) {
3514 Isolate* isolate = Isolate::Current(); 3514 Isolate* isolate = Isolate::Current();
3515 WeakProperty& weak1 = WeakProperty::Handle(); 3515 WeakProperty& weak1 = WeakProperty::Handle();
3516 WeakProperty& weak2 = WeakProperty::Handle(); 3516 WeakProperty& weak2 = WeakProperty::Handle();
3517 String& key = String::Handle(); 3517 String& key = String::Handle();
3518 key ^= OneByteString::New("key"); 3518 key ^= OneByteString::New("key");
3519 { 3519 {
3520 HANDLESCOPE(thread); 3520 HANDLESCOPE(thread);
3521 String& value1 = String::Handle(); 3521 String& value1 = String::Handle();
3522 value1 ^= OneByteString::New("value1"); 3522 value1 ^= OneByteString::New("value1");
3523 weak1 ^= WeakProperty::New(); 3523 weak1 ^= WeakProperty::New();
3524 weak1.set_key(key); 3524 weak1.set_key(key);
3525 weak1.set_value(value1); 3525 weak1.set_value(value1);
3526 String& value2 = String::Handle(); 3526 String& value2 = String::Handle();
3527 value2 ^= OneByteString::New("value2"); 3527 value2 ^= OneByteString::New("value2");
3528 weak2 ^= WeakProperty::New(); 3528 weak2 ^= WeakProperty::New();
3529 weak2.set_key(key); 3529 weak2.set_key(key);
3530 weak2.set_value(value2); 3530 weak2.set_value(value2);
3531 } 3531 }
3532 isolate->heap()->CollectAllGarbage(); 3532 isolate->heap()->CollectAllGarbage();
3533 EXPECT(weak1.key() != Object::null()); 3533 EXPECT(weak1.key() != Object::null());
3534 EXPECT(weak1.value() != Object::null()); 3534 EXPECT(weak1.value() != Object::null());
3535 EXPECT(weak2.key() != Object::null()); 3535 EXPECT(weak2.key() != Object::null());
3536 EXPECT(weak2.value() != Object::null()); 3536 EXPECT(weak2.value() != Object::null());
3537 } 3537 }
3538 3538
3539 3539
3540 TEST_CASE(WeakProperty_PreserveOne_OldSpace) { 3540 VM_TEST_CASE(WeakProperty_PreserveOne_OldSpace) {
3541 Isolate* isolate = Isolate::Current(); 3541 Isolate* isolate = Isolate::Current();
3542 WeakProperty& weak = WeakProperty::Handle(); 3542 WeakProperty& weak = WeakProperty::Handle();
3543 String& key = String::Handle(); 3543 String& key = String::Handle();
3544 key ^= OneByteString::New("key", Heap::kOld); 3544 key ^= OneByteString::New("key", Heap::kOld);
3545 { 3545 {
3546 HANDLESCOPE(thread); 3546 HANDLESCOPE(thread);
3547 String& value = String::Handle(); 3547 String& value = String::Handle();
3548 value ^= OneByteString::New("value", Heap::kOld); 3548 value ^= OneByteString::New("value", Heap::kOld);
3549 weak ^= WeakProperty::New(Heap::kOld); 3549 weak ^= WeakProperty::New(Heap::kOld);
3550 weak.set_key(key); 3550 weak.set_key(key);
3551 weak.set_value(value); 3551 weak.set_value(value);
3552 } 3552 }
3553 isolate->heap()->CollectAllGarbage(); 3553 isolate->heap()->CollectAllGarbage();
3554 EXPECT(weak.key() != Object::null()); 3554 EXPECT(weak.key() != Object::null());
3555 EXPECT(weak.value() != Object::null()); 3555 EXPECT(weak.value() != Object::null());
3556 } 3556 }
3557 3557
3558 3558
3559 TEST_CASE(WeakProperty_PreserveTwo_OldSpace) { 3559 VM_TEST_CASE(WeakProperty_PreserveTwo_OldSpace) {
3560 Isolate* isolate = Isolate::Current(); 3560 Isolate* isolate = Isolate::Current();
3561 WeakProperty& weak1 = WeakProperty::Handle(); 3561 WeakProperty& weak1 = WeakProperty::Handle();
3562 String& key1 = String::Handle(); 3562 String& key1 = String::Handle();
3563 key1 ^= OneByteString::New("key1", Heap::kOld); 3563 key1 ^= OneByteString::New("key1", Heap::kOld);
3564 WeakProperty& weak2 = WeakProperty::Handle(); 3564 WeakProperty& weak2 = WeakProperty::Handle();
3565 String& key2 = String::Handle(); 3565 String& key2 = String::Handle();
3566 key2 ^= OneByteString::New("key2", Heap::kOld); 3566 key2 ^= OneByteString::New("key2", Heap::kOld);
3567 { 3567 {
3568 HANDLESCOPE(thread); 3568 HANDLESCOPE(thread);
3569 String& value1 = String::Handle(); 3569 String& value1 = String::Handle();
3570 value1 ^= OneByteString::New("value1", Heap::kOld); 3570 value1 ^= OneByteString::New("value1", Heap::kOld);
3571 weak1 ^= WeakProperty::New(Heap::kOld); 3571 weak1 ^= WeakProperty::New(Heap::kOld);
3572 weak1.set_key(key1); 3572 weak1.set_key(key1);
3573 weak1.set_value(value1); 3573 weak1.set_value(value1);
3574 String& value2 = String::Handle(); 3574 String& value2 = String::Handle();
3575 value2 ^= OneByteString::New("value2", Heap::kOld); 3575 value2 ^= OneByteString::New("value2", Heap::kOld);
3576 weak2 ^= WeakProperty::New(Heap::kOld); 3576 weak2 ^= WeakProperty::New(Heap::kOld);
3577 weak2.set_key(key2); 3577 weak2.set_key(key2);
3578 weak2.set_value(value2); 3578 weak2.set_value(value2);
3579 } 3579 }
3580 isolate->heap()->CollectAllGarbage(); 3580 isolate->heap()->CollectAllGarbage();
3581 EXPECT(weak1.key() != Object::null()); 3581 EXPECT(weak1.key() != Object::null());
3582 EXPECT(weak1.value() != Object::null()); 3582 EXPECT(weak1.value() != Object::null());
3583 EXPECT(weak2.key() != Object::null()); 3583 EXPECT(weak2.key() != Object::null());
3584 EXPECT(weak2.value() != Object::null()); 3584 EXPECT(weak2.value() != Object::null());
3585 } 3585 }
3586 3586
3587 3587
3588 TEST_CASE(WeakProperty_PreserveTwoShared_OldSpace) { 3588 VM_TEST_CASE(WeakProperty_PreserveTwoShared_OldSpace) {
3589 Isolate* isolate = Isolate::Current(); 3589 Isolate* isolate = Isolate::Current();
3590 WeakProperty& weak1 = WeakProperty::Handle(); 3590 WeakProperty& weak1 = WeakProperty::Handle();
3591 WeakProperty& weak2 = WeakProperty::Handle(); 3591 WeakProperty& weak2 = WeakProperty::Handle();
3592 String& key = String::Handle(); 3592 String& key = String::Handle();
3593 key ^= OneByteString::New("key", Heap::kOld); 3593 key ^= OneByteString::New("key", Heap::kOld);
3594 { 3594 {
3595 HANDLESCOPE(thread); 3595 HANDLESCOPE(thread);
3596 String& value1 = String::Handle(); 3596 String& value1 = String::Handle();
3597 value1 ^= OneByteString::New("value1", Heap::kOld); 3597 value1 ^= OneByteString::New("value1", Heap::kOld);
3598 weak1 ^= WeakProperty::New(Heap::kOld); 3598 weak1 ^= WeakProperty::New(Heap::kOld);
3599 weak1.set_key(key); 3599 weak1.set_key(key);
3600 weak1.set_value(value1); 3600 weak1.set_value(value1);
3601 String& value2 = String::Handle(); 3601 String& value2 = String::Handle();
3602 value2 ^= OneByteString::New("value2", Heap::kOld); 3602 value2 ^= OneByteString::New("value2", Heap::kOld);
3603 weak2 ^= WeakProperty::New(Heap::kOld); 3603 weak2 ^= WeakProperty::New(Heap::kOld);
3604 weak2.set_key(key); 3604 weak2.set_key(key);
3605 weak2.set_value(value2); 3605 weak2.set_value(value2);
3606 } 3606 }
3607 isolate->heap()->CollectAllGarbage(); 3607 isolate->heap()->CollectAllGarbage();
3608 EXPECT(weak1.key() != Object::null()); 3608 EXPECT(weak1.key() != Object::null());
3609 EXPECT(weak1.value() != Object::null()); 3609 EXPECT(weak1.value() != Object::null());
3610 EXPECT(weak2.key() != Object::null()); 3610 EXPECT(weak2.key() != Object::null());
3611 EXPECT(weak2.value() != Object::null()); 3611 EXPECT(weak2.value() != Object::null());
3612 } 3612 }
3613 3613
3614 3614
3615 TEST_CASE(WeakProperty_ClearOne_NewSpace) { 3615 VM_TEST_CASE(WeakProperty_ClearOne_NewSpace) {
3616 Isolate* isolate = Isolate::Current(); 3616 Isolate* isolate = Isolate::Current();
3617 WeakProperty& weak = WeakProperty::Handle(); 3617 WeakProperty& weak = WeakProperty::Handle();
3618 { 3618 {
3619 HANDLESCOPE(thread); 3619 HANDLESCOPE(thread);
3620 String& key = String::Handle(); 3620 String& key = String::Handle();
3621 key ^= OneByteString::New("key"); 3621 key ^= OneByteString::New("key");
3622 String& value = String::Handle(); 3622 String& value = String::Handle();
3623 value ^= OneByteString::New("value"); 3623 value ^= OneByteString::New("value");
3624 weak ^= WeakProperty::New(); 3624 weak ^= WeakProperty::New();
3625 weak.set_key(key); 3625 weak.set_key(key);
3626 weak.set_value(value); 3626 weak.set_value(value);
3627 key ^= OneByteString::null(); 3627 key ^= OneByteString::null();
3628 value ^= OneByteString::null(); 3628 value ^= OneByteString::null();
3629 } 3629 }
3630 isolate->heap()->CollectAllGarbage(); 3630 isolate->heap()->CollectAllGarbage();
3631 EXPECT(weak.key() == Object::null()); 3631 EXPECT(weak.key() == Object::null());
3632 EXPECT(weak.value() == Object::null()); 3632 EXPECT(weak.value() == Object::null());
3633 } 3633 }
3634 3634
3635 3635
3636 TEST_CASE(WeakProperty_ClearTwoShared_NewSpace) { 3636 VM_TEST_CASE(WeakProperty_ClearTwoShared_NewSpace) {
3637 Isolate* isolate = Isolate::Current(); 3637 Isolate* isolate = Isolate::Current();
3638 WeakProperty& weak1 = WeakProperty::Handle(); 3638 WeakProperty& weak1 = WeakProperty::Handle();
3639 WeakProperty& weak2 = WeakProperty::Handle(); 3639 WeakProperty& weak2 = WeakProperty::Handle();
3640 { 3640 {
3641 HANDLESCOPE(thread); 3641 HANDLESCOPE(thread);
3642 String& key = String::Handle(); 3642 String& key = String::Handle();
3643 key ^= OneByteString::New("key"); 3643 key ^= OneByteString::New("key");
3644 String& value1 = String::Handle(); 3644 String& value1 = String::Handle();
3645 value1 ^= OneByteString::New("value1"); 3645 value1 ^= OneByteString::New("value1");
3646 weak1 ^= WeakProperty::New(); 3646 weak1 ^= WeakProperty::New();
3647 weak1.set_key(key); 3647 weak1.set_key(key);
3648 weak1.set_value(value1); 3648 weak1.set_value(value1);
3649 String& value2 = String::Handle(); 3649 String& value2 = String::Handle();
3650 value2 ^= OneByteString::New("value2"); 3650 value2 ^= OneByteString::New("value2");
3651 weak2 ^= WeakProperty::New(); 3651 weak2 ^= WeakProperty::New();
3652 weak2.set_key(key); 3652 weak2.set_key(key);
3653 weak2.set_value(value2); 3653 weak2.set_value(value2);
3654 } 3654 }
3655 isolate->heap()->CollectAllGarbage(); 3655 isolate->heap()->CollectAllGarbage();
3656 EXPECT(weak1.key() == Object::null()); 3656 EXPECT(weak1.key() == Object::null());
3657 EXPECT(weak1.value() == Object::null()); 3657 EXPECT(weak1.value() == Object::null());
3658 EXPECT(weak2.key() == Object::null()); 3658 EXPECT(weak2.key() == Object::null());
3659 EXPECT(weak2.value() == Object::null()); 3659 EXPECT(weak2.value() == Object::null());
3660 } 3660 }
3661 3661
3662 3662
3663 TEST_CASE(WeakProperty_ClearOne_OldSpace) { 3663 VM_TEST_CASE(WeakProperty_ClearOne_OldSpace) {
3664 Isolate* isolate = Isolate::Current(); 3664 Isolate* isolate = Isolate::Current();
3665 WeakProperty& weak = WeakProperty::Handle(); 3665 WeakProperty& weak = WeakProperty::Handle();
3666 { 3666 {
3667 HANDLESCOPE(thread); 3667 HANDLESCOPE(thread);
3668 String& key = String::Handle(); 3668 String& key = String::Handle();
3669 key ^= OneByteString::New("key", Heap::kOld); 3669 key ^= OneByteString::New("key", Heap::kOld);
3670 String& value = String::Handle(); 3670 String& value = String::Handle();
3671 value ^= OneByteString::New("value", Heap::kOld); 3671 value ^= OneByteString::New("value", Heap::kOld);
3672 weak ^= WeakProperty::New(Heap::kOld); 3672 weak ^= WeakProperty::New(Heap::kOld);
3673 weak.set_key(key); 3673 weak.set_key(key);
3674 weak.set_value(value); 3674 weak.set_value(value);
3675 key ^= OneByteString::null(); 3675 key ^= OneByteString::null();
3676 value ^= OneByteString::null(); 3676 value ^= OneByteString::null();
3677 } 3677 }
3678 isolate->heap()->CollectAllGarbage(); 3678 isolate->heap()->CollectAllGarbage();
3679 EXPECT(weak.key() == Object::null()); 3679 EXPECT(weak.key() == Object::null());
3680 EXPECT(weak.value() == Object::null()); 3680 EXPECT(weak.value() == Object::null());
3681 } 3681 }
3682 3682
3683 3683
3684 TEST_CASE(WeakProperty_ClearTwoShared_OldSpace) { 3684 VM_TEST_CASE(WeakProperty_ClearTwoShared_OldSpace) {
3685 Isolate* isolate = Isolate::Current(); 3685 Isolate* isolate = Isolate::Current();
3686 WeakProperty& weak1 = WeakProperty::Handle(); 3686 WeakProperty& weak1 = WeakProperty::Handle();
3687 WeakProperty& weak2 = WeakProperty::Handle(); 3687 WeakProperty& weak2 = WeakProperty::Handle();
3688 { 3688 {
3689 HANDLESCOPE(thread); 3689 HANDLESCOPE(thread);
3690 String& key = String::Handle(); 3690 String& key = String::Handle();
3691 key ^= OneByteString::New("key", Heap::kOld); 3691 key ^= OneByteString::New("key", Heap::kOld);
3692 String& value1 = String::Handle(); 3692 String& value1 = String::Handle();
3693 value1 ^= OneByteString::New("value1"); 3693 value1 ^= OneByteString::New("value1");
3694 weak1 ^= WeakProperty::New(Heap::kOld); 3694 weak1 ^= WeakProperty::New(Heap::kOld);
3695 weak1.set_key(key); 3695 weak1.set_key(key);
3696 weak1.set_value(value1); 3696 weak1.set_value(value1);
3697 String& value2 = String::Handle(); 3697 String& value2 = String::Handle();
3698 value2 ^= OneByteString::New("value2", Heap::kOld); 3698 value2 ^= OneByteString::New("value2", Heap::kOld);
3699 weak2 ^= WeakProperty::New(Heap::kOld); 3699 weak2 ^= WeakProperty::New(Heap::kOld);
3700 weak2.set_key(key); 3700 weak2.set_key(key);
3701 weak2.set_value(value2); 3701 weak2.set_value(value2);
3702 } 3702 }
3703 isolate->heap()->CollectAllGarbage(); 3703 isolate->heap()->CollectAllGarbage();
3704 EXPECT(weak1.key() == Object::null()); 3704 EXPECT(weak1.key() == Object::null());
3705 EXPECT(weak1.value() == Object::null()); 3705 EXPECT(weak1.value() == Object::null());
3706 EXPECT(weak2.key() == Object::null()); 3706 EXPECT(weak2.key() == Object::null());
3707 EXPECT(weak2.value() == Object::null()); 3707 EXPECT(weak2.value() == Object::null());
3708 } 3708 }
3709 3709
3710 3710
3711 TEST_CASE(MirrorReference) { 3711 VM_TEST_CASE(MirrorReference) {
3712 const MirrorReference& reference = 3712 const MirrorReference& reference =
3713 MirrorReference::Handle(MirrorReference::New(Object::Handle())); 3713 MirrorReference::Handle(MirrorReference::New(Object::Handle()));
3714 Object& initial_referent = Object::Handle(reference.referent()); 3714 Object& initial_referent = Object::Handle(reference.referent());
3715 EXPECT(initial_referent.IsNull()); 3715 EXPECT(initial_referent.IsNull());
3716 3716
3717 Library& library = Library::Handle(Library::CoreLibrary()); 3717 Library& library = Library::Handle(Library::CoreLibrary());
3718 EXPECT(!library.IsNull()); 3718 EXPECT(!library.IsNull());
3719 EXPECT(library.IsLibrary()); 3719 EXPECT(library.IsLibrary());
3720 reference.set_referent(library); 3720 reference.set_referent(library);
3721 const Object& returned_referent = Object::Handle(reference.referent()); 3721 const Object& returned_referent = Object::Handle(reference.referent());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3759 3759
3760 3760
3761 static RawClass* GetClass(const Library& lib, const char* name) { 3761 static RawClass* GetClass(const Library& lib, const char* name) {
3762 const Class& cls = Class::Handle( 3762 const Class& cls = Class::Handle(
3763 lib.LookupClass(String::Handle(Symbols::New(name)))); 3763 lib.LookupClass(String::Handle(Symbols::New(name))));
3764 EXPECT(!cls.IsNull()); // No ambiguity error expected. 3764 EXPECT(!cls.IsNull()); // No ambiguity error expected.
3765 return cls.raw(); 3765 return cls.raw();
3766 } 3766 }
3767 3767
3768 3768
3769 TEST_CASE(FindClosureIndex) { 3769 VM_TEST_CASE(FindClosureIndex) {
3770 // Allocate the class first. 3770 // Allocate the class first.
3771 const String& class_name = String::Handle(Symbols::New("MyClass")); 3771 const String& class_name = String::Handle(Symbols::New("MyClass"));
3772 const Script& script = Script::Handle(); 3772 const Script& script = Script::Handle();
3773 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); 3773 const Class& cls = Class::Handle(CreateDummyClass(class_name, script));
3774 const Array& functions = Array::Handle(Array::New(1)); 3774 const Array& functions = Array::Handle(Array::New(1));
3775 const Isolate* iso = Isolate::Current(); 3775 const Isolate* iso = Isolate::Current();
3776 3776
3777 Function& parent = Function::Handle(); 3777 Function& parent = Function::Handle();
3778 const String& parent_name = String::Handle(Symbols::New("foo_papa")); 3778 const String& parent_name = String::Handle(Symbols::New("foo_papa"));
3779 parent = Function::New(parent_name, RawFunction::kRegularFunction, 3779 parent = Function::New(parent_name, RawFunction::kRegularFunction,
(...skipping 15 matching lines...) Expand all
3795 EXPECT_EQ(bad_closure_index, -1); 3795 EXPECT_EQ(bad_closure_index, -1);
3796 3796
3797 // Retrieve closure function via index. 3797 // Retrieve closure function via index.
3798 Function& func_from_index = Function::Handle(); 3798 Function& func_from_index = Function::Handle();
3799 func_from_index ^= iso->ClosureFunctionFromIndex(good_closure_index); 3799 func_from_index ^= iso->ClosureFunctionFromIndex(good_closure_index);
3800 // Same closure function. 3800 // Same closure function.
3801 EXPECT_EQ(func_from_index.raw(), function.raw()); 3801 EXPECT_EQ(func_from_index.raw(), function.raw());
3802 } 3802 }
3803 3803
3804 3804
3805 TEST_CASE(FindInvocationDispatcherFunctionIndex) { 3805 VM_TEST_CASE(FindInvocationDispatcherFunctionIndex) {
3806 const String& class_name = String::Handle(Symbols::New("MyClass")); 3806 const String& class_name = String::Handle(Symbols::New("MyClass"));
3807 const Script& script = Script::Handle(); 3807 const Script& script = Script::Handle();
3808 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); 3808 const Class& cls = Class::Handle(CreateDummyClass(class_name, script));
3809 ClassFinalizer::FinalizeTypesInClass(cls); 3809 ClassFinalizer::FinalizeTypesInClass(cls);
3810 3810
3811 const Array& functions = Array::Handle(Array::New(1)); 3811 const Array& functions = Array::Handle(Array::New(1));
3812 Function& parent = Function::Handle(); 3812 Function& parent = Function::Handle();
3813 const String& parent_name = String::Handle(Symbols::New("foo_papa")); 3813 const String& parent_name = String::Handle(Symbols::New("foo_papa"));
3814 parent = Function::New(parent_name, RawFunction::kRegularFunction, 3814 parent = Function::New(parent_name, RawFunction::kRegularFunction,
3815 false, false, false, false, false, cls, 0); 3815 false, false, false, false, false, cls, 0);
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
4046 4046
4047 // After setting a breakpoint in a function A.b, it is no longer inlineable. 4047 // After setting a breakpoint in a function A.b, it is no longer inlineable.
4048 Breakpoint* bpt = 4048 Breakpoint* bpt =
4049 Isolate::Current()->debugger()->SetBreakpointAtLine(name, 4049 Isolate::Current()->debugger()->SetBreakpointAtLine(name,
4050 kBreakpointLine); 4050 kBreakpointLine);
4051 ASSERT(bpt != NULL); 4051 ASSERT(bpt != NULL);
4052 EXPECT(!func_b.CanBeInlined()); 4052 EXPECT(!func_b.CanBeInlined());
4053 } 4053 }
4054 4054
4055 4055
4056 TEST_CASE(SpecialClassesHaveEmptyArrays) { 4056 VM_TEST_CASE(SpecialClassesHaveEmptyArrays) {
4057 ObjectStore* object_store = Isolate::Current()->object_store(); 4057 ObjectStore* object_store = Isolate::Current()->object_store();
4058 Class& cls = Class::Handle(); 4058 Class& cls = Class::Handle();
4059 Object& array = Object::Handle(); 4059 Object& array = Object::Handle();
4060 4060
4061 cls = object_store->null_class(); 4061 cls = object_store->null_class();
4062 array = cls.fields(); 4062 array = cls.fields();
4063 EXPECT(!array.IsNull()); 4063 EXPECT(!array.IsNull());
4064 EXPECT(array.IsArray()); 4064 EXPECT(array.IsArray());
4065 array = cls.functions(); 4065 array = cls.functions();
4066 EXPECT(!array.IsNull()); 4066 EXPECT(!array.IsNull());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4101 handle.IsLiteralToken()) { 4101 handle.IsLiteralToken()) {
4102 return; 4102 return;
4103 } 4103 }
4104 objects_->Add(&handle); 4104 objects_->Add(&handle);
4105 } 4105 }
4106 private: 4106 private:
4107 GrowableArray<Object*>* objects_; 4107 GrowableArray<Object*>* objects_;
4108 }; 4108 };
4109 4109
4110 4110
4111 TEST_CASE(PrintJSON) { 4111 VM_TEST_CASE(PrintJSON) {
4112 Heap* heap = Isolate::Current()->heap(); 4112 Heap* heap = Isolate::Current()->heap();
4113 heap->CollectAllGarbage(); 4113 heap->CollectAllGarbage();
4114 GrowableArray<Object*> objects; 4114 GrowableArray<Object*> objects;
4115 ObjectAccumulator acc(&objects); 4115 ObjectAccumulator acc(&objects);
4116 heap->IterateObjects(&acc); 4116 heap->IterateObjects(&acc);
4117 for (intptr_t i = 0; i < objects.length(); ++i) { 4117 for (intptr_t i = 0; i < objects.length(); ++i) {
4118 JSONStream js; 4118 JSONStream js;
4119 objects[i]->PrintJSON(&js, false); 4119 objects[i]->PrintJSON(&js, false);
4120 EXPECT_SUBSTRING("\"type\":", js.ToCString()); 4120 EXPECT_SUBSTRING("\"type\":", js.ToCString());
4121 } 4121 }
4122 } 4122 }
4123 4123
4124 4124
4125 TEST_CASE(PrintJSONPrimitives) { 4125 VM_TEST_CASE(PrintJSONPrimitives) {
4126 char buffer[1024]; 4126 char buffer[1024];
4127 Isolate* isolate = Isolate::Current(); 4127 Isolate* isolate = Isolate::Current();
4128 4128
4129 // Class reference 4129 // Class reference
4130 { 4130 {
4131 JSONStream js; 4131 JSONStream js;
4132 Class& cls = Class::Handle(isolate->object_store()->bool_class()); 4132 Class& cls = Class::Handle(isolate->object_store()->bool_class());
4133 cls.PrintJSON(&js, true); 4133 cls.PrintJSON(&js, true);
4134 ElideJSONSubstring("classes", js.ToCString(), buffer); 4134 ElideJSONSubstring("classes", js.ToCString(), buffer);
4135 EXPECT_STREQ( 4135 EXPECT_STREQ(
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
4580 for (int i = 0; i < n; i++) { 4580 for (int i = 0; i < n; i++) {
4581 pieces.Add(*data[i]); 4581 pieces.Add(*data[i]);
4582 array.SetAt(i, *data[i]); 4582 array.SetAt(i, *data[i]);
4583 } 4583 }
4584 const String& res1 = String::Handle(zone, Symbols::FromConcatAll(pieces)); 4584 const String& res1 = String::Handle(zone, Symbols::FromConcatAll(pieces));
4585 const String& res2 = String::Handle(zone, String::ConcatAll(array)); 4585 const String& res2 = String::Handle(zone, String::ConcatAll(array));
4586 EXPECT(res1.Equals(res2)); 4586 EXPECT(res1.Equals(res2));
4587 } 4587 }
4588 4588
4589 4589
4590 TEST_CASE(Symbols_FromConcatAll) { 4590 VM_TEST_CASE(Symbols_FromConcatAll) {
4591 { 4591 {
4592 const String* data[3] = { &Symbols::FallThroughError(), 4592 const String* data[3] = { &Symbols::FallThroughError(),
4593 &Symbols::Dot(), 4593 &Symbols::Dot(),
4594 &Symbols::isPaused() }; 4594 &Symbols::isPaused() };
4595 CheckConcatAll(data, 3); 4595 CheckConcatAll(data, 3);
4596 } 4596 }
4597 4597
4598 { 4598 {
4599 const intptr_t kWideCharsLen = 7; 4599 const intptr_t kWideCharsLen = 7;
4600 uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' }; 4600 uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' };
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
4652 } 4652 }
4653 } 4653 }
4654 4654
4655 4655
4656 struct TestResult { 4656 struct TestResult {
4657 const char* in; 4657 const char* in;
4658 const char* out; 4658 const char* out;
4659 }; 4659 };
4660 4660
4661 4661
4662 TEST_CASE(String_IdentifierPrettyName) { 4662 VM_TEST_CASE(String_IdentifierPrettyName) {
4663 TestResult tests[] = { 4663 TestResult tests[] = {
4664 {"(dynamic, dynamic) => void", "(dynamic, dynamic) => void"}, 4664 {"(dynamic, dynamic) => void", "(dynamic, dynamic) => void"},
4665 {"_List@915557746", "_List"}, 4665 {"_List@915557746", "_List"},
4666 {"_HashMap@600006304<K, V>(dynamic) => V", "_HashMap<K, V>(dynamic) => V"}, 4666 {"_HashMap@600006304<K, V>(dynamic) => V", "_HashMap<K, V>(dynamic) => V"},
4667 {"set:foo", "foo="}, 4667 {"set:foo", "foo="},
4668 {"get:foo", "foo"}, 4668 {"get:foo", "foo"},
4669 {"_ReceivePortImpl@709387912", "_ReceivePortImpl"}, 4669 {"_ReceivePortImpl@709387912", "_ReceivePortImpl"},
4670 {"_ReceivePortImpl@709387912._internal@709387912", 4670 {"_ReceivePortImpl@709387912._internal@709387912",
4671 "_ReceivePortImpl._internal"}, 4671 "_ReceivePortImpl._internal"},
4672 {"_C@6328321&_E@6328321&_F@6328321", "_C&_E&_F"}, 4672 {"_C@6328321&_E@6328321&_F@6328321", "_C&_E&_F"},
4673 {"List.", "List"}, 4673 {"List.", "List"},
4674 {"get:foo@6328321", "foo"}, 4674 {"get:foo@6328321", "foo"},
4675 {"_MyClass@6328321.", "_MyClass"}, 4675 {"_MyClass@6328321.", "_MyClass"},
4676 {"_MyClass@6328321.named", "_MyClass.named"}, 4676 {"_MyClass@6328321.named", "_MyClass.named"},
4677 }; 4677 };
4678 String& test = String::Handle(); 4678 String& test = String::Handle();
4679 String& result = String::Handle(); 4679 String& result = String::Handle();
4680 for (size_t i = 0; i < ARRAY_SIZE(tests); i++) { 4680 for (size_t i = 0; i < ARRAY_SIZE(tests); i++) {
4681 test = String::New(tests[i].in); 4681 test = String::New(tests[i].in);
4682 result = String::IdentifierPrettyName(test); 4682 result = String::IdentifierPrettyName(test);
4683 EXPECT_STREQ(tests[i].out, result.ToCString()); 4683 EXPECT_STREQ(tests[i].out, result.ToCString());
4684 } 4684 }
4685 } 4685 }
4686 4686
4687 } // namespace dart 4687 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object_id_ring_test.cc ('k') | runtime/vm/os_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698