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

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

Issue 1130753006: Hide Isolate pointer from embedder (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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
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 "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 3663 matching lines...) Expand 10 before | Expand all | Expand 10 after
3674 3674
3675 3675
3676 UNIT_TEST_CASE(Isolates) { 3676 UNIT_TEST_CASE(Isolates) {
3677 // This test currently assumes that the Dart_Isolate type is an opaque 3677 // This test currently assumes that the Dart_Isolate type is an opaque
3678 // representation of Isolate*. 3678 // representation of Isolate*.
3679 Dart_Isolate iso_1 = TestCase::CreateTestIsolate(); 3679 Dart_Isolate iso_1 = TestCase::CreateTestIsolate();
3680 EXPECT_EQ(iso_1, Api::CastIsolate(Isolate::Current())); 3680 EXPECT_EQ(iso_1, Api::CastIsolate(Isolate::Current()));
3681 Dart_Isolate isolate = Dart_CurrentIsolate(); 3681 Dart_Isolate isolate = Dart_CurrentIsolate();
3682 EXPECT_EQ(iso_1, isolate); 3682 EXPECT_EQ(iso_1, isolate);
3683 Dart_ExitIsolate(); 3683 Dart_ExitIsolate();
3684 EXPECT(NULL == Dart_CurrentIsolate()); 3684 EXPECT(ILLEGAL_ISOLATE == Dart_CurrentIsolate());
3685 Dart_Isolate iso_2 = TestCase::CreateTestIsolate(); 3685 Dart_Isolate iso_2 = TestCase::CreateTestIsolate();
3686 EXPECT_EQ(iso_2, Dart_CurrentIsolate()); 3686 EXPECT_EQ(iso_2, Dart_CurrentIsolate());
3687 Dart_ExitIsolate(); 3687 Dart_ExitIsolate();
3688 EXPECT(NULL == Dart_CurrentIsolate()); 3688 EXPECT(ILLEGAL_ISOLATE == Dart_CurrentIsolate());
3689 Dart_EnterIsolate(iso_2); 3689 Dart_EnterIsolate(iso_2);
3690 EXPECT_EQ(iso_2, Dart_CurrentIsolate()); 3690 EXPECT_EQ(iso_2, Dart_CurrentIsolate());
3691 Dart_ShutdownIsolate(); 3691 Dart_ShutdownIsolate();
3692 EXPECT(NULL == Dart_CurrentIsolate()); 3692 EXPECT(ILLEGAL_ISOLATE == Dart_CurrentIsolate());
3693 Dart_EnterIsolate(iso_1); 3693 Dart_EnterIsolate(iso_1);
3694 EXPECT_EQ(iso_1, Dart_CurrentIsolate()); 3694 EXPECT_EQ(iso_1, Dart_CurrentIsolate());
3695 Dart_ShutdownIsolate(); 3695 Dart_ShutdownIsolate();
3696 EXPECT(NULL == Dart_CurrentIsolate()); 3696 EXPECT(ILLEGAL_ISOLATE == Dart_CurrentIsolate());
3697 } 3697 }
3698 3698
3699 3699
3700 UNIT_TEST_CASE(CurrentIsolateData) { 3700 UNIT_TEST_CASE(CurrentIsolateData) {
3701 intptr_t mydata = 12345; 3701 intptr_t mydata = 12345;
3702 char* err; 3702 char* err;
3703 // We expect that Dart_Port and Dart_Isolate are the same size.
3704 EXPECT_EQ(sizeof(Dart_Port), sizeof(Dart_Isolate));
3703 Dart_Isolate isolate = 3705 Dart_Isolate isolate =
3704 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, 3706 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer,
3705 reinterpret_cast<void*>(mydata), 3707 reinterpret_cast<void*>(mydata),
3706 &err); 3708 &err);
3707 EXPECT(isolate != NULL); 3709 EXPECT(isolate != ILLEGAL_ISOLATE);
3708 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData())); 3710 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_CurrentIsolateData()));
3709 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_IsolateData(isolate))); 3711 EXPECT_EQ(mydata, reinterpret_cast<intptr_t>(Dart_IsolateData(isolate)));
3710 Dart_ShutdownIsolate(); 3712 Dart_ShutdownIsolate();
3711 } 3713 }
3712 3714
3713 3715
3714 TEST_CASE(IsolateSetCheckedMode) { 3716 TEST_CASE(IsolateSetCheckedMode) {
3715 const char* kScriptChars = 3717 const char* kScriptChars =
3716 "int bad1() {\n" 3718 "int bad1() {\n"
3717 " int foo = 'string';\n" 3719 " int foo = 'string';\n"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3749 } 3751 }
3750 3752
3751 3753
3752 static void MyMessageNotifyCallback(Dart_Isolate dest_isolate) { 3754 static void MyMessageNotifyCallback(Dart_Isolate dest_isolate) {
3753 } 3755 }
3754 3756
3755 3757
3756 UNIT_TEST_CASE(SetMessageCallbacks) { 3758 UNIT_TEST_CASE(SetMessageCallbacks) {
3757 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); 3759 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate();
3758 Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback); 3760 Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback);
3759 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); 3761 Isolate* isolate = Api::CastIsolate(dart_isolate);
3760 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback()); 3762 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback());
3761 Dart_ShutdownIsolate(); 3763 Dart_ShutdownIsolate();
3762 } 3764 }
3763 3765
3764 3766
3765 TEST_CASE(TypeGetNonParamtericTypes) { 3767 TEST_CASE(TypeGetNonParamtericTypes) {
3766 const char* kScriptChars = 3768 const char* kScriptChars =
3767 "class MyClass0 {\n" 3769 "class MyClass0 {\n"
3768 "}\n" 3770 "}\n"
3769 "\n" 3771 "\n"
(...skipping 3549 matching lines...) Expand 10 before | Expand all | Expand 10 after
7319 "void main(exc_child, exc_parent) {\n" 7321 "void main(exc_child, exc_parent) {\n"
7320 " var receivePort = new RawReceivePort();\n" 7322 " var receivePort = new RawReceivePort();\n"
7321 " Isolate.spawn(entry, [exc_child, receivePort.sendPort]);\n" 7323 " Isolate.spawn(entry, [exc_child, receivePort.sendPort]);\n"
7322 " receivePort.handler = (message) {\n" 7324 " receivePort.handler = (message) {\n"
7323 " receivePort.close();\n" 7325 " receivePort.close();\n"
7324 " if (message != 'hello') throw new Exception('ShouldNotHappen');\n" 7326 " if (message != 'hello') throw new Exception('ShouldNotHappen');\n"
7325 " if (exc_parent) throw new Exception('MakeParentExit');\n" 7327 " if (exc_parent) throw new Exception('MakeParentExit');\n"
7326 " };\n" 7328 " };\n"
7327 "}\n"; 7329 "}\n";
7328 7330
7329 if (Dart_CurrentIsolate() != NULL) { 7331 if (Dart_CurrentIsolate() != ILLEGAL_ISOLATE) {
7330 Dart_ExitIsolate(); 7332 Dart_ExitIsolate();
7331 } 7333 }
7332 Dart_Isolate isolate = TestCase::CreateTestIsolate(script_name); 7334 Dart_Isolate isolate = TestCase::CreateTestIsolate(script_name);
7333 ASSERT(isolate != NULL); 7335 ASSERT(isolate != ILLEGAL_ISOLATE);
7334 if (Dart_IsServiceIsolate(isolate)) { 7336 if (Dart_IsServiceIsolate(isolate)) {
7335 return isolate; 7337 return isolate;
7336 } 7338 }
7337 Dart_EnterScope(); 7339 Dart_EnterScope();
7338 Dart_Handle url = NewString(TestCase::url()); 7340 Dart_Handle url = NewString(TestCase::url());
7339 Dart_Handle source = NewString(kScriptChars); 7341 Dart_Handle source = NewString(kScriptChars);
7340 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); 7342 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler);
7341 EXPECT_VALID(result); 7343 EXPECT_VALID(result);
7342 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); 7344 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0);
7343 EXPECT_VALID(lib); 7345 EXPECT_VALID(lib);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
7469 "}\n"; 7471 "}\n";
7470 7472
7471 // Tell the other thread that shared_isolate is created. 7473 // Tell the other thread that shared_isolate is created.
7472 Dart_Handle lib; 7474 Dart_Handle lib;
7473 { 7475 {
7474 MonitorLocker ml(sync); 7476 MonitorLocker ml(sync);
7475 char* error = NULL; 7477 char* error = NULL;
7476 shared_isolate = Dart_CreateIsolate(NULL, NULL, 7478 shared_isolate = Dart_CreateIsolate(NULL, NULL,
7477 bin::isolate_snapshot_buffer, 7479 bin::isolate_snapshot_buffer,
7478 NULL, &error); 7480 NULL, &error);
7479 EXPECT(shared_isolate != NULL); 7481 EXPECT(shared_isolate != ILLEGAL_ISOLATE);
7480 Dart_EnterScope(); 7482 Dart_EnterScope();
7481 Dart_Handle url = NewString(TestCase::url()); 7483 Dart_Handle url = NewString(TestCase::url());
7482 Dart_Handle source = NewString(kScriptChars); 7484 Dart_Handle source = NewString(kScriptChars);
7483 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); 7485 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler);
7484 EXPECT_VALID(result); 7486 EXPECT_VALID(result);
7485 lib = Dart_LoadScript(url, source, 0, 0); 7487 lib = Dart_LoadScript(url, source, 0, 0);
7486 EXPECT_VALID(lib); 7488 EXPECT_VALID(lib);
7487 result = Dart_FinalizeLoading(false); 7489 result = Dart_FinalizeLoading(false);
7488 EXPECT_VALID(result); 7490 EXPECT_VALID(result);
7489 result = 7491 result =
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
7568 while (interrupt_count == i) { 7570 while (interrupt_count == i) {
7569 ml.Wait(); 7571 ml.Wait();
7570 } 7572 }
7571 OS::Print(" ========== Interrupt processed #%d\n", interrupt_count); 7573 OS::Print(" ========== Interrupt processed #%d\n", interrupt_count);
7572 } 7574 }
7573 } 7575 }
7574 7576
7575 { 7577 {
7576 MonitorLocker ml(sync); 7578 MonitorLocker ml(sync);
7577 // Wait for our isolate to finish. 7579 // Wait for our isolate to finish.
7578 while (shared_isolate != NULL) { 7580 while (shared_isolate != ILLEGAL_ISOLATE) {
7579 ml.Wait(); 7581 ml.Wait();
7580 } 7582 }
7581 } 7583 }
7582 7584
7583 // We should have received the expected number of interrupts. 7585 // We should have received the expected number of interrupts.
7584 EXPECT_EQ(kInterruptCount, interrupt_count); 7586 EXPECT_EQ(kInterruptCount, interrupt_count);
7585 7587
7586 Isolate::SetInterruptCallback(saved); 7588 Isolate::SetInterruptCallback(saved);
7587 } 7589 }
7588 7590
7589 static void* saved_callback_data; 7591 static void* saved_callback_data;
7590 static void IsolateShutdownTestCallback(void* callback_data) { 7592 static void IsolateShutdownTestCallback(void* callback_data) {
7591 saved_callback_data = callback_data; 7593 saved_callback_data = callback_data;
7592 } 7594 }
7593 7595
7594 UNIT_TEST_CASE(IsolateShutdown) { 7596 UNIT_TEST_CASE(IsolateShutdown) {
7595 Dart_IsolateShutdownCallback saved = Isolate::ShutdownCallback(); 7597 Dart_IsolateShutdownCallback saved = Isolate::ShutdownCallback();
7596 Isolate::SetShutdownCallback(IsolateShutdownTestCallback); 7598 Isolate::SetShutdownCallback(IsolateShutdownTestCallback);
7597 7599
7598 saved_callback_data = NULL; 7600 saved_callback_data = NULL;
7599 7601
7600 void* my_data = reinterpret_cast<void*>(12345); 7602 void* my_data = reinterpret_cast<void*>(12345);
7601 7603
7602 // Create an isolate. 7604 // Create an isolate.
7603 char* err; 7605 char* err;
7604 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, 7606 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL,
7605 bin::isolate_snapshot_buffer, 7607 bin::isolate_snapshot_buffer,
7606 my_data, &err); 7608 my_data, &err);
7607 if (isolate == NULL) { 7609 if (isolate == ILLEGAL_ISOLATE) {
7608 OS::Print("Creation of isolate failed '%s'\n", err); 7610 OS::Print("Creation of isolate failed '%s'\n", err);
7609 free(err); 7611 free(err);
7610 } 7612 }
7611 EXPECT(isolate != NULL); 7613 EXPECT(isolate != ILLEGAL_ISOLATE);
7612 7614
7613 // The shutdown callback has not been called. 7615 // The shutdown callback has not been called.
7614 EXPECT_EQ(0, reinterpret_cast<intptr_t>(saved_callback_data)); 7616 EXPECT_EQ(0, reinterpret_cast<intptr_t>(saved_callback_data));
7615 7617
7616 // Shutdown the isolate. 7618 // Shutdown the isolate.
7617 Dart_ShutdownIsolate(); 7619 Dart_ShutdownIsolate();
7618 7620
7619 // The shutdown callback has been called. 7621 // The shutdown callback has been called.
7620 EXPECT_EQ(12345, reinterpret_cast<intptr_t>(saved_callback_data)); 7622 EXPECT_EQ(12345, reinterpret_cast<intptr_t>(saved_callback_data));
7621 7623
(...skipping 25 matching lines...) Expand all
7647 "\n" 7649 "\n"
7648 "void main() {\n" 7650 "void main() {\n"
7649 " add(4, 5);\n" 7651 " add(4, 5);\n"
7650 "}\n"; 7652 "}\n";
7651 7653
7652 // Create an isolate. 7654 // Create an isolate.
7653 char* err; 7655 char* err;
7654 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, 7656 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL,
7655 bin::isolate_snapshot_buffer, 7657 bin::isolate_snapshot_buffer,
7656 NULL, &err); 7658 NULL, &err);
7657 if (isolate == NULL) { 7659 if (isolate == ILLEGAL_ISOLATE) {
7658 OS::Print("Creation of isolate failed '%s'\n", err); 7660 OS::Print("Creation of isolate failed '%s'\n", err);
7659 free(err); 7661 free(err);
7660 } 7662 }
7661 EXPECT(isolate != NULL); 7663 EXPECT(isolate != ILLEGAL_ISOLATE);
7662 7664
7663 Isolate::SetShutdownCallback(IsolateShutdownRunDartCodeTestCallback); 7665 Isolate::SetShutdownCallback(IsolateShutdownRunDartCodeTestCallback);
7664 7666
7665 { 7667 {
7666 Dart_EnterScope(); 7668 Dart_EnterScope();
7667 Dart_Handle url = NewString(TestCase::url()); 7669 Dart_Handle url = NewString(TestCase::url());
7668 Dart_Handle source = NewString(kScriptChars); 7670 Dart_Handle source = NewString(kScriptChars);
7669 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); 7671 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler);
7670 EXPECT_VALID(result); 7672 EXPECT_VALID(result);
7671 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); 7673 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0);
7672 EXPECT_VALID(lib); 7674 EXPECT_VALID(lib);
7673 result = Dart_FinalizeLoading(false); 7675 result = Dart_FinalizeLoading(false);
7674 EXPECT_VALID(result); 7676 EXPECT_VALID(result);
7675 result = Dart_Invoke(lib, NewString("main"), 0, NULL); 7677 result = Dart_Invoke(lib, NewString("main"), 0, NULL);
7676 EXPECT_VALID(result); 7678 EXPECT_VALID(result);
7677 Dart_ExitScope(); 7679 Dart_ExitScope();
7678 } 7680 }
7679 7681
7680 7682
7681 // The shutdown callback has not been called. 7683 // The shutdown callback has not been called.
7682 EXPECT_EQ(0, add_result); 7684 EXPECT_EQ(0, add_result);
7683 7685
7684 EXPECT(isolate != NULL); 7686 EXPECT(isolate != ILLEGAL_ISOLATE);
7685 7687
7686 // Shutdown the isolate. 7688 // Shutdown the isolate.
7687 Dart_ShutdownIsolate(); 7689 Dart_ShutdownIsolate();
7688 7690
7689 // The shutdown callback has been called and ran Dart code. 7691 // The shutdown callback has been called and ran Dart code.
7690 EXPECT_EQ(99, add_result); 7692 EXPECT_EQ(99, add_result);
7691 } 7693 }
7692 7694
7693 static int64_t GetValue(Dart_Handle arg) { 7695 static int64_t GetValue(Dart_Handle arg) {
7694 EXPECT_VALID(arg); 7696 EXPECT_VALID(arg);
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after
9131 result = Dart_Invoke(lib, 9133 result = Dart_Invoke(lib,
9132 NewString("testView16"), 9134 NewString("testView16"),
9133 1, 9135 1,
9134 dart_args); 9136 dart_args);
9135 EXPECT_VALID(result); 9137 EXPECT_VALID(result);
9136 EXPECT(Dart_IsString(result)); 9138 EXPECT(Dart_IsString(result));
9137 } 9139 }
9138 } 9140 }
9139 9141
9140 } // namespace dart 9142 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698