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 "include/dart_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.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_api_message.h" | 10 #include "vm/dart_api_message.h" |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 writer.FinalizeBuffer(); | 407 writer.FinalizeBuffer(); |
408 | 408 |
409 // Create a snapshot object using the buffer. | 409 // Create a snapshot object using the buffer. |
410 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 410 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
411 | 411 |
412 // Read object back from the snapshot. | 412 // Read object back from the snapshot. |
413 SnapshotReader reader(snapshot, Isolate::Current()); | 413 SnapshotReader reader(snapshot, Isolate::Current()); |
414 Bigint& obj = Bigint::Handle(); | 414 Bigint& obj = Bigint::Handle(); |
415 obj ^= reader.ReadObject(); | 415 obj ^= reader.ReadObject(); |
416 | 416 |
417 EXPECT_EQ(BigintOperations::ToInt64(bigint), BigintOperations::ToInt64(obj)); | 417 EXPECT_EQ(BigintOperations::ToMint(bigint), BigintOperations::ToMint(obj)); |
418 | 418 |
419 // Read object back from the snapshot into a C structure. | 419 // Read object back from the snapshot into a C structure. |
420 ApiNativeScope scope; | 420 ApiNativeScope scope; |
421 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize, | 421 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize, |
422 writer.BytesWritten(), | 422 writer.BytesWritten(), |
423 &zone_allocator); | 423 &zone_allocator); |
424 // Bigint not supported. | 424 // Bigint not supported. |
425 EXPECT_NOTNULL(root); | 425 EXPECT_NOTNULL(root); |
426 EXPECT_EQ(Dart_CObject::kBigint, root->type); | 426 EXPECT_EQ(Dart_CObject::kBigint, root->type); |
427 EXPECT_STREQ("FFFFFFFFF", root->value.as_bigint); | 427 EXPECT_STREQ("FFFFFFFFF", root->value.as_bigint); |
428 CheckEncodeDecodeMessage(root); | 428 CheckEncodeDecodeMessage(root); |
429 } | 429 } |
430 | 430 |
431 | 431 |
432 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { | 432 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { |
433 // Write snapshot with object content. | 433 // Write snapshot with object content. |
434 uint8_t* buffer; | 434 uint8_t* buffer; |
435 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator); | 435 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator); |
436 writer.WriteObject(bigint.raw()); | 436 writer.WriteObject(bigint.raw()); |
437 writer.FinalizeBuffer(); | 437 writer.FinalizeBuffer(); |
438 | 438 |
439 // Create a snapshot object using the buffer. | 439 // Create a snapshot object using the buffer. |
440 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 440 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
441 | 441 |
442 // Read object back from the snapshot. | 442 // Read object back from the snapshot. |
443 SnapshotReader reader(snapshot, Isolate::Current()); | 443 SnapshotReader reader(snapshot, Isolate::Current()); |
444 Bigint& serialized_bigint = Bigint::Handle(); | 444 Bigint& serialized_bigint = Bigint::Handle(); |
445 serialized_bigint ^= reader.ReadObject(); | 445 serialized_bigint ^= reader.ReadObject(); |
446 const char *str1 = BigintOperations::ToDecCString(bigint, allocator); | 446 const char *str1 = BigintOperations::ToHexCString(bigint, allocator); |
447 const char *str2 = | 447 const char *str2 = |
448 BigintOperations::ToDecCString(serialized_bigint, allocator); | 448 BigintOperations::ToHexCString(serialized_bigint, allocator); |
449 EXPECT_STREQ(str1, str2); | 449 EXPECT_STREQ(str1, str2); |
450 free(const_cast<char*>(str1)); | 450 free(const_cast<char*>(str1)); |
451 free(const_cast<char*>(str2)); | 451 free(const_cast<char*>(str2)); |
452 | 452 |
453 // Read object back from the snapshot into a C structure. | 453 // Read object back from the snapshot into a C structure. |
454 ApiNativeScope scope; | 454 ApiNativeScope scope; |
455 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize, | 455 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize, |
456 writer.BytesWritten(), | 456 writer.BytesWritten(), |
457 &zone_allocator); | 457 &zone_allocator); |
458 // Bigint not supported. | 458 // Bigint not supported. |
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 EXPECT(Dart_ErrorHasException(result)); | 1559 EXPECT(Dart_ErrorHasException(result)); |
1560 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", | 1560 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", |
1561 Dart_GetError(result)); | 1561 Dart_GetError(result)); |
1562 | 1562 |
1563 Dart_ExitScope(); | 1563 Dart_ExitScope(); |
1564 } | 1564 } |
1565 | 1565 |
1566 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 1566 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
1567 | 1567 |
1568 } // namespace dart | 1568 } // namespace dart |
OLD | NEW |