| 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 return reinterpret_cast<uword>(malloc(size)); | 366 return reinterpret_cast<uword>(malloc(size)); |
| 367 } | 367 } |
| 368 | 368 |
| 369 | 369 |
| 370 TEST_CASE(SerializeBigint) { | 370 TEST_CASE(SerializeBigint) { |
| 371 StackZone zone(Isolate::Current()); | 371 StackZone zone(Isolate::Current()); |
| 372 | 372 |
| 373 // Write snapshot with object content. | 373 // Write snapshot with object content. |
| 374 uint8_t* buffer; | 374 uint8_t* buffer; |
| 375 MessageWriter writer(&buffer, &zone_allocator); | 375 MessageWriter writer(&buffer, &zone_allocator); |
| 376 const Bigint& bigint = Bigint::Handle(Bigint::New(DART_INT64_C(0xfffffffff))); | 376 const char* cstr = "0x270FFFFFFFFFFFFFD8F0"; |
| 377 const String& str = String::Handle(String::New(cstr)); |
| 378 const Bigint& bigint = Bigint::Handle(Bigint::New(str)); |
| 377 writer.WriteMessage(bigint); | 379 writer.WriteMessage(bigint); |
| 378 intptr_t buffer_len = writer.BytesWritten(); | 380 intptr_t buffer_len = writer.BytesWritten(); |
| 379 | 381 |
| 380 // Read object back from the snapshot. | 382 // Read object back from the snapshot. |
| 381 SnapshotReader reader(buffer, buffer_len, | 383 SnapshotReader reader(buffer, buffer_len, |
| 382 Snapshot::kMessage, Isolate::Current()); | 384 Snapshot::kMessage, Isolate::Current()); |
| 383 Bigint& obj = Bigint::Handle(); | 385 Bigint& obj = Bigint::Handle(); |
| 384 obj ^= reader.ReadObject(); | 386 obj ^= reader.ReadObject(); |
| 385 | 387 |
| 386 EXPECT_EQ(BigintOperations::ToMint(bigint), BigintOperations::ToMint(obj)); | 388 EXPECT_STREQ(BigintOperations::ToHexCString(bigint, &allocator), |
| 389 BigintOperations::ToHexCString(obj, &allocator)); |
| 387 | 390 |
| 388 // Read object back from the snapshot into a C structure. | 391 // Read object back from the snapshot into a C structure. |
| 389 ApiNativeScope scope; | 392 ApiNativeScope scope; |
| 390 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 393 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
| 391 Dart_CObject* root = api_reader.ReadMessage(); | 394 Dart_CObject* root = api_reader.ReadMessage(); |
| 392 // Bigint not supported. | 395 // Bigint not supported. |
| 393 EXPECT_NOTNULL(root); | 396 EXPECT_NOTNULL(root); |
| 394 EXPECT_EQ(Dart_CObject::kBigint, root->type); | 397 EXPECT_EQ(Dart_CObject::kBigint, root->type); |
| 395 EXPECT_STREQ("FFFFFFFFF", root->value.as_bigint); | 398 EXPECT_STREQ("270FFFFFFFFFFFFFD8F0", root->value.as_bigint); |
| 396 CheckEncodeDecodeMessage(root); | 399 CheckEncodeDecodeMessage(root); |
| 397 } | 400 } |
| 398 | 401 |
| 399 | 402 |
| 400 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { | 403 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { |
| 401 // Write snapshot with object content. | 404 // Write snapshot with object content. |
| 402 uint8_t* buffer; | 405 uint8_t* buffer; |
| 403 MessageWriter writer(&buffer, &zone_allocator); | 406 MessageWriter writer(&buffer, &zone_allocator); |
| 404 writer.WriteMessage(bigint); | 407 writer.WriteMessage(bigint); |
| 405 intptr_t buffer_len = writer.BytesWritten(); | 408 intptr_t buffer_len = writer.BytesWritten(); |
| (...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2144 EXPECT(Dart_ErrorHasException(result)); | 2147 EXPECT(Dart_ErrorHasException(result)); |
| 2145 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", | 2148 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", |
| 2146 Dart_GetError(result)); | 2149 Dart_GetError(result)); |
| 2147 | 2150 |
| 2148 Dart_ExitScope(); | 2151 Dart_ExitScope(); |
| 2149 } | 2152 } |
| 2150 | 2153 |
| 2151 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 2154 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 2152 | 2155 |
| 2153 } // namespace dart | 2156 } // namespace dart |
| OLD | NEW |