OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
(...skipping 4334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4345 "{\"type\":\"@Library\",\"fixedId\":true,\"id\":\"\"," | 4345 "{\"type\":\"@Library\",\"fixedId\":true,\"id\":\"\"," |
4346 "\"name\":\"dart.core\",\"uri\":\"dart:core\"}", | 4346 "\"name\":\"dart.core\",\"uri\":\"dart:core\"}", |
4347 buffer); | 4347 buffer); |
4348 } | 4348 } |
4349 // Bool reference | 4349 // Bool reference |
4350 { | 4350 { |
4351 JSONStream js; | 4351 JSONStream js; |
4352 Bool::True().PrintJSON(&js, true); | 4352 Bool::True().PrintJSON(&js, true); |
4353 elideSubstring("classes", js.ToCString(), buffer); | 4353 elideSubstring("classes", js.ToCString(), buffer); |
4354 EXPECT_STREQ( | 4354 EXPECT_STREQ( |
4355 "{\"type\":\"@bool\"," | 4355 "{\"type\":\"@Instance\"," |
| 4356 "\"_vmType\":\"Bool\"," |
4356 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4357 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4357 "\"name\":\"bool\"},\"fixedId\":true," | 4358 "\"name\":\"bool\"}," |
| 4359 "\"kind\":\"Bool\"," |
| 4360 "\"fixedId\":true," |
4358 "\"id\":\"objects\\/bool-true\",\"valueAsString\":\"true\"}", | 4361 "\"id\":\"objects\\/bool-true\",\"valueAsString\":\"true\"}", |
4359 buffer); | 4362 buffer); |
4360 } | 4363 } |
4361 // Smi reference | 4364 // Smi reference |
4362 { | 4365 { |
4363 JSONStream js; | 4366 JSONStream js; |
4364 const Integer& smi = Integer::Handle(Integer::New(7)); | 4367 const Integer& smi = Integer::Handle(Integer::New(7)); |
4365 smi.PrintJSON(&js, true); | 4368 smi.PrintJSON(&js, true); |
4366 elideSubstring("classes", js.ToCString(), buffer); | 4369 elideSubstring("classes", js.ToCString(), buffer); |
4367 elideSubstring("_Smi@", buffer, buffer); | 4370 elideSubstring("_Smi@", buffer, buffer); |
4368 EXPECT_STREQ( | 4371 EXPECT_STREQ( |
4369 "{\"type\":\"@int\",\"_vmType\":\"@Smi\"," | 4372 "{\"type\":\"@Instance\"," |
| 4373 "\"_vmType\":\"Smi\"," |
4370 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4374 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4371 "\"name\":\"_Smi\"," | 4375 "\"name\":\"_Smi\"," |
4372 "\"_vmName\":\"\"},\"fixedId\":true," | 4376 "\"_vmName\":\"\"}," |
| 4377 "\"kind\":\"Int\"," |
| 4378 "\"fixedId\":true," |
4373 "\"id\":\"objects\\/int-7\",\"valueAsString\":\"7\"}", | 4379 "\"id\":\"objects\\/int-7\",\"valueAsString\":\"7\"}", |
4374 buffer); | 4380 buffer); |
4375 } | 4381 } |
4376 // Mint reference | 4382 // Mint reference |
4377 { | 4383 { |
4378 JSONStream js; | 4384 JSONStream js; |
4379 const Integer& smi = Integer::Handle(Integer::New(Mint::kMinValue)); | 4385 const Integer& smi = Integer::Handle(Integer::New(Mint::kMinValue)); |
4380 smi.PrintJSON(&js, true); | 4386 smi.PrintJSON(&js, true); |
4381 elideSubstring("classes", js.ToCString(), buffer); | 4387 elideSubstring("classes", js.ToCString(), buffer); |
4382 elideSubstring("objects", buffer, buffer); | 4388 elideSubstring("objects", buffer, buffer); |
4383 elideSubstring("_Mint@", buffer, buffer); | 4389 elideSubstring("_Mint@", buffer, buffer); |
4384 EXPECT_STREQ( | 4390 EXPECT_STREQ( |
4385 "{\"type\":\"@int\",\"_vmType\":\"@Mint\"," | 4391 "{\"type\":\"@Instance\"," |
| 4392 "\"_vmType\":\"Mint\"," |
4386 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4393 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4387 "\"name\":\"_Mint\",\"_vmName\":\"\"}," | 4394 "\"name\":\"_Mint\",\"_vmName\":\"\"}," |
| 4395 "\"kind\":\"Int\"," |
4388 "\"id\":\"\",\"valueAsString\":\"-9223372036854775808\"}", | 4396 "\"id\":\"\",\"valueAsString\":\"-9223372036854775808\"}", |
4389 buffer); | 4397 buffer); |
4390 } | 4398 } |
4391 // Bigint reference | 4399 // Bigint reference |
4392 { | 4400 { |
4393 JSONStream js; | 4401 JSONStream js; |
4394 const String& bigint_str = | 4402 const String& bigint_str = |
4395 String::Handle(String::New("44444444444444444444444444444444")); | 4403 String::Handle(String::New("44444444444444444444444444444444")); |
4396 const Integer& bigint = Integer::Handle(Integer::New(bigint_str)); | 4404 const Integer& bigint = Integer::Handle(Integer::New(bigint_str)); |
4397 bigint.PrintJSON(&js, true); | 4405 bigint.PrintJSON(&js, true); |
4398 elideSubstring("classes", js.ToCString(), buffer); | 4406 elideSubstring("classes", js.ToCString(), buffer); |
4399 elideSubstring("objects", buffer, buffer); | 4407 elideSubstring("objects", buffer, buffer); |
4400 elideSubstring("_Bigint@", buffer, buffer); | 4408 elideSubstring("_Bigint@", buffer, buffer); |
4401 EXPECT_STREQ( | 4409 EXPECT_STREQ( |
4402 "{\"type\":\"@int\",\"_vmType\":\"@Bigint\"," | 4410 "{\"type\":\"@Instance\"," |
| 4411 "\"_vmType\":\"Bigint\"," |
4403 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4412 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4404 "\"name\":\"_Bigint\",\"_vmName\":\"\"}," | 4413 "\"name\":\"_Bigint\",\"_vmName\":\"\"}," |
| 4414 "\"kind\":\"Int\"," |
4405 "\"id\":\"\",\"valueAsString\":\"44444444444444444444444444444444\"}", | 4415 "\"id\":\"\",\"valueAsString\":\"44444444444444444444444444444444\"}", |
4406 buffer); | 4416 buffer); |
4407 } | 4417 } |
4408 // Double reference | 4418 // Double reference |
4409 { | 4419 { |
4410 JSONStream js; | 4420 JSONStream js; |
4411 const Double& dub = Double::Handle(Double::New(0.1234)); | 4421 const Double& dub = Double::Handle(Double::New(0.1234)); |
4412 dub.PrintJSON(&js, true); | 4422 dub.PrintJSON(&js, true); |
4413 elideSubstring("classes", js.ToCString(), buffer); | 4423 elideSubstring("classes", js.ToCString(), buffer); |
4414 elideSubstring("objects", buffer, buffer); | 4424 elideSubstring("objects", buffer, buffer); |
4415 elideSubstring("_Double@", buffer, buffer); | 4425 elideSubstring("_Double@", buffer, buffer); |
4416 EXPECT_STREQ( | 4426 EXPECT_STREQ( |
4417 "{\"type\":\"@double\"," | 4427 "{\"type\":\"@Instance\"," |
| 4428 "\"_vmType\":\"Double\"," |
4418 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4429 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4419 "\"name\":\"_Double\",\"_vmName\":\"\"}," | 4430 "\"name\":\"_Double\",\"_vmName\":\"\"}," |
| 4431 "\"kind\":\"Double\"," |
4420 "\"id\":\"\",\"valueAsString\":\"0.1234\"}", | 4432 "\"id\":\"\",\"valueAsString\":\"0.1234\"}", |
4421 buffer); | 4433 buffer); |
4422 } | 4434 } |
4423 // String reference | 4435 // String reference |
4424 { | 4436 { |
4425 JSONStream js; | 4437 JSONStream js; |
4426 const String& str = String::Handle(String::New("dw")); | 4438 const String& str = String::Handle(String::New("dw")); |
4427 str.PrintJSON(&js, true); | 4439 str.PrintJSON(&js, true); |
4428 elideSubstring("classes", js.ToCString(), buffer); | 4440 elideSubstring("classes", js.ToCString(), buffer); |
4429 elideSubstring("objects", buffer, buffer); | 4441 elideSubstring("objects", buffer, buffer); |
4430 elideSubstring("_OneByteString@", buffer, buffer); | 4442 elideSubstring("_OneByteString@", buffer, buffer); |
4431 EXPECT_STREQ( | 4443 EXPECT_STREQ( |
4432 "{\"type\":\"@String\"," | 4444 "{\"type\":\"@Instance\"," |
| 4445 "\"_vmType\":\"String\"," |
4433 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4446 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4434 "\"name\":\"_OneByteString\",\"_vmName\":\"\"}," | 4447 "\"name\":\"_OneByteString\",\"_vmName\":\"\"}," |
| 4448 "\"kind\":\"String\"," |
4435 "\"id\":\"\",\"valueAsString\":\"dw\"}", | 4449 "\"id\":\"\",\"valueAsString\":\"dw\"}", |
4436 buffer); | 4450 buffer); |
4437 } | 4451 } |
4438 // Array reference | 4452 // Array reference |
4439 { | 4453 { |
4440 JSONStream js; | 4454 JSONStream js; |
4441 const Array& array = Array::Handle(Array::New(0)); | 4455 const Array& array = Array::Handle(Array::New(0)); |
4442 array.PrintJSON(&js, true); | 4456 array.PrintJSON(&js, true); |
4443 elideSubstring("classes", js.ToCString(), buffer); | 4457 elideSubstring("classes", js.ToCString(), buffer); |
4444 elideSubstring("objects", buffer, buffer); | 4458 elideSubstring("objects", buffer, buffer); |
4445 elideSubstring("_List@", buffer, buffer); | 4459 elideSubstring("_List@", buffer, buffer); |
4446 EXPECT_STREQ( | 4460 EXPECT_STREQ( |
4447 "{\"type\":\"@List\",\"_vmType\":\"@Array\"," | 4461 "{\"type\":\"@Instance\"," |
| 4462 "\"_vmType\":\"Array\"," |
4448 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4463 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4449 "\"name\":\"_List\",\"_vmName\":\"\"}," | 4464 "\"name\":\"_List\",\"_vmName\":\"\"}," |
| 4465 "\"kind\":\"List\"," |
4450 "\"id\":\"\",\"length\":0}", | 4466 "\"id\":\"\",\"length\":0}", |
4451 buffer); | 4467 buffer); |
4452 } | 4468 } |
4453 // GrowableObjectArray reference | 4469 // GrowableObjectArray reference |
4454 { | 4470 { |
4455 JSONStream js; | 4471 JSONStream js; |
4456 const GrowableObjectArray& array = | 4472 const GrowableObjectArray& array = |
4457 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 4473 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
4458 array.PrintJSON(&js, true); | 4474 array.PrintJSON(&js, true); |
4459 elideSubstring("classes", js.ToCString(), buffer); | 4475 elideSubstring("classes", js.ToCString(), buffer); |
4460 elideSubstring("objects", buffer, buffer); | 4476 elideSubstring("objects", buffer, buffer); |
4461 elideSubstring("_GrowableList@", buffer, buffer); | 4477 elideSubstring("_GrowableList@", buffer, buffer); |
4462 EXPECT_STREQ( | 4478 EXPECT_STREQ( |
4463 "{\"type\":\"@List\",\"_vmType\":\"@GrowableObjectArray\"," | 4479 "{\"type\":\"@Instance\"," |
| 4480 "\"_vmType\":\"GrowableObjectArray\"," |
4464 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4481 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4465 "\"name\":\"_GrowableList\"," | 4482 "\"name\":\"_GrowableList\"," |
4466 "\"_vmName\":\"\"},\"id\":\"\",\"length\":0}", | 4483 "\"_vmName\":\"\"}," |
| 4484 "\"kind\":\"List\"," |
| 4485 "\"id\":\"\",\"length\":0}", |
4467 buffer); | 4486 buffer); |
4468 } | 4487 } |
4469 // LinkedHashMap reference | 4488 // LinkedHashMap reference |
4470 { | 4489 { |
4471 JSONStream js; | 4490 JSONStream js; |
4472 const LinkedHashMap& array = | 4491 const LinkedHashMap& array = |
4473 LinkedHashMap::Handle(LinkedHashMap::NewDefault()); | 4492 LinkedHashMap::Handle(LinkedHashMap::NewDefault()); |
4474 array.PrintJSON(&js, true); | 4493 array.PrintJSON(&js, true); |
4475 elideSubstring("classes", js.ToCString(), buffer); | 4494 elideSubstring("classes", js.ToCString(), buffer); |
4476 elideSubstring("objects", buffer, buffer); | 4495 elideSubstring("objects", buffer, buffer); |
4477 elideSubstring("_InternalLinkedHashMap@", buffer, buffer); | 4496 elideSubstring("_InternalLinkedHashMap@", buffer, buffer); |
4478 EXPECT_STREQ( | 4497 EXPECT_STREQ( |
4479 "{\"type\":\"@Instance\",\"_vmType\":\"@LinkedHashMap\"," | 4498 "{\"type\":\"@Instance\"," |
| 4499 "\"_vmType\":\"LinkedHashMap\"," |
4480 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4500 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4481 "\"name\":\"_InternalLinkedHashMap\",\"_vmName\":\"\"},\"id\":\"\"}", | 4501 "\"name\":\"_InternalLinkedHashMap\",\"_vmName\":\"\"}," |
| 4502 "\"kind\":\"Map\"," |
| 4503 "\"id\":\"\"}", |
4482 buffer); | 4504 buffer); |
4483 } | 4505 } |
4484 // UserTag reference | 4506 // UserTag reference |
4485 { | 4507 { |
4486 JSONStream js; | 4508 JSONStream js; |
4487 Instance& tag = Instance::Handle(isolate->default_tag()); | 4509 Instance& tag = Instance::Handle(isolate->default_tag()); |
4488 tag.PrintJSON(&js, true); | 4510 tag.PrintJSON(&js, true); |
4489 elideSubstring("classes", js.ToCString(), buffer); | 4511 elideSubstring("classes", js.ToCString(), buffer); |
4490 elideSubstring("objects", buffer, buffer); | 4512 elideSubstring("objects", buffer, buffer); |
4491 elideSubstring("_UserTag@", buffer, buffer); | 4513 elideSubstring("_UserTag@", buffer, buffer); |
4492 EXPECT_STREQ( | 4514 EXPECT_STREQ( |
4493 "{\"type\":\"@Instance\",\"_vmType\":\"@UserTag\"," | 4515 "{\"type\":\"@Instance\"," |
| 4516 "\"_vmType\":\"UserTag\"," |
4494 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4517 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4495 "\"name\":\"_UserTag\",\"_vmName\":\"\"}," | 4518 "\"name\":\"_UserTag\",\"_vmName\":\"\"}," |
| 4519 "\"kind\":\"PlainInstance\"," |
4496 "\"id\":\"\"}", | 4520 "\"id\":\"\"}", |
4497 buffer); | 4521 buffer); |
4498 } | 4522 } |
4499 // Type reference | 4523 // Type reference |
4500 // TODO(turnidge): Add in all of the other Type siblings. | 4524 // TODO(turnidge): Add in all of the other Type siblings. |
4501 { | 4525 { |
4502 JSONStream js; | 4526 JSONStream js; |
4503 Instance& type = Instance::Handle(isolate->object_store()->bool_type()); | 4527 Instance& type = Instance::Handle(isolate->object_store()->bool_type()); |
4504 type.PrintJSON(&js, true); | 4528 type.PrintJSON(&js, true); |
4505 elideSubstring("classes", js.ToCString(), buffer); | 4529 elideSubstring("classes", js.ToCString(), buffer); |
4506 elideSubstring("objects", buffer, buffer); | 4530 elideSubstring("objects", buffer, buffer); |
4507 elideSubstring("_Type@", buffer, buffer); | 4531 elideSubstring("_Type@", buffer, buffer); |
4508 EXPECT_STREQ( | 4532 EXPECT_STREQ( |
4509 "{\"type\":\"@Type\"," | 4533 "{\"type\":\"@Instance\"," |
| 4534 "\"_vmType\":\"Type\"," |
4510 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4535 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4511 "\"name\":\"_Type\",\"_vmName\":\"\"},\"fixedId\":true,\"id\":\"\"," | 4536 "\"name\":\"_Type\",\"_vmName\":\"\"}," |
| 4537 "\"kind\":\"Type\"," |
| 4538 "\"fixedId\":true,\"id\":\"\"," |
4512 "\"typeClass\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4539 "\"typeClass\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4513 "\"name\":\"bool\"},\"name\":\"bool\"}", | 4540 "\"name\":\"bool\"},\"name\":\"bool\"}", |
4514 buffer); | 4541 buffer); |
4515 } | 4542 } |
4516 // Null reference | 4543 // Null reference |
4517 { | 4544 { |
4518 JSONStream js; | 4545 JSONStream js; |
4519 Object::null_object().PrintJSON(&js, true); | 4546 Object::null_object().PrintJSON(&js, true); |
4520 EXPECT_STREQ( | 4547 EXPECT_STREQ( |
4521 "{\"type\":\"@null\",\"fixedId\":true," | 4548 "{\"type\":\"@Instance\"," |
| 4549 "\"_vmType\":\"null\"," |
| 4550 "\"kind\":\"Null\"," |
| 4551 "\"fixedId\":true," |
4522 "\"id\":\"objects\\/null\"," | 4552 "\"id\":\"objects\\/null\"," |
4523 "\"valueAsString\":\"null\"}", | 4553 "\"valueAsString\":\"null\"}", |
4524 js.ToCString()); | 4554 js.ToCString()); |
4525 } | 4555 } |
4526 // Sentinel reference | 4556 // Sentinel reference |
4527 { | 4557 { |
4528 JSONStream js; | 4558 JSONStream js; |
4529 Object::sentinel().PrintJSON(&js, true); | 4559 Object::sentinel().PrintJSON(&js, true); |
4530 EXPECT_STREQ( | 4560 EXPECT_STREQ( |
4531 "{\"type\":\"Sentinel\"," | 4561 "{\"type\":\"Sentinel\"," |
(...skipping 13 matching lines...) Expand all Loading... |
4545 } | 4575 } |
4546 // LiteralToken reference. This is meant to be an example of a | 4576 // LiteralToken reference. This is meant to be an example of a |
4547 // "weird" type that isn't usually returned by the VM Service except | 4577 // "weird" type that isn't usually returned by the VM Service except |
4548 // when we are doing direct heap inspection. | 4578 // when we are doing direct heap inspection. |
4549 { | 4579 { |
4550 JSONStream js; | 4580 JSONStream js; |
4551 LiteralToken& tok = LiteralToken::Handle(LiteralToken::New()); | 4581 LiteralToken& tok = LiteralToken::Handle(LiteralToken::New()); |
4552 tok.PrintJSON(&js, true); | 4582 tok.PrintJSON(&js, true); |
4553 elideSubstring("objects", js.ToCString(), buffer); | 4583 elideSubstring("objects", js.ToCString(), buffer); |
4554 EXPECT_STREQ( | 4584 EXPECT_STREQ( |
4555 "{\"type\":\"@Object\",\"_vmType\":\"@LiteralToken\",\"id\":\"\"}", | 4585 "{\"type\":\"@Object\",\"_vmType\":\"LiteralToken\",\"id\":\"\"}", |
4556 buffer); | 4586 buffer); |
4557 } | 4587 } |
4558 } | 4588 } |
4559 | 4589 |
4560 | 4590 |
4561 TEST_CASE(InstanceEquality) { | 4591 TEST_CASE(InstanceEquality) { |
4562 // Test that Instance::OperatorEquals can call a user-defined operator==. | 4592 // Test that Instance::OperatorEquals can call a user-defined operator==. |
4563 const char* kScript = | 4593 const char* kScript = |
4564 "class A {\n" | 4594 "class A {\n" |
4565 " bool operator==(A other) { return true; }\n" | 4595 " bool operator==(A other) { return true; }\n" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4670 // 2. Create an empty internalized LinkedHashMap in C++. | 4700 // 2. Create an empty internalized LinkedHashMap in C++. |
4671 Instance& dart_map = Instance::Handle(); | 4701 Instance& dart_map = Instance::Handle(); |
4672 dart_map ^= Api::UnwrapHandle(h_result); | 4702 dart_map ^= Api::UnwrapHandle(h_result); |
4673 LinkedHashMap& cc_map = LinkedHashMap::Handle(LinkedHashMap::NewDefault()); | 4703 LinkedHashMap& cc_map = LinkedHashMap::Handle(LinkedHashMap::NewDefault()); |
4674 | 4704 |
4675 // 3. Expect them to have identical structure. | 4705 // 3. Expect them to have identical structure. |
4676 CheckIdenticalHashStructure(dart_map, cc_map); | 4706 CheckIdenticalHashStructure(dart_map, cc_map); |
4677 } | 4707 } |
4678 | 4708 |
4679 } // namespace dart | 4709 } // namespace dart |
OLD | NEW |