| 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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
| 6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
| 7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 #include "include/dart_tools_api.h" | 9 #include "include/dart_tools_api.h" |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| 11 #include "platform/text_buffer.h" | 11 #include "platform/text_buffer.h" |
| 12 #include "platform/utils.h" | 12 #include "platform/utils.h" |
| 13 #include "vm/class_finalizer.h" | 13 #include "vm/class_finalizer.h" |
| 14 #include "vm/dart_api_impl.h" | 14 #include "vm/dart_api_impl.h" |
| 15 #include "vm/dart_api_state.h" | 15 #include "vm/dart_api_state.h" |
| 16 #include "vm/lockers.h" | 16 #include "vm/lockers.h" |
| 17 #include "vm/unit_test.h" | 17 #include "vm/unit_test.h" |
| 18 #include "vm/verifier.h" | 18 #include "vm/verifier.h" |
| 19 | 19 |
| 20 namespace dart { | 20 namespace dart { |
| 21 | 21 |
| 22 DECLARE_FLAG(int, optimization_counter_threshold); | 22 DECLARE_FLAG(int, optimization_counter_threshold); |
| 23 DECLARE_FLAG(bool, verify_acquired_data); | 23 DECLARE_FLAG(bool, verify_acquired_data); |
| 24 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); | 24 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); |
| 25 | 25 |
| 26 #ifndef PRODUCT |
| 27 |
| 26 TEST_CASE(ErrorHandleBasics) { | 28 TEST_CASE(ErrorHandleBasics) { |
| 27 const char* kScriptChars = | 29 const char* kScriptChars = |
| 28 "void testMain() {\n" | 30 "void testMain() {\n" |
| 29 " throw new Exception(\"bad news\");\n" | 31 " throw new Exception(\"bad news\");\n" |
| 30 "}\n"; | 32 "}\n"; |
| 31 | 33 |
| 32 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 34 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 33 | 35 |
| 34 Dart_Handle instance = Dart_True(); | 36 Dart_Handle instance = Dart_True(); |
| 35 Dart_Handle error = Api::NewError("myerror"); | 37 Dart_Handle error = Api::NewError("myerror"); |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 &CurrentStackTraceNativeLookup); | 391 &CurrentStackTraceNativeLookup); |
| 390 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 392 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 391 EXPECT_VALID(result); | 393 EXPECT_VALID(result); |
| 392 EXPECT(Dart_IsInteger(result)); | 394 EXPECT(Dart_IsInteger(result)); |
| 393 int64_t value = 0; | 395 int64_t value = 0; |
| 394 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 396 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 395 EXPECT_EQ(42, value); | 397 EXPECT_EQ(42, value); |
| 396 } | 398 } |
| 397 | 399 |
| 398 | 400 |
| 401 #endif // !PRODUCT |
| 402 |
| 403 |
| 399 TEST_CASE(ErrorHandleTypes) { | 404 TEST_CASE(ErrorHandleTypes) { |
| 400 const String& compile_message = String::Handle(String::New("CompileError")); | 405 const String& compile_message = String::Handle(String::New("CompileError")); |
| 401 const String& fatal_message = String::Handle(String::New("FatalError")); | 406 const String& fatal_message = String::Handle(String::New("FatalError")); |
| 402 | 407 |
| 403 Dart_Handle not_error = NewString("NotError"); | 408 Dart_Handle not_error = NewString("NotError"); |
| 404 Dart_Handle api_error = Api::NewError("Api%s", "Error"); | 409 Dart_Handle api_error = Api::NewError("Api%s", "Error"); |
| 405 Dart_Handle exception_error = | 410 Dart_Handle exception_error = |
| 406 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); | 411 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); |
| 407 Dart_Handle compile_error = | 412 Dart_Handle compile_error = |
| 408 Api::NewHandle(thread, LanguageError::New(compile_message)); | 413 Api::NewHandle(thread, LanguageError::New(compile_message)); |
| (...skipping 5611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6020 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 6025 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| 6021 | 6026 |
| 6022 result = Dart_LibraryName(lib); | 6027 result = Dart_LibraryName(lib); |
| 6023 EXPECT_VALID(result); | 6028 EXPECT_VALID(result); |
| 6024 EXPECT(Dart_IsString(result)); | 6029 EXPECT(Dart_IsString(result)); |
| 6025 const char* cstr = NULL; | 6030 const char* cstr = NULL; |
| 6026 EXPECT_VALID(Dart_StringToCString(result, &cstr)); | 6031 EXPECT_VALID(Dart_StringToCString(result, &cstr)); |
| 6027 EXPECT_STREQ("library1_name", cstr); | 6032 EXPECT_STREQ("library1_name", cstr); |
| 6028 } | 6033 } |
| 6029 | 6034 |
| 6035 |
| 6036 #ifndef PRODUCT |
| 6037 |
| 6038 |
| 6030 TEST_CASE(LibraryId) { | 6039 TEST_CASE(LibraryId) { |
| 6031 const char* kLibrary1Chars = | 6040 const char* kLibrary1Chars = |
| 6032 "library library1_name;"; | 6041 "library library1_name;"; |
| 6033 Dart_Handle url = NewString("library1_url"); | 6042 Dart_Handle url = NewString("library1_url"); |
| 6034 Dart_Handle source = NewString(kLibrary1Chars); | 6043 Dart_Handle source = NewString(kLibrary1Chars); |
| 6035 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); | 6044 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); |
| 6036 Dart_Handle error = Dart_NewApiError("incoming error"); | 6045 Dart_Handle error = Dart_NewApiError("incoming error"); |
| 6037 EXPECT_VALID(lib); | 6046 EXPECT_VALID(lib); |
| 6038 intptr_t libraryId = -1; | 6047 intptr_t libraryId = -1; |
| 6039 | 6048 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 6057 Dart_Handle libFromId = Dart_GetLibraryFromId(libraryId); | 6066 Dart_Handle libFromId = Dart_GetLibraryFromId(libraryId); |
| 6058 EXPECT(Dart_IsLibrary(libFromId)); | 6067 EXPECT(Dart_IsLibrary(libFromId)); |
| 6059 result = Dart_LibraryName(libFromId); | 6068 result = Dart_LibraryName(libFromId); |
| 6060 EXPECT(Dart_IsString(result)); | 6069 EXPECT(Dart_IsString(result)); |
| 6061 const char* cstr = NULL; | 6070 const char* cstr = NULL; |
| 6062 EXPECT_VALID(Dart_StringToCString(result, &cstr)); | 6071 EXPECT_VALID(Dart_StringToCString(result, &cstr)); |
| 6063 EXPECT_STREQ("library1_name", cstr); | 6072 EXPECT_STREQ("library1_name", cstr); |
| 6064 } | 6073 } |
| 6065 | 6074 |
| 6066 | 6075 |
| 6076 #endif // !PRODUCT |
| 6077 |
| 6078 |
| 6067 TEST_CASE(LibraryUrl) { | 6079 TEST_CASE(LibraryUrl) { |
| 6068 const char* kLibrary1Chars = | 6080 const char* kLibrary1Chars = |
| 6069 "library library1_name;"; | 6081 "library library1_name;"; |
| 6070 Dart_Handle url = NewString("library1_url"); | 6082 Dart_Handle url = NewString("library1_url"); |
| 6071 Dart_Handle source = NewString(kLibrary1Chars); | 6083 Dart_Handle source = NewString(kLibrary1Chars); |
| 6072 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); | 6084 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); |
| 6073 Dart_Handle error = Dart_NewApiError("incoming error"); | 6085 Dart_Handle error = Dart_NewApiError("incoming error"); |
| 6074 EXPECT_VALID(lib); | 6086 EXPECT_VALID(lib); |
| 6075 | 6087 |
| 6076 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); | 6088 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); |
| (...skipping 3082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9159 result = Dart_Invoke(lib, | 9171 result = Dart_Invoke(lib, |
| 9160 NewString("testView16"), | 9172 NewString("testView16"), |
| 9161 1, | 9173 1, |
| 9162 dart_args); | 9174 dart_args); |
| 9163 EXPECT_VALID(result); | 9175 EXPECT_VALID(result); |
| 9164 EXPECT(Dart_IsString(result)); | 9176 EXPECT(Dart_IsString(result)); |
| 9165 } | 9177 } |
| 9166 } | 9178 } |
| 9167 | 9179 |
| 9168 | 9180 |
| 9181 #ifndef PRODUCT |
| 9182 |
| 9183 |
| 9169 TEST_CASE(Timeline_Dart_TimelineDuration) { | 9184 TEST_CASE(Timeline_Dart_TimelineDuration) { |
| 9170 Isolate* isolate = Isolate::Current(); | 9185 Isolate* isolate = Isolate::Current(); |
| 9171 // Grab embedder stream. | 9186 // Grab embedder stream. |
| 9172 TimelineStream* stream = isolate->GetEmbedderStream(); | 9187 TimelineStream* stream = isolate->GetEmbedderStream(); |
| 9173 // Make sure it is enabled. | 9188 // Make sure it is enabled. |
| 9174 stream->set_enabled(true); | 9189 stream->set_enabled(true); |
| 9175 // Add a duration event. | 9190 // Add a duration event. |
| 9176 Dart_TimelineDuration("testDurationEvent", 0, 1); | 9191 Dart_TimelineDuration("testDurationEvent", 0, 1); |
| 9177 // Check that it is in the output. | 9192 // Check that it is in the output. |
| 9178 TimelineEventRecorder* recorder = Timeline::recorder(); | 9193 TimelineEventRecorder* recorder = Timeline::recorder(); |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9744 EXPECT_SUBSTRING("\"name\":\"TestVMDuration\"", buffer); | 9759 EXPECT_SUBSTRING("\"name\":\"TestVMDuration\"", buffer); |
| 9745 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9760 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
| 9746 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9761 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
| 9747 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9762 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
| 9748 | 9763 |
| 9749 // Heartbeat test for new events. | 9764 // Heartbeat test for new events. |
| 9750 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | 9765 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
| 9751 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9766 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
| 9752 } | 9767 } |
| 9753 | 9768 |
| 9769 #endif // !PRODUCT |
| 9770 |
| 9754 } // namespace dart | 9771 } // namespace dart |
| OLD | NEW |