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

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

Issue 9347040: Add API function Dart_ZoneAllocate (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from iposva@ Created 8 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 | Annotate | Revision Log
« runtime/vm/dart_api_state.h ('K') | « runtime/vm/dart_api_state.h ('k') | no next file » | 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 "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 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 1466
1467 UNIT_TEST_CASE(PostCObject) { 1467 UNIT_TEST_CASE(PostCObject) {
1468 // Create a native port for posting from C to Dart 1468 // Create a native port for posting from C to Dart
1469 TestIsolateScope __test_isolate__; 1469 TestIsolateScope __test_isolate__;
1470 const char* kScriptChars = 1470 const char* kScriptChars =
1471 "void main() {\n" 1471 "void main() {\n"
1472 " var messageCount = 0;\n" 1472 " var messageCount = 0;\n"
1473 " var exception = '';\n" 1473 " var exception = '';\n"
1474 " var port = new ReceivePort();\n" 1474 " var port = new ReceivePort();\n"
1475 " port.receive((message, replyTo) {\n" 1475 " port.receive((message, replyTo) {\n"
1476 " exception += message.toString();\n" 1476 " if (messageCount < 7) {\n"
1477 " exception += message.toString();\n"
1478 " } else {\n"
1479 " exception += message.length;\n"
1480 " for (int i = 0; i < message.length; i++) {\n"
1481 " exception += message[i];\n"
1482 " }\n"
1483 " }\n"
1477 " messageCount++;\n" 1484 " messageCount++;\n"
1478 " if (messageCount == 7) throw new Exception(exception);\n" 1485 " if (messageCount == 8) throw new Exception(exception);\n"
1479 " });\n" 1486 " });\n"
1480 " return port.toSendPort();\n" 1487 " return port.toSendPort();\n"
1481 "}\n"; 1488 "}\n";
1482 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1489 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1483 Dart_EnterScope(); 1490 Dart_EnterScope();
1484 1491
1485 // xxx 1492 // xxx
1486 Dart_Handle send_port = Dart_InvokeStatic(lib, 1493 Dart_Handle send_port = Dart_InvokeStatic(lib,
1487 Dart_NewString(""), 1494 Dart_NewString(""),
1488 Dart_NewString("main"), 1495 Dart_NewString("main"),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 EXPECT(Dart_PostCObject(send_port_id, &object)); 1527 EXPECT(Dart_PostCObject(send_port_id, &object));
1521 1528
1522 object.type = Dart_CObject::kDouble; 1529 object.type = Dart_CObject::kDouble;
1523 object.value.as_double = 3.14; 1530 object.value.as_double = 3.14;
1524 EXPECT(Dart_PostCObject(send_port_id, &object)); 1531 EXPECT(Dart_PostCObject(send_port_id, &object));
1525 1532
1526 object.type = Dart_CObject::kArray; 1533 object.type = Dart_CObject::kArray;
1527 object.value.as_array.length = 0; 1534 object.value.as_array.length = 0;
1528 EXPECT(Dart_PostCObject(send_port_id, &object)); 1535 EXPECT(Dart_PostCObject(send_port_id, &object));
1529 1536
1537 static const int kArrayLength = 10;
1538 Dart_CObject* array =
1539 reinterpret_cast<Dart_CObject*>(
1540 Dart_ZoneAllocate(
1541 sizeof(Dart_CObject) + sizeof(Dart_CObject*) * kArrayLength)); // NOLINT
1542 array->type = Dart_CObject::Dart_CObject::kArray;
1543 array->value.as_array.length = kArrayLength;
1544 array->value.as_array.values =
1545 reinterpret_cast<Dart_CObject**>(array + 1);
1546 for (int i = 0; i < kArrayLength; i++) {
1547 Dart_CObject* element =
1548 reinterpret_cast<Dart_CObject*>(
1549 Dart_ZoneAllocate(sizeof(Dart_CObject)));
1550 element->type = Dart_CObject::kInt32;
1551 element->value.as_int32 = i;
1552 array->value.as_array.values[i] = element;
1553 }
1554 EXPECT(Dart_PostCObject(send_port_id, array));
1555
1530 result = Dart_RunLoop(); 1556 result = Dart_RunLoop();
1531 EXPECT(Dart_IsError(result)); 1557 EXPECT(Dart_IsError(result));
1532 EXPECT(Dart_ErrorHasException(result)); 1558 EXPECT(Dart_ErrorHasException(result));
1533 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]\n", 1559 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n",
1534 Dart_GetError(result)); 1560 Dart_GetError(result));
1535 1561
1536 Dart_ExitScope(); 1562 Dart_ExitScope();
1537 } 1563 }
1538 1564
1539 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 1565 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
1540 1566
1541 } // namespace dart 1567 } // namespace dart
OLDNEW
« runtime/vm/dart_api_state.h ('K') | « runtime/vm/dart_api_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698