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_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 3693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3704 EXPECT_EQ(iso_1, Dart_CurrentIsolate()); | 3704 EXPECT_EQ(iso_1, Dart_CurrentIsolate()); |
3705 Dart_ShutdownIsolate(); | 3705 Dart_ShutdownIsolate(); |
3706 EXPECT(NULL == Dart_CurrentIsolate()); | 3706 EXPECT(NULL == Dart_CurrentIsolate()); |
3707 } | 3707 } |
3708 | 3708 |
3709 | 3709 |
3710 UNIT_TEST_CASE(CurrentIsolateData) { | 3710 UNIT_TEST_CASE(CurrentIsolateData) { |
3711 intptr_t mydata = 12345; | 3711 intptr_t mydata = 12345; |
3712 char* err; | 3712 char* err; |
3713 Dart_Isolate isolate = | 3713 Dart_Isolate isolate = |
3714 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, | 3714 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL, |
3715 reinterpret_cast<void*>(mydata), | 3715 reinterpret_cast<void*>(mydata), |
3716 &err); | 3716 &err); |
3717 EXPECT(isolate != NULL); | 3717 EXPECT(isolate != NULL); |
3718 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData())); | 3718 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData())); |
3719 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_IsolateData(isolate))); | 3719 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_IsolateData(isolate))); |
3720 Dart_ShutdownIsolate(); | 3720 Dart_ShutdownIsolate(); |
3721 } | 3721 } |
3722 | 3722 |
3723 | 3723 |
3724 TEST_CASE(IsolateSetCheckedMode) { | 3724 TEST_CASE(IsolateSetCheckedMode) { |
(...skipping 3579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7304 | 7304 |
7305 // Delete the native ports. | 7305 // Delete the native ports. |
7306 EXPECT(Dart_CloseNativePort(port_id1)); | 7306 EXPECT(Dart_CloseNativePort(port_id1)); |
7307 EXPECT(Dart_CloseNativePort(port_id2)); | 7307 EXPECT(Dart_CloseNativePort(port_id2)); |
7308 } | 7308 } |
7309 | 7309 |
7310 | 7310 |
7311 static Dart_Isolate RunLoopTestCallback(const char* script_name, | 7311 static Dart_Isolate RunLoopTestCallback(const char* script_name, |
7312 const char* main, | 7312 const char* main, |
7313 const char* package_root, | 7313 const char* package_root, |
| 7314 Dart_IsolateFlags* flags, |
7314 void* data, | 7315 void* data, |
7315 char** error) { | 7316 char** error) { |
7316 const char* kScriptChars = | 7317 const char* kScriptChars = |
7317 "import 'builtin';\n" | 7318 "import 'builtin';\n" |
7318 "import 'dart:isolate';\n" | 7319 "import 'dart:isolate';\n" |
7319 "void entry(message) {\n" | 7320 "void entry(message) {\n" |
7320 " var data = message[0];\n" | 7321 " var data = message[0];\n" |
7321 " var replyTo = message[1];\n" | 7322 " var replyTo = message[1];\n" |
7322 " if (data) {\n" | 7323 " if (data) {\n" |
7323 " throw new Exception('MakeChildExit');\n" | 7324 " throw new Exception('MakeChildExit');\n" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7376 EXPECT_VALID(result); | 7377 EXPECT_VALID(result); |
7377 } | 7378 } |
7378 | 7379 |
7379 | 7380 |
7380 // Common code for RunLoop_Success/RunLoop_Failure. | 7381 // Common code for RunLoop_Success/RunLoop_Failure. |
7381 static void RunLoopTest(bool throw_exception_child, | 7382 static void RunLoopTest(bool throw_exception_child, |
7382 bool throw_exception_parent) { | 7383 bool throw_exception_parent) { |
7383 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); | 7384 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); |
7384 Isolate::SetCreateCallback(RunLoopTestCallback); | 7385 Isolate::SetCreateCallback(RunLoopTestCallback); |
7385 Isolate::SetUnhandledExceptionCallback(RunLoopUnhandledExceptionCallback); | 7386 Isolate::SetUnhandledExceptionCallback(RunLoopUnhandledExceptionCallback); |
7386 Dart_Isolate isolate = RunLoopTestCallback(NULL, NULL, NULL, NULL, NULL); | 7387 Dart_Isolate isolate = RunLoopTestCallback( |
| 7388 NULL, NULL, NULL, NULL, NULL, NULL); |
7387 | 7389 |
7388 Dart_EnterIsolate(isolate); | 7390 Dart_EnterIsolate(isolate); |
7389 Dart_EnterScope(); | 7391 Dart_EnterScope(); |
7390 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); | 7392 Dart_Handle lib = Dart_LookupLibrary(NewString(TestCase::url())); |
7391 EXPECT_VALID(lib); | 7393 EXPECT_VALID(lib); |
7392 | 7394 |
7393 Dart_Handle result; | 7395 Dart_Handle result; |
7394 Dart_Handle args[2]; | 7396 Dart_Handle args[2]; |
7395 args[0] = (throw_exception_child ? Dart_True() : Dart_False()); | 7397 args[0] = (throw_exception_child ? Dart_True() : Dart_False()); |
7396 args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); | 7398 args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7478 " }\n" | 7480 " }\n" |
7479 "}\n"; | 7481 "}\n"; |
7480 | 7482 |
7481 // Tell the other thread that shared_isolate is created. | 7483 // Tell the other thread that shared_isolate is created. |
7482 Dart_Handle lib; | 7484 Dart_Handle lib; |
7483 { | 7485 { |
7484 MonitorLocker ml(sync); | 7486 MonitorLocker ml(sync); |
7485 char* error = NULL; | 7487 char* error = NULL; |
7486 shared_isolate = Dart_CreateIsolate(NULL, NULL, | 7488 shared_isolate = Dart_CreateIsolate(NULL, NULL, |
7487 bin::isolate_snapshot_buffer, | 7489 bin::isolate_snapshot_buffer, |
| 7490 NULL, |
7488 NULL, &error); | 7491 NULL, &error); |
7489 EXPECT(shared_isolate != NULL); | 7492 EXPECT(shared_isolate != NULL); |
7490 Dart_EnterScope(); | 7493 Dart_EnterScope(); |
7491 Dart_Handle url = NewString(TestCase::url()); | 7494 Dart_Handle url = NewString(TestCase::url()); |
7492 Dart_Handle source = NewString(kScriptChars); | 7495 Dart_Handle source = NewString(kScriptChars); |
7493 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | 7496 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
7494 EXPECT_VALID(result); | 7497 EXPECT_VALID(result); |
7495 lib = Dart_LoadScript(url, source, 0, 0); | 7498 lib = Dart_LoadScript(url, source, 0, 0); |
7496 EXPECT_VALID(lib); | 7499 EXPECT_VALID(lib); |
7497 result = Dart_FinalizeLoading(false); | 7500 result = Dart_FinalizeLoading(false); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7606 Isolate::SetShutdownCallback(IsolateShutdownTestCallback); | 7609 Isolate::SetShutdownCallback(IsolateShutdownTestCallback); |
7607 | 7610 |
7608 saved_callback_data = NULL; | 7611 saved_callback_data = NULL; |
7609 | 7612 |
7610 void* my_data = reinterpret_cast<void*>(12345); | 7613 void* my_data = reinterpret_cast<void*>(12345); |
7611 | 7614 |
7612 // Create an isolate. | 7615 // Create an isolate. |
7613 char* err; | 7616 char* err; |
7614 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, | 7617 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, |
7615 bin::isolate_snapshot_buffer, | 7618 bin::isolate_snapshot_buffer, |
| 7619 NULL, |
7616 my_data, &err); | 7620 my_data, &err); |
7617 if (isolate == NULL) { | 7621 if (isolate == NULL) { |
7618 OS::Print("Creation of isolate failed '%s'\n", err); | 7622 OS::Print("Creation of isolate failed '%s'\n", err); |
7619 free(err); | 7623 free(err); |
7620 } | 7624 } |
7621 EXPECT(isolate != NULL); | 7625 EXPECT(isolate != NULL); |
7622 | 7626 |
7623 // The shutdown callback has not been called. | 7627 // The shutdown callback has not been called. |
7624 EXPECT_EQ(0, reinterpret_cast<intptr_t>(saved_callback_data)); | 7628 EXPECT_EQ(0, reinterpret_cast<intptr_t>(saved_callback_data)); |
7625 | 7629 |
(...skipping 30 matching lines...) Expand all Loading... |
7656 "}\n" | 7660 "}\n" |
7657 "\n" | 7661 "\n" |
7658 "void main() {\n" | 7662 "void main() {\n" |
7659 " add(4, 5);\n" | 7663 " add(4, 5);\n" |
7660 "}\n"; | 7664 "}\n"; |
7661 | 7665 |
7662 // Create an isolate. | 7666 // Create an isolate. |
7663 char* err; | 7667 char* err; |
7664 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, | 7668 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, |
7665 bin::isolate_snapshot_buffer, | 7669 bin::isolate_snapshot_buffer, |
| 7670 NULL, |
7666 NULL, &err); | 7671 NULL, &err); |
7667 if (isolate == NULL) { | 7672 if (isolate == NULL) { |
7668 OS::Print("Creation of isolate failed '%s'\n", err); | 7673 OS::Print("Creation of isolate failed '%s'\n", err); |
7669 free(err); | 7674 free(err); |
7670 } | 7675 } |
7671 EXPECT(isolate != NULL); | 7676 EXPECT(isolate != NULL); |
7672 | 7677 |
7673 Isolate::SetShutdownCallback(IsolateShutdownRunDartCodeTestCallback); | 7678 Isolate::SetShutdownCallback(IsolateShutdownRunDartCodeTestCallback); |
7674 | 7679 |
7675 { | 7680 { |
(...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9141 result = Dart_Invoke(lib, | 9146 result = Dart_Invoke(lib, |
9142 NewString("testView16"), | 9147 NewString("testView16"), |
9143 1, | 9148 1, |
9144 dart_args); | 9149 dart_args); |
9145 EXPECT_VALID(result); | 9150 EXPECT_VALID(result); |
9146 EXPECT(Dart_IsString(result)); | 9151 EXPECT(Dart_IsString(result)); |
9147 } | 9152 } |
9148 } | 9153 } |
9149 | 9154 |
9150 } // namespace dart | 9155 } // namespace dart |
OLD | NEW |