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

Side by Side Diff: vm/snapshot_test.cc

Issue 10021072: Remove the deprecated method invocation and field access apis from the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 8 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
« no previous file with comments | « vm/object.cc ('k') | vm/stack_frame_test.cc » ('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 "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 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 // from the script. 819 // from the script.
820 Timer timer2(true, "Snapshot_test"); 820 Timer timer2(true, "Snapshot_test");
821 timer2.Start(); 821 timer2.Start();
822 TestCase::CreateTestIsolateFromSnapshot(buffer); 822 TestCase::CreateTestIsolateFromSnapshot(buffer);
823 { 823 {
824 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 824 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
825 timer2.Stop(); 825 timer2.Stop();
826 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime()); 826 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime());
827 827
828 // Invoke a function which returns an object. 828 // Invoke a function which returns an object.
829 result = Dart_InvokeStatic(TestCase::lib(), 829 Dart_Handle cls =
830 Dart_NewString("FieldsTest"), 830 Dart_GetClass(TestCase::lib(), Dart_NewString("FieldsTest"));
831 Dart_NewString("testMain"), 831 result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL);
832 0,
833 NULL);
834 EXPECT_VALID(result); 832 EXPECT_VALID(result);
835 Dart_ExitScope(); 833 Dart_ExitScope();
836 } 834 }
837 Dart_ShutdownIsolate(); 835 Dart_ShutdownIsolate();
838 free(buffer); 836 free(buffer);
839 } 837 }
840 838
841 839
842 UNIT_TEST_CASE(FullSnapshot1) { 840 UNIT_TEST_CASE(FullSnapshot1) {
843 // This buffer has to be static for this to compile with Visual Studio. 841 // This buffer has to be static for this to compile with Visual Studio.
(...skipping 20 matching lines...) Expand all
864 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 862 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
865 ClassFinalizer::FinalizePendingClasses(); 863 ClassFinalizer::FinalizePendingClasses();
866 timer1.Stop(); 864 timer1.Stop();
867 OS::PrintErr("Without Snapshot: %dus\n", timer1.TotalElapsedTime()); 865 OS::PrintErr("Without Snapshot: %dus\n", timer1.TotalElapsedTime());
868 866
869 // Write snapshot with object content. 867 // Write snapshot with object content.
870 SnapshotWriter writer(Snapshot::kFull, &buffer, &malloc_allocator); 868 SnapshotWriter writer(Snapshot::kFull, &buffer, &malloc_allocator);
871 writer.WriteFullSnapshot(); 869 writer.WriteFullSnapshot();
872 870
873 // Invoke a function which returns an object. 871 // Invoke a function which returns an object.
874 Dart_Handle result = Dart_InvokeStatic(lib, 872 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("FieldsTest"));
875 Dart_NewString("FieldsTest"), 873 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL);
876 Dart_NewString("testMain"),
877 0,
878 NULL);
879 EXPECT_VALID(result); 874 EXPECT_VALID(result);
880 } 875 }
881 876
882 // Now Create another isolate using the snapshot and execute a method 877 // Now Create another isolate using the snapshot and execute a method
883 // from the script. 878 // from the script.
884 Timer timer2(true, "Snapshot_test"); 879 Timer timer2(true, "Snapshot_test");
885 timer2.Start(); 880 timer2.Start();
886 TestCase::CreateTestIsolateFromSnapshot(buffer); 881 TestCase::CreateTestIsolateFromSnapshot(buffer);
887 { 882 {
888 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 883 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
889 timer2.Stop(); 884 timer2.Stop();
890 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime()); 885 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime());
891 886
892 // Invoke a function which returns an object. 887 // Invoke a function which returns an object.
893 Dart_Handle result = Dart_InvokeStatic(TestCase::lib(), 888 Dart_Handle cls = Dart_GetClass(TestCase::lib(),
894 Dart_NewString("FieldsTest"), 889 Dart_NewString("FieldsTest"));
895 Dart_NewString("testMain"), 890 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL);
896 0,
897 NULL);
898 if (Dart_IsError(result)) { 891 if (Dart_IsError(result)) {
899 // Print the error. It is probably an unhandled exception. 892 // Print the error. It is probably an unhandled exception.
900 fprintf(stderr, "%s\n", Dart_GetError(result)); 893 fprintf(stderr, "%s\n", Dart_GetError(result));
901 } 894 }
902 EXPECT_VALID(result); 895 EXPECT_VALID(result);
903 Dart_ExitScope(); 896 Dart_ExitScope();
904 } 897 }
905 Dart_ShutdownIsolate(); 898 Dart_ShutdownIsolate();
906 free(buffer); 899 free(buffer);
907 } 900 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 EXPECT_VALID(result); 1004 EXPECT_VALID(result);
1012 1005
1013 // Get list of library URLs loaded and compare with expected count. 1006 // Get list of library URLs loaded and compare with expected count.
1014 Dart_Handle libs = Dart_GetLibraryURLs(); 1007 Dart_Handle libs = Dart_GetLibraryURLs();
1015 EXPECT(Dart_IsList(libs)); 1008 EXPECT(Dart_IsList(libs));
1016 Dart_ListLength(libs, &actual_num_libs); 1009 Dart_ListLength(libs, &actual_num_libs);
1017 1010
1018 EXPECT_EQ(expected_num_libs, actual_num_libs); 1011 EXPECT_EQ(expected_num_libs, actual_num_libs);
1019 1012
1020 // Invoke a function which returns an object. 1013 // Invoke a function which returns an object.
1021 result = Dart_InvokeStatic(result, 1014 Dart_Handle cls = Dart_GetClass(result, Dart_NewString("FieldsTest"));
1022 Dart_NewString("FieldsTest"), 1015 result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL);
1023 Dart_NewString("testMain"),
1024 0,
1025 NULL);
1026 EXPECT_VALID(result); 1016 EXPECT_VALID(result);
1027 Dart_ExitScope(); 1017 Dart_ExitScope();
1028 } 1018 }
1029 Dart_ShutdownIsolate(); 1019 Dart_ShutdownIsolate();
1030 free(full_snapshot); 1020 free(full_snapshot);
1031 free(script_snapshot); 1021 free(script_snapshot);
1032 } 1022 }
1033 1023
1034 1024
1035 TEST_CASE(IntArrayMessage) { 1025 TEST_CASE(IntArrayMessage) {
(...skipping 20 matching lines...) Expand all
1056 } 1046 }
1057 CheckEncodeDecodeMessage(root); 1047 CheckEncodeDecodeMessage(root);
1058 } 1048 }
1059 1049
1060 1050
1061 // Helper function to call a top level Dart function, serialize the 1051 // Helper function to call a top level Dart function, serialize the
1062 // result and deserialize the result into a Dart_CObject structure. 1052 // result and deserialize the result into a Dart_CObject structure.
1063 static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib, 1053 static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib,
1064 const char* dart_function) { 1054 const char* dart_function) {
1065 Dart_Handle result; 1055 Dart_Handle result;
1066 result = Dart_InvokeStatic(lib, 1056 result = Dart_Invoke(lib, Dart_NewString(dart_function), 0, NULL);
1067 Dart_NewString(""),
1068 Dart_NewString(dart_function),
1069 0,
1070 NULL);
1071 EXPECT_VALID(result); 1057 EXPECT_VALID(result);
1072 1058
1073 // Serialize the list into a message. 1059 // Serialize the list into a message.
1074 uint8_t* buffer; 1060 uint8_t* buffer;
1075 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator); 1061 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator);
1076 const Object& list = Object::Handle(Api::UnwrapHandle(result)); 1062 const Object& list = Object::Handle(Api::UnwrapHandle(result));
1077 writer.WriteObject(list.raw()); 1063 writer.WriteObject(list.raw());
1078 writer.FinalizeBuffer(); 1064 writer.FinalizeBuffer();
1079 1065
1080 // Read object back from the snapshot into a C structure. 1066 // Read object back from the snapshot into a C structure.
(...skipping 20 matching lines...) Expand all
1101 1087
1102 TestCase::CreateTestIsolate(); 1088 TestCase::CreateTestIsolate();
1103 Isolate* isolate = Isolate::Current(); 1089 Isolate* isolate = Isolate::Current();
1104 EXPECT(isolate != NULL); 1090 EXPECT(isolate != NULL);
1105 Dart_EnterScope(); 1091 Dart_EnterScope();
1106 1092
1107 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, 1093 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars,
1108 NULL); 1094 NULL);
1109 EXPECT_VALID(lib); 1095 EXPECT_VALID(lib);
1110 Dart_Handle smi_result; 1096 Dart_Handle smi_result;
1111 smi_result = Dart_InvokeStatic(lib, 1097 smi_result = Dart_Invoke(lib, Dart_NewString("getSmi"), 0, NULL);
1112 Dart_NewString(""),
1113 Dart_NewString("getSmi"),
1114 0,
1115 NULL);
1116 EXPECT_VALID(smi_result); 1098 EXPECT_VALID(smi_result);
1117 Dart_Handle bigint_result; 1099 Dart_Handle bigint_result;
1118 bigint_result = Dart_InvokeStatic(lib, 1100 bigint_result = Dart_Invoke(lib, Dart_NewString("getBigint"), 0, NULL);
1119 Dart_NewString(""),
1120 Dart_NewString("getBigint"),
1121 0,
1122 NULL);
1123 EXPECT_VALID(bigint_result); 1101 EXPECT_VALID(bigint_result);
1124 Dart_Handle string_result; 1102 Dart_Handle string_result;
1125 string_result = Dart_InvokeStatic(lib, 1103 string_result = Dart_Invoke(lib, Dart_NewString("getString"), 0, NULL);
1126 Dart_NewString(""),
1127 Dart_NewString("getString"),
1128 0,
1129 NULL);
1130 EXPECT_VALID(string_result); 1104 EXPECT_VALID(string_result);
1131 EXPECT(Dart_IsString(string_result)); 1105 EXPECT(Dart_IsString(string_result));
1132 1106
1133 { 1107 {
1134 DARTSCOPE_NOCHECKS(isolate); 1108 DARTSCOPE_NOCHECKS(isolate);
1135 1109
1136 { 1110 {
1137 Zone zone(Isolate::Current()); 1111 Zone zone(Isolate::Current());
1138 uint8_t* buffer; 1112 uint8_t* buffer;
1139 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator); 1113 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator);
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 " }\n" 1462 " }\n"
1489 " messageCount++;\n" 1463 " messageCount++;\n"
1490 " if (messageCount == 8) throw new Exception(exception);\n" 1464 " if (messageCount == 8) throw new Exception(exception);\n"
1491 " });\n" 1465 " });\n"
1492 " return port.toSendPort();\n" 1466 " return port.toSendPort();\n"
1493 "}\n"; 1467 "}\n";
1494 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1468 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1495 Dart_EnterScope(); 1469 Dart_EnterScope();
1496 1470
1497 // xxx 1471 // xxx
1498 Dart_Handle send_port = Dart_InvokeStatic(lib, 1472 Dart_Handle send_port = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL);
1499 Dart_NewString(""),
1500 Dart_NewString("main"),
1501 0,
1502 NULL);
1503 EXPECT_VALID(send_port); 1473 EXPECT_VALID(send_port);
1504 Dart_Handle result = Dart_GetField(send_port, Dart_NewString("_id")); 1474 Dart_Handle result = Dart_GetField(send_port, Dart_NewString("_id"));
1505 ASSERT(!Dart_IsError(result)); 1475 ASSERT(!Dart_IsError(result));
1506 ASSERT(Dart_IsInteger(result)); 1476 ASSERT(Dart_IsInteger(result));
1507 int64_t send_port_id; 1477 int64_t send_port_id;
1508 Dart_Handle result2 = Dart_IntegerToInt64(result, &send_port_id); 1478 Dart_Handle result2 = Dart_IntegerToInt64(result, &send_port_id);
1509 ASSERT(!Dart_IsError(result2)); 1479 ASSERT(!Dart_IsError(result2));
1510 1480
1511 // Setup single object message. 1481 // Setup single object message.
1512 Dart_CObject object; 1482 Dart_CObject object;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 EXPECT(Dart_ErrorHasException(result)); 1532 EXPECT(Dart_ErrorHasException(result));
1563 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", 1533 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n",
1564 Dart_GetError(result)); 1534 Dart_GetError(result));
1565 1535
1566 Dart_ExitScope(); 1536 Dart_ExitScope();
1567 } 1537 }
1568 1538
1569 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 1539 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
1570 1540
1571 } // namespace dart 1541 } // namespace dart
OLDNEW
« no previous file with comments | « vm/object.cc ('k') | vm/stack_frame_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698