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: runtime/vm/dart_api_impl_test.cc

Issue 10386107: Implement spawnUri from dart:isolate. This function allows us to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/utils.h" 7 #include "platform/utils.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_state.h" 10 #include "vm/dart_api_state.h"
(...skipping 2313 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2324 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2325 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields")); 2325 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields"));
2326 EXPECT_VALID(cls); 2326 EXPECT_VALID(cls);
2327 Dart_Handle instance = Dart_Invoke(lib, Dart_NewString("test"), 0, NULL); 2327 Dart_Handle instance = Dart_Invoke(lib, Dart_NewString("test"), 0, NULL);
2328 EXPECT_VALID(instance); 2328 EXPECT_VALID(instance);
2329 Dart_Handle name; 2329 Dart_Handle name;
2330 2330
2331 // Load imported lib. 2331 // Load imported lib.
2332 Dart_Handle url = Dart_NewString("library_url"); 2332 Dart_Handle url = Dart_NewString("library_url");
2333 Dart_Handle source = Dart_NewString(kImportedScriptChars); 2333 Dart_Handle source = Dart_NewString(kImportedScriptChars);
2334 Dart_Handle import_map = Dart_NewList(0); 2334 Dart_Handle imported_lib = Dart_LoadLibrary(url, source);
2335 Dart_Handle imported_lib = Dart_LoadLibrary(url, source, import_map);
2336 EXPECT_VALID(imported_lib); 2335 EXPECT_VALID(imported_lib);
2337 Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib); 2336 Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib);
2338 EXPECT_VALID(result); 2337 EXPECT_VALID(result);
2339 result = Dart_Invoke(imported_lib, Dart_NewString("test2"), 0, NULL); 2338 result = Dart_Invoke(imported_lib, Dart_NewString("test2"), 0, NULL);
2340 EXPECT_VALID(result); 2339 EXPECT_VALID(result);
2341 2340
2342 // Instance field. 2341 // Instance field.
2343 name = Dart_NewString("instance_fld"); 2342 name = Dart_NewString("instance_fld");
2344 TestFieldNotFound(lib, name); 2343 TestFieldNotFound(lib, name);
2345 TestFieldNotFound(cls, name); 2344 TestFieldNotFound(cls, name);
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
3287 "void local() {}\n" 3286 "void local() {}\n"
3288 "void _local() {}\n"; 3287 "void _local() {}\n";
3289 const char* kLibrary2Chars = 3288 const char* kLibrary2Chars =
3290 "#library('library2_name');\n" 3289 "#library('library2_name');\n"
3291 "void imported() {}\n" 3290 "void imported() {}\n"
3292 "void _imported() {}\n"; 3291 "void _imported() {}\n";
3293 3292
3294 // Load lib1 3293 // Load lib1
3295 Dart_Handle url = Dart_NewString("library1_url"); 3294 Dart_Handle url = Dart_NewString("library1_url");
3296 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3295 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3297 Dart_Handle import_map = Dart_NewList(0); 3296 Dart_Handle lib1 = Dart_LoadLibrary(url, source);
3298 Dart_Handle lib1 = Dart_LoadLibrary(url, source, import_map);
3299 EXPECT_VALID(lib1); 3297 EXPECT_VALID(lib1);
3300 3298
3301 // Load lib2 3299 // Load lib2
3302 url = Dart_NewString("library2_url"); 3300 url = Dart_NewString("library2_url");
3303 source = Dart_NewString(kLibrary2Chars); 3301 source = Dart_NewString(kLibrary2Chars);
3304 Dart_Handle lib2 = Dart_LoadLibrary(url, source, import_map); 3302 Dart_Handle lib2 = Dart_LoadLibrary(url, source);
3305 EXPECT_VALID(lib2); 3303 EXPECT_VALID(lib2);
3306 3304
3307 // Import lib2 from lib1 3305 // Import lib2 from lib1
3308 Dart_Handle result = Dart_LibraryImportLibrary(lib1, lib2); 3306 Dart_Handle result = Dart_LibraryImportLibrary(lib1, lib2);
3309 EXPECT_VALID(result); 3307 EXPECT_VALID(result);
3310 3308
3311 // We can invoke both private and non-private local functions. 3309 // We can invoke both private and non-private local functions.
3312 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("local"), 0, NULL)); 3310 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("local"), 0, NULL));
3313 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("_local"), 0, NULL)); 3311 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("_local"), 0, NULL));
3314 3312
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
3570 EXPECT(!is_instance); 3568 EXPECT(!is_instance);
3571 3569
3572 // Check that error is returned if null is passed as a class argument. 3570 // Check that error is returned if null is passed as a class argument.
3573 result = Dart_ObjectIsType(null, null, &is_instance); 3571 result = Dart_ObjectIsType(null, null, &is_instance);
3574 EXPECT(Dart_IsError(result)); 3572 EXPECT(Dart_IsError(result));
3575 } 3573 }
3576 3574
3577 3575
3578 static Dart_Handle library_handler(Dart_LibraryTag tag, 3576 static Dart_Handle library_handler(Dart_LibraryTag tag,
3579 Dart_Handle library, 3577 Dart_Handle library,
3580 Dart_Handle url, 3578 Dart_Handle url) {
3581 Dart_Handle import_url_map) {
3582 if (tag == kCanonicalizeUrl) { 3579 if (tag == kCanonicalizeUrl) {
3583 return url; 3580 return url;
3584 } 3581 }
3585 return Api::Success(Isolate::Current()); 3582 return Api::Success(Isolate::Current());
3586 } 3583 }
3587 3584
3588 3585
3589 TEST_CASE(LoadScript) { 3586 TEST_CASE(LoadScript) {
3590 const char* kScriptChars = 3587 const char* kScriptChars =
3591 "main() {" 3588 "main() {"
3592 " return 12345;" 3589 " return 12345;"
3593 "}"; 3590 "}";
3594 Dart_Handle url = Dart_NewString(TestCase::url()); 3591 Dart_Handle url = Dart_NewString(TestCase::url());
3595 Dart_Handle source = Dart_NewString(kScriptChars); 3592 Dart_Handle source = Dart_NewString(kScriptChars);
3596 Dart_Handle error = Dart_Error("incoming error"); 3593 Dart_Handle error = Dart_Error("incoming error");
3597 Dart_Handle result; 3594 Dart_Handle result;
3598 Dart_Handle import_map = Dart_NewList(0);
3599 3595
3600 result = Dart_SetLibraryTagHandler(library_handler); 3596 result = Dart_SetLibraryTagHandler(library_handler);
3601 EXPECT_VALID(result); 3597 EXPECT_VALID(result);
3602 3598
3603 result = Dart_LoadScript(Dart_Null(), source, import_map); 3599 result = Dart_LoadScript(Dart_Null(), source);
3604 EXPECT(Dart_IsError(result)); 3600 EXPECT(Dart_IsError(result));
3605 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.", 3601 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.",
3606 Dart_GetError(result)); 3602 Dart_GetError(result));
3607 3603
3608 result = Dart_LoadScript(Dart_True(), source, import_map); 3604 result = Dart_LoadScript(Dart_True(), source);
3609 EXPECT(Dart_IsError(result)); 3605 EXPECT(Dart_IsError(result));
3610 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be of type String.", 3606 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be of type String.",
3611 Dart_GetError(result)); 3607 Dart_GetError(result));
3612 3608
3613 result = Dart_LoadScript(error, source, import_map); 3609 result = Dart_LoadScript(error, source);
3614 EXPECT(Dart_IsError(result)); 3610 EXPECT(Dart_IsError(result));
3615 EXPECT_STREQ("incoming error", Dart_GetError(result)); 3611 EXPECT_STREQ("incoming error", Dart_GetError(result));
3616 3612
3617 result = Dart_LoadScript(url, Dart_Null(), import_map); 3613 result = Dart_LoadScript(url, Dart_Null());
3618 EXPECT(Dart_IsError(result)); 3614 EXPECT(Dart_IsError(result));
3619 EXPECT_STREQ("Dart_LoadScript expects argument 'source' to be non-null.", 3615 EXPECT_STREQ("Dart_LoadScript expects argument 'source' to be non-null.",
3620 Dart_GetError(result)); 3616 Dart_GetError(result));
3621 3617
3622 result = Dart_LoadScript(url, Dart_True(), import_map); 3618 result = Dart_LoadScript(url, Dart_True());
3623 EXPECT(Dart_IsError(result)); 3619 EXPECT(Dart_IsError(result));
3624 EXPECT_STREQ( 3620 EXPECT_STREQ(
3625 "Dart_LoadScript expects argument 'source' to be of type String.", 3621 "Dart_LoadScript expects argument 'source' to be of type String.",
3626 Dart_GetError(result)); 3622 Dart_GetError(result));
3627 3623
3628 result = Dart_LoadScript(url, error, import_map); 3624 result = Dart_LoadScript(url, error);
3629 EXPECT(Dart_IsError(result)); 3625 EXPECT(Dart_IsError(result));
3630 EXPECT_STREQ("incoming error", Dart_GetError(result)); 3626 EXPECT_STREQ("incoming error", Dart_GetError(result));
3631 3627
3632 // Load a script successfully. 3628 // Load a script successfully.
3633 result = Dart_LoadScript(url, source, import_map); 3629 result = Dart_LoadScript(url, source);
3634 EXPECT_VALID(result); 3630 EXPECT_VALID(result);
3635 3631
3636 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 3632 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
3637 EXPECT_VALID(result); 3633 EXPECT_VALID(result);
3638 EXPECT(Dart_IsInteger(result)); 3634 EXPECT(Dart_IsInteger(result));
3639 int64_t value = 0; 3635 int64_t value = 0;
3640 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); 3636 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
3641 EXPECT_EQ(12345, value); 3637 EXPECT_EQ(12345, value);
3642 3638
3643 // Further calls to LoadScript are errors. 3639 // Further calls to LoadScript are errors.
3644 result = Dart_LoadScript(url, source, import_map); 3640 result = Dart_LoadScript(url, source);
3645 EXPECT(Dart_IsError(result)); 3641 EXPECT(Dart_IsError(result));
3646 EXPECT_STREQ("Dart_LoadScript: " 3642 EXPECT_STREQ("Dart_LoadScript: "
3647 "A script has already been loaded from 'dart:test-lib'.", 3643 "A script has already been loaded from 'dart:test-lib'.",
3648 Dart_GetError(result)); 3644 Dart_GetError(result));
3649 } 3645 }
3650 3646
3651 3647
3652 static const char* var_mapping[] = { 3648 static const char* var_mapping[] = {
3653 "GOOGLE3", ".", 3649 "GOOGLE3", ".",
3654 "ABC", "lala", 3650 "ABC", "lala",
3655 "var1", "", 3651 "var1", "",
3656 "var2", "winner", 3652 "var2", "winner",
3657 }; 3653 };
3658 static int index = 0; 3654 static int index = 0;
3659 3655
3660 3656
3661 static Dart_Handle import_library_handler(Dart_LibraryTag tag, 3657 static Dart_Handle import_library_handler(Dart_LibraryTag tag,
3662 Dart_Handle library, 3658 Dart_Handle library,
3663 Dart_Handle url, 3659 Dart_Handle url) {
3664 Dart_Handle import_url_map) {
3665 if (tag == kCanonicalizeUrl) { 3660 if (tag == kCanonicalizeUrl) {
3666 return url; 3661 return url;
3667 } 3662 }
3668 EXPECT(Dart_IsString(url)); 3663 EXPECT(Dart_IsString(url));
3669 const char* cstr = NULL; 3664 const char* cstr = NULL;
3670 EXPECT_VALID(Dart_StringToCString(url, &cstr)); 3665 EXPECT_VALID(Dart_StringToCString(url, &cstr));
3671 switch (index) { 3666 switch (index) {
3672 case 0: 3667 case 0:
3673 EXPECT_STREQ("./weird.dart", cstr); 3668 EXPECT_STREQ("./weird.dart", cstr);
3674 break; 3669 break;
(...skipping 30 matching lines...) Expand all
3705 "}"; 3700 "}";
3706 Dart_Handle url = Dart_NewString(TestCase::url()); 3701 Dart_Handle url = Dart_NewString(TestCase::url());
3707 Dart_Handle source = Dart_NewString(kScriptChars); 3702 Dart_Handle source = Dart_NewString(kScriptChars);
3708 intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0])); 3703 intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0]));
3709 Dart_Handle import_map = Dart_NewList(length); 3704 Dart_Handle import_map = Dart_NewList(length);
3710 for (intptr_t i = 0; i < length; i++) { 3705 for (intptr_t i = 0; i < length; i++) {
3711 Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i])); 3706 Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i]));
3712 } 3707 }
3713 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); 3708 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler);
3714 EXPECT_VALID(result); 3709 EXPECT_VALID(result);
3715 result = Dart_LoadScript(url, source, import_map); 3710 result = Dart_SetImportMap(import_map);
3711 EXPECT_VALID(result);
3712 result = Dart_LoadScript(url, source);
3716 EXPECT(!Dart_IsError(result)); 3713 EXPECT(!Dart_IsError(result));
3717 } 3714 }
3718 3715
3719 3716
3720 TEST_CASE(LoadImportScriptError1) { 3717 TEST_CASE(LoadImportScriptError1) {
3721 const char* kScriptChars = 3718 const char* kScriptChars =
3722 "#import('abc${DEF}def/extra_weird.dart');" 3719 "#import('abc${DEF}def/extra_weird.dart');"
3723 "main() {" 3720 "main() {"
3724 " return 12345;" 3721 " return 12345;"
3725 "}"; 3722 "}";
3726 Dart_Handle url = Dart_NewString(TestCase::url()); 3723 Dart_Handle url = Dart_NewString(TestCase::url());
3727 Dart_Handle source = Dart_NewString(kScriptChars); 3724 Dart_Handle source = Dart_NewString(kScriptChars);
3728 Dart_Handle import_map = Dart_NewList(0);
3729 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); 3725 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler);
3730 EXPECT_VALID(result); 3726 EXPECT_VALID(result);
3731 result = Dart_LoadScript(url, source, import_map); 3727 result = Dart_LoadScript(url, source);
3732 EXPECT(Dart_IsError(result)); 3728 EXPECT(Dart_IsError(result));
3733 EXPECT(strstr(Dart_GetError(result), 3729 EXPECT(strstr(Dart_GetError(result),
3734 "import variable 'DEF' has not been defined")); 3730 "import variable 'DEF' has not been defined"));
3735 } 3731 }
3736 3732
3737 3733
3738 TEST_CASE(LoadImportScriptError2) { 3734 TEST_CASE(LoadImportScriptError2) {
3739 const char* kScriptChars = 3735 const char* kScriptChars =
3740 "#import('abc${ABC/extra_weird.dart');" 3736 "#import('abc${ABC/extra_weird.dart');"
3741 "main() {" 3737 "main() {"
3742 " return 12345;" 3738 " return 12345;"
3743 "}"; 3739 "}";
3744 Dart_Handle url = Dart_NewString(TestCase::url()); 3740 Dart_Handle url = Dart_NewString(TestCase::url());
3745 Dart_Handle source = Dart_NewString(kScriptChars); 3741 Dart_Handle source = Dart_NewString(kScriptChars);
3746 intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0])); 3742 intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0]));
3747 Dart_Handle import_map = Dart_NewList(length); 3743 Dart_Handle import_map = Dart_NewList(length);
3748 for (intptr_t i = 0; i < length; i++) { 3744 for (intptr_t i = 0; i < length; i++) {
3749 Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i])); 3745 Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i]));
3750 } 3746 }
3751 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); 3747 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler);
3752 EXPECT_VALID(result); 3748 EXPECT_VALID(result);
3753 result = Dart_LoadScript(url, source, import_map); 3749 result = Dart_SetImportMap(import_map);
3750 EXPECT_VALID(result);
3751 result = Dart_LoadScript(url, source);
3754 EXPECT(Dart_IsError(result)); 3752 EXPECT(Dart_IsError(result));
3755 EXPECT(strstr(Dart_GetError(result), "'}' expected")); 3753 EXPECT(strstr(Dart_GetError(result), "'}' expected"));
3756 } 3754 }
3757 3755
3758 3756
3759 TEST_CASE(LoadScript_CompileError) { 3757 TEST_CASE(LoadScript_CompileError) {
3760 const char* kScriptChars = 3758 const char* kScriptChars =
3761 ")"; 3759 ")";
3762 Dart_Handle url = Dart_NewString(TestCase::url()); 3760 Dart_Handle url = Dart_NewString(TestCase::url());
3763 Dart_Handle source = Dart_NewString(kScriptChars); 3761 Dart_Handle source = Dart_NewString(kScriptChars);
3764 Dart_Handle import_map = Dart_NewList(0);
3765 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); 3762 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler);
3766 EXPECT_VALID(result); 3763 EXPECT_VALID(result);
3767 result = Dart_LoadScript(url, source, import_map); 3764 result = Dart_LoadScript(url, source);
3768 EXPECT(Dart_IsError(result)); 3765 EXPECT(Dart_IsError(result));
3769 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); 3766 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'"));
3770 } 3767 }
3771 3768
3772 3769
3773 TEST_CASE(LookupLibrary) { 3770 TEST_CASE(LookupLibrary) {
3774 const char* kScriptChars = 3771 const char* kScriptChars =
3775 "#import('library1.dart');" 3772 "#import('library1.dart');"
3776 "main() {}"; 3773 "main() {}";
3777 const char* kLibrary1Chars = 3774 const char* kLibrary1Chars =
3778 "#library('library1.dart');" 3775 "#library('library1.dart');"
3779 "#import('library2.dart');"; 3776 "#import('library2.dart');";
3780 3777
3781 // Create a test library and Load up a test script in it. 3778 // Create a test library and Load up a test script in it.
3782 Dart_Handle url = Dart_NewString(TestCase::url()); 3779 Dart_Handle url = Dart_NewString(TestCase::url());
3783 Dart_Handle source = Dart_NewString(kScriptChars); 3780 Dart_Handle source = Dart_NewString(kScriptChars);
3784 Dart_Handle import_map = Dart_NewList(0);
3785 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); 3781 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler);
3786 EXPECT_VALID(result); 3782 EXPECT_VALID(result);
3787 result = Dart_LoadScript(url, source, import_map); 3783 result = Dart_LoadScript(url, source);
3788 EXPECT_VALID(result); 3784 EXPECT_VALID(result);
3789 3785
3790 url = Dart_NewString("library1.dart"); 3786 url = Dart_NewString("library1.dart");
3791 source = Dart_NewString(kLibrary1Chars); 3787 source = Dart_NewString(kLibrary1Chars);
3792 result = Dart_LoadLibrary(url, source, import_map); 3788 result = Dart_LoadLibrary(url, source);
3793 EXPECT_VALID(result); 3789 EXPECT_VALID(result);
3794 3790
3795 result = Dart_LookupLibrary(url); 3791 result = Dart_LookupLibrary(url);
3796 EXPECT_VALID(result); 3792 EXPECT_VALID(result);
3797 3793
3798 result = Dart_LookupLibrary(Dart_Null()); 3794 result = Dart_LookupLibrary(Dart_Null());
3799 EXPECT(Dart_IsError(result)); 3795 EXPECT(Dart_IsError(result));
3800 EXPECT_STREQ("Dart_LookupLibrary expects argument 'url' to be non-null.", 3796 EXPECT_STREQ("Dart_LookupLibrary expects argument 'url' to be non-null.",
3801 Dart_GetError(result)); 3797 Dart_GetError(result));
3802 3798
(...skipping 13 matching lines...) Expand all
3816 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", 3812 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.",
3817 Dart_GetError(result)); 3813 Dart_GetError(result));
3818 } 3814 }
3819 3815
3820 3816
3821 TEST_CASE(LibraryUrl) { 3817 TEST_CASE(LibraryUrl) {
3822 const char* kLibrary1Chars = 3818 const char* kLibrary1Chars =
3823 "#library('library1_name');"; 3819 "#library('library1_name');";
3824 Dart_Handle url = Dart_NewString("library1_url"); 3820 Dart_Handle url = Dart_NewString("library1_url");
3825 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3821 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3826 Dart_Handle lib = Dart_LoadLibrary(url, source, Dart_Null()); 3822 Dart_Handle lib = Dart_LoadLibrary(url, source);
3827 Dart_Handle error = Dart_Error("incoming error"); 3823 Dart_Handle error = Dart_Error("incoming error");
3828 EXPECT_VALID(lib); 3824 EXPECT_VALID(lib);
3829 3825
3830 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); 3826 Dart_Handle result = Dart_LibraryUrl(Dart_Null());
3831 EXPECT(Dart_IsError(result)); 3827 EXPECT(Dart_IsError(result));
3832 EXPECT_STREQ("Dart_LibraryUrl expects argument 'library' to be non-null.", 3828 EXPECT_STREQ("Dart_LibraryUrl expects argument 'library' to be non-null.",
3833 Dart_GetError(result)); 3829 Dart_GetError(result));
3834 3830
3835 result = Dart_LibraryUrl(Dart_True()); 3831 result = Dart_LibraryUrl(Dart_True());
3836 EXPECT(Dart_IsError(result)); 3832 EXPECT(Dart_IsError(result));
(...skipping 17 matching lines...) Expand all
3854 TEST_CASE(LibraryImportLibrary) { 3850 TEST_CASE(LibraryImportLibrary) {
3855 const char* kLibrary1Chars = 3851 const char* kLibrary1Chars =
3856 "#library('library1_name');"; 3852 "#library('library1_name');";
3857 const char* kLibrary2Chars = 3853 const char* kLibrary2Chars =
3858 "#library('library2_name');"; 3854 "#library('library2_name');";
3859 Dart_Handle error = Dart_Error("incoming error"); 3855 Dart_Handle error = Dart_Error("incoming error");
3860 Dart_Handle result; 3856 Dart_Handle result;
3861 3857
3862 Dart_Handle url = Dart_NewString("library1_url"); 3858 Dart_Handle url = Dart_NewString("library1_url");
3863 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3859 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3864 Dart_Handle import_map = Dart_NewList(0); 3860 Dart_Handle lib1 = Dart_LoadLibrary(url, source);
3865 Dart_Handle lib1 = Dart_LoadLibrary(url, source, import_map);
3866 EXPECT_VALID(lib1); 3861 EXPECT_VALID(lib1);
3867 3862
3868 url = Dart_NewString("library2_url"); 3863 url = Dart_NewString("library2_url");
3869 source = Dart_NewString(kLibrary2Chars); 3864 source = Dart_NewString(kLibrary2Chars);
3870 Dart_Handle lib2 = Dart_LoadLibrary(url, source, import_map); 3865 Dart_Handle lib2 = Dart_LoadLibrary(url, source);
3871 EXPECT_VALID(lib2); 3866 EXPECT_VALID(lib2);
3872 3867
3873 result = Dart_LibraryImportLibrary(Dart_Null(), lib2); 3868 result = Dart_LibraryImportLibrary(Dart_Null(), lib2);
3874 EXPECT(Dart_IsError(result)); 3869 EXPECT(Dart_IsError(result));
3875 EXPECT_STREQ( 3870 EXPECT_STREQ(
3876 "Dart_LibraryImportLibrary expects argument 'library' to be non-null.", 3871 "Dart_LibraryImportLibrary expects argument 'library' to be non-null.",
3877 Dart_GetError(result)); 3872 Dart_GetError(result));
3878 3873
3879 result = Dart_LibraryImportLibrary(Dart_True(), lib2); 3874 result = Dart_LibraryImportLibrary(Dart_True(), lib2);
3880 EXPECT(Dart_IsError(result)); 3875 EXPECT(Dart_IsError(result));
(...skipping 28 matching lines...) Expand all
3909 3904
3910 3905
3911 TEST_CASE(LoadLibrary) { 3906 TEST_CASE(LoadLibrary) {
3912 const char* kLibrary1Chars = 3907 const char* kLibrary1Chars =
3913 "#library('library1_name');"; 3908 "#library('library1_name');";
3914 Dart_Handle error = Dart_Error("incoming error"); 3909 Dart_Handle error = Dart_Error("incoming error");
3915 Dart_Handle result; 3910 Dart_Handle result;
3916 3911
3917 Dart_Handle url = Dart_NewString("library1_url"); 3912 Dart_Handle url = Dart_NewString("library1_url");
3918 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3913 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3919 Dart_Handle import_map = Dart_NewList(0);
3920 3914
3921 result = Dart_LoadLibrary(Dart_Null(), source, import_map); 3915 result = Dart_LoadLibrary(Dart_Null(), source);
3922 EXPECT(Dart_IsError(result)); 3916 EXPECT(Dart_IsError(result));
3923 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.", 3917 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.",
3924 Dart_GetError(result)); 3918 Dart_GetError(result));
3925 3919
3926 result = Dart_LoadLibrary(Dart_True(), source, import_map); 3920 result = Dart_LoadLibrary(Dart_True(), source);
3927 EXPECT(Dart_IsError(result)); 3921 EXPECT(Dart_IsError(result));
3928 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be of type String.", 3922 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be of type String.",
3929 Dart_GetError(result)); 3923 Dart_GetError(result));
3930 3924
3931 result = Dart_LoadLibrary(error, source, import_map); 3925 result = Dart_LoadLibrary(error, source);
3932 EXPECT(Dart_IsError(result)); 3926 EXPECT(Dart_IsError(result));
3933 EXPECT_STREQ("incoming error", Dart_GetError(result)); 3927 EXPECT_STREQ("incoming error", Dart_GetError(result));
3934 3928
3935 result = Dart_LoadLibrary(url, Dart_Null(), import_map); 3929 result = Dart_LoadLibrary(url, Dart_Null());
3936 EXPECT(Dart_IsError(result)); 3930 EXPECT(Dart_IsError(result));
3937 EXPECT_STREQ("Dart_LoadLibrary expects argument 'source' to be non-null.", 3931 EXPECT_STREQ("Dart_LoadLibrary expects argument 'source' to be non-null.",
3938 Dart_GetError(result)); 3932 Dart_GetError(result));
3939 3933
3940 result = Dart_LoadLibrary(url, Dart_True(), import_map); 3934 result = Dart_LoadLibrary(url, Dart_True());
3941 EXPECT(Dart_IsError(result)); 3935 EXPECT(Dart_IsError(result));
3942 EXPECT_STREQ( 3936 EXPECT_STREQ(
3943 "Dart_LoadLibrary expects argument 'source' to be of type String.", 3937 "Dart_LoadLibrary expects argument 'source' to be of type String.",
3944 Dart_GetError(result)); 3938 Dart_GetError(result));
3945 3939
3946 result = Dart_LoadLibrary(url, error, import_map); 3940 result = Dart_LoadLibrary(url, error);
3947 EXPECT(Dart_IsError(result)); 3941 EXPECT(Dart_IsError(result));
3948 EXPECT_STREQ("incoming error", Dart_GetError(result)); 3942 EXPECT_STREQ("incoming error", Dart_GetError(result));
3949 3943
3950 // Success. 3944 // Success.
3951 result = Dart_LoadLibrary(url, source, import_map); 3945 result = Dart_LoadLibrary(url, source);
3952 EXPECT_VALID(result); 3946 EXPECT_VALID(result);
3953 EXPECT(Dart_IsLibrary(result)); 3947 EXPECT(Dart_IsLibrary(result));
3954 3948
3955 // Duplicate library load fails. 3949 // Duplicate library load fails.
3956 result = Dart_LoadLibrary(url, source, import_map); 3950 result = Dart_LoadLibrary(url, source);
3957 EXPECT(Dart_IsError(result)); 3951 EXPECT(Dart_IsError(result));
3958 EXPECT_STREQ( 3952 EXPECT_STREQ(
3959 "Dart_LoadLibrary: library 'library1_url' has already been loaded.", 3953 "Dart_LoadLibrary: library 'library1_url' has already been loaded.",
3960 Dart_GetError(result)); 3954 Dart_GetError(result));
3961 } 3955 }
3962 3956
3963 3957
3964 TEST_CASE(LoadLibrary_CompileError) { 3958 TEST_CASE(LoadLibrary_CompileError) {
3965 const char* kLibrary1Chars = 3959 const char* kLibrary1Chars =
3966 "#library('library1_name');" 3960 "#library('library1_name');"
3967 ")"; 3961 ")";
3968 Dart_Handle url = Dart_NewString("library1_url"); 3962 Dart_Handle url = Dart_NewString("library1_url");
3969 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3963 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3970 Dart_Handle import_map = Dart_NewList(0); 3964 Dart_Handle result = Dart_LoadLibrary(url, source);
3971 Dart_Handle result = Dart_LoadLibrary(url, source, import_map);
3972 EXPECT(Dart_IsError(result)); 3965 EXPECT(Dart_IsError(result));
3973 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); 3966 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'"));
3974 } 3967 }
3975 3968
3976 3969
3977 TEST_CASE(LoadSource) { 3970 TEST_CASE(LoadSource) {
3978 const char* kLibrary1Chars = 3971 const char* kLibrary1Chars =
3979 "#library('library1_name');"; 3972 "#library('library1_name');";
3980 const char* kSourceChars = 3973 const char* kSourceChars =
3981 "// Something innocuous"; 3974 "// Something innocuous";
3982 const char* kBadSourceChars = 3975 const char* kBadSourceChars =
3983 ")"; 3976 ")";
3984 Dart_Handle error = Dart_Error("incoming error"); 3977 Dart_Handle error = Dart_Error("incoming error");
3985 Dart_Handle result; 3978 Dart_Handle result;
3986 3979
3987 // Load up a library. 3980 // Load up a library.
3988 Dart_Handle url = Dart_NewString("library1_url"); 3981 Dart_Handle url = Dart_NewString("library1_url");
3989 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3982 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3990 Dart_Handle import_map = Dart_NewList(0); 3983 Dart_Handle lib = Dart_LoadLibrary(url, source);
3991 Dart_Handle lib = Dart_LoadLibrary(url, source, import_map);
3992 EXPECT_VALID(lib); 3984 EXPECT_VALID(lib);
3993 EXPECT(Dart_IsLibrary(lib)); 3985 EXPECT(Dart_IsLibrary(lib));
3994 3986
3995 url = Dart_NewString("source_url"); 3987 url = Dart_NewString("source_url");
3996 source = Dart_NewString(kSourceChars); 3988 source = Dart_NewString(kSourceChars);
3997 3989
3998 result = Dart_LoadSource(Dart_Null(), url, source); 3990 result = Dart_LoadSource(Dart_Null(), url, source);
3999 EXPECT(Dart_IsError(result)); 3991 EXPECT(Dart_IsError(result));
4000 EXPECT_STREQ("Dart_LoadSource expects argument 'library' to be non-null.", 3992 EXPECT_STREQ("Dart_LoadSource expects argument 'library' to be non-null.",
4001 Dart_GetError(result)); 3993 Dart_GetError(result));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
4094 " static foo() native \"SomeNativeFunction\";" 4086 " static foo() native \"SomeNativeFunction\";"
4095 " static bar() native \"SomeNativeFunction2\";" 4087 " static bar() native \"SomeNativeFunction2\";"
4096 " static baz() native \"SomeNativeFunction3\";" 4088 " static baz() native \"SomeNativeFunction3\";"
4097 "}"; 4089 "}";
4098 Dart_Handle error = Dart_Error("incoming error"); 4090 Dart_Handle error = Dart_Error("incoming error");
4099 Dart_Handle result; 4091 Dart_Handle result;
4100 4092
4101 // Load a test script. 4093 // Load a test script.
4102 Dart_Handle url = Dart_NewString(TestCase::url()); 4094 Dart_Handle url = Dart_NewString(TestCase::url());
4103 Dart_Handle source = Dart_NewString(kScriptChars); 4095 Dart_Handle source = Dart_NewString(kScriptChars);
4104 Dart_Handle import_map = Dart_NewList(0);
4105 result = Dart_SetLibraryTagHandler(library_handler); 4096 result = Dart_SetLibraryTagHandler(library_handler);
4106 EXPECT_VALID(result); 4097 EXPECT_VALID(result);
4107 Dart_Handle lib = Dart_LoadScript(url, source, import_map); 4098 Dart_Handle lib = Dart_LoadScript(url, source);
4108 EXPECT_VALID(lib); 4099 EXPECT_VALID(lib);
4109 EXPECT(Dart_IsLibrary(lib)); 4100 EXPECT(Dart_IsLibrary(lib));
4110 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Test")); 4101 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Test"));
4111 EXPECT_VALID(cls); 4102 EXPECT_VALID(cls);
4112 4103
4113 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1); 4104 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1);
4114 EXPECT(Dart_IsError(result)); 4105 EXPECT(Dart_IsError(result));
4115 EXPECT_STREQ( 4106 EXPECT_STREQ(
4116 "Dart_SetNativeResolver expects argument 'library' to be non-null.", 4107 "Dart_SetNativeResolver expects argument 'library' to be non-null.",
4117 Dart_GetError(result)); 4108 Dart_GetError(result));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
4178 "var foo1;"; 4169 "var foo1;";
4179 const char* kLibrary2Chars = 4170 const char* kLibrary2Chars =
4180 "#library('library2.dart');" 4171 "#library('library2.dart');"
4181 "var foo;"; 4172 "var foo;";
4182 Dart_Handle result; 4173 Dart_Handle result;
4183 // Create a test library and Load up a test script in it. 4174 // Create a test library and Load up a test script in it.
4184 Dart_Handle url = Dart_NewString(TestCase::url()); 4175 Dart_Handle url = Dart_NewString(TestCase::url());
4185 Dart_Handle source = Dart_NewString(kScriptChars); 4176 Dart_Handle source = Dart_NewString(kScriptChars);
4186 result = Dart_SetLibraryTagHandler(library_handler); 4177 result = Dart_SetLibraryTagHandler(library_handler);
4187 EXPECT_VALID(result); 4178 EXPECT_VALID(result);
4188 result = Dart_LoadScript(url, source, Dart_Null()); 4179 result = Dart_LoadScript(url, source);
4189 4180
4190 url = Dart_NewString("library1.dart"); 4181 url = Dart_NewString("library1.dart");
4191 source = Dart_NewString(kLibrary1Chars); 4182 source = Dart_NewString(kLibrary1Chars);
4192 Dart_LoadLibrary(url, source, Dart_Null()); 4183 Dart_LoadLibrary(url, source);
4193 4184
4194 url = Dart_NewString("library2.dart"); 4185 url = Dart_NewString("library2.dart");
4195 source = Dart_NewString(kLibrary2Chars); 4186 source = Dart_NewString(kLibrary2Chars);
4196 Dart_LoadLibrary(url, source, Dart_Null()); 4187 Dart_LoadLibrary(url, source);
4197 4188
4198 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 4189 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
4199 EXPECT(Dart_IsError(result)); 4190 EXPECT(Dart_IsError(result));
4200 EXPECT_STREQ("Duplicate definition : 'foo' is defined in" 4191 EXPECT_STREQ("Duplicate definition : 'foo' is defined in"
4201 " 'library2.dart' and 'dart:test-lib'\n", 4192 " 'library2.dart' and 'dart:test-lib'\n",
4202 Dart_GetError(result)); 4193 Dart_GetError(result));
4203 } 4194 }
4204 4195
4205 4196
4206 TEST_CASE(ImportLibrary2) { 4197 TEST_CASE(ImportLibrary2) {
4207 const char* kScriptChars = 4198 const char* kScriptChars =
4208 "#import('library1.dart');" 4199 "#import('library1.dart');"
4209 "var foo;" 4200 "var foo;"
4210 "main() {}"; 4201 "main() {}";
4211 const char* kLibrary1Chars = 4202 const char* kLibrary1Chars =
4212 "#library('library1.dart');" 4203 "#library('library1.dart');"
4213 "#import('library2.dart');" 4204 "#import('library2.dart');"
4214 "var foo1;"; 4205 "var foo1;";
4215 const char* kLibrary2Chars = 4206 const char* kLibrary2Chars =
4216 "#library('library2.dart');" 4207 "#library('library2.dart');"
4217 "#import('library1.dart');" 4208 "#import('library1.dart');"
4218 "var foo;"; 4209 "var foo;";
4219 Dart_Handle result; 4210 Dart_Handle result;
4220 // Create a test library and Load up a test script in it. 4211 // Create a test library and Load up a test script in it.
4221 Dart_Handle url = Dart_NewString(TestCase::url()); 4212 Dart_Handle url = Dart_NewString(TestCase::url());
4222 Dart_Handle source = Dart_NewString(kScriptChars); 4213 Dart_Handle source = Dart_NewString(kScriptChars);
4223 Dart_Handle import_map = Dart_NewList(0);
4224 result = Dart_SetLibraryTagHandler(library_handler); 4214 result = Dart_SetLibraryTagHandler(library_handler);
4225 EXPECT_VALID(result); 4215 EXPECT_VALID(result);
4226 result = Dart_LoadScript(url, source, import_map); 4216 result = Dart_LoadScript(url, source);
4227 4217
4228 url = Dart_NewString("library1.dart"); 4218 url = Dart_NewString("library1.dart");
4229 source = Dart_NewString(kLibrary1Chars); 4219 source = Dart_NewString(kLibrary1Chars);
4230 Dart_LoadLibrary(url, source, import_map); 4220 Dart_LoadLibrary(url, source);
4231 4221
4232 url = Dart_NewString("library2.dart"); 4222 url = Dart_NewString("library2.dart");
4233 source = Dart_NewString(kLibrary2Chars); 4223 source = Dart_NewString(kLibrary2Chars);
4234 Dart_LoadLibrary(url, source, import_map); 4224 Dart_LoadLibrary(url, source);
4235 4225
4236 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 4226 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
4237 EXPECT_VALID(result); 4227 EXPECT_VALID(result);
4238 } 4228 }
4239 4229
4240 4230
4241 TEST_CASE(ImportLibrary3) { 4231 TEST_CASE(ImportLibrary3) {
4242 const char* kScriptChars = 4232 const char* kScriptChars =
4243 "#import('library2.dart');" 4233 "#import('library2.dart');"
4244 "#import('library1.dart');" 4234 "#import('library1.dart');"
4245 "var foo_top = 10; // foo has dup def. So should be an error." 4235 "var foo_top = 10; // foo has dup def. So should be an error."
4246 "main() {}"; 4236 "main() {}";
4247 const char* kLibrary1Chars = 4237 const char* kLibrary1Chars =
4248 "#library('library1.dart');" 4238 "#library('library1.dart');"
4249 "var foo;"; 4239 "var foo;";
4250 const char* kLibrary2Chars = 4240 const char* kLibrary2Chars =
4251 "#library('library2.dart');" 4241 "#library('library2.dart');"
4252 "var foo;"; 4242 "var foo;";
4253 Dart_Handle result; 4243 Dart_Handle result;
4254 4244
4255 // Create a test library and Load up a test script in it. 4245 // Create a test library and Load up a test script in it.
4256 Dart_Handle url = Dart_NewString(TestCase::url()); 4246 Dart_Handle url = Dart_NewString(TestCase::url());
4257 Dart_Handle source = Dart_NewString(kScriptChars); 4247 Dart_Handle source = Dart_NewString(kScriptChars);
4258 Dart_Handle import_map = Dart_NewList(0);
4259 result = Dart_SetLibraryTagHandler(library_handler); 4248 result = Dart_SetLibraryTagHandler(library_handler);
4260 EXPECT_VALID(result); 4249 EXPECT_VALID(result);
4261 result = Dart_LoadScript(url, source, import_map); 4250 result = Dart_LoadScript(url, source);
4262 4251
4263 url = Dart_NewString("library2.dart"); 4252 url = Dart_NewString("library2.dart");
4264 source = Dart_NewString(kLibrary2Chars); 4253 source = Dart_NewString(kLibrary2Chars);
4265 Dart_LoadLibrary(url, source, import_map); 4254 Dart_LoadLibrary(url, source);
4266 4255
4267 url = Dart_NewString("library1.dart"); 4256 url = Dart_NewString("library1.dart");
4268 source = Dart_NewString(kLibrary1Chars); 4257 source = Dart_NewString(kLibrary1Chars);
4269 Dart_LoadLibrary(url, source, import_map); 4258 Dart_LoadLibrary(url, source);
4270 4259
4271 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 4260 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
4272 EXPECT(Dart_IsError(result)); 4261 EXPECT(Dart_IsError(result));
4273 EXPECT_STREQ("Duplicate definition : 'foo' is defined in" 4262 EXPECT_STREQ("Duplicate definition : 'foo' is defined in"
4274 " 'library1.dart' and 'library2.dart'\n", 4263 " 'library1.dart' and 'library2.dart'\n",
4275 Dart_GetError(result)); 4264 Dart_GetError(result));
4276 } 4265 }
4277 4266
4278 4267
4279 TEST_CASE(ImportLibrary4) { 4268 TEST_CASE(ImportLibrary4) {
(...skipping 25 matching lines...) Expand all
4305 "#import('libraryF.dart');" 4294 "#import('libraryF.dart');"
4306 "var fooE = 10; //fooC has duplicate def. so should be an error."; 4295 "var fooE = 10; //fooC has duplicate def. so should be an error.";
4307 const char* kLibraryFChars = 4296 const char* kLibraryFChars =
4308 "#library('libraryF.dart');" 4297 "#library('libraryF.dart');"
4309 "var fooC;"; 4298 "var fooC;";
4310 Dart_Handle result; 4299 Dart_Handle result;
4311 4300
4312 // Create a test library and Load up a test script in it. 4301 // Create a test library and Load up a test script in it.
4313 Dart_Handle url = Dart_NewString(TestCase::url()); 4302 Dart_Handle url = Dart_NewString(TestCase::url());
4314 Dart_Handle source = Dart_NewString(kScriptChars); 4303 Dart_Handle source = Dart_NewString(kScriptChars);
4315 Dart_Handle import_map = Dart_NewList(0);
4316 result = Dart_SetLibraryTagHandler(library_handler); 4304 result = Dart_SetLibraryTagHandler(library_handler);
4317 EXPECT_VALID(result); 4305 EXPECT_VALID(result);
4318 result = Dart_LoadScript(url, source, import_map); 4306 result = Dart_LoadScript(url, source);
4319 4307
4320 url = Dart_NewString("libraryA.dart"); 4308 url = Dart_NewString("libraryA.dart");
4321 source = Dart_NewString(kLibraryAChars); 4309 source = Dart_NewString(kLibraryAChars);
4322 Dart_LoadLibrary(url, source, import_map); 4310 Dart_LoadLibrary(url, source);
4323 4311
4324 url = Dart_NewString("libraryC.dart"); 4312 url = Dart_NewString("libraryC.dart");
4325 source = Dart_NewString(kLibraryCChars); 4313 source = Dart_NewString(kLibraryCChars);
4326 Dart_LoadLibrary(url, source, import_map); 4314 Dart_LoadLibrary(url, source);
4327 4315
4328 url = Dart_NewString("libraryB.dart"); 4316 url = Dart_NewString("libraryB.dart");
4329 source = Dart_NewString(kLibraryBChars); 4317 source = Dart_NewString(kLibraryBChars);
4330 Dart_LoadLibrary(url, source, import_map); 4318 Dart_LoadLibrary(url, source);
4331 4319
4332 url = Dart_NewString("libraryD.dart"); 4320 url = Dart_NewString("libraryD.dart");
4333 source = Dart_NewString(kLibraryDChars); 4321 source = Dart_NewString(kLibraryDChars);
4334 Dart_LoadLibrary(url, source, import_map); 4322 Dart_LoadLibrary(url, source);
4335 4323
4336 url = Dart_NewString("libraryF.dart"); 4324 url = Dart_NewString("libraryF.dart");
4337 source = Dart_NewString(kLibraryFChars); 4325 source = Dart_NewString(kLibraryFChars);
4338 Dart_LoadLibrary(url, source, import_map); 4326 Dart_LoadLibrary(url, source);
4339 4327
4340 url = Dart_NewString("libraryE.dart"); 4328 url = Dart_NewString("libraryE.dart");
4341 source = Dart_NewString(kLibraryEChars); 4329 source = Dart_NewString(kLibraryEChars);
4342 Dart_LoadLibrary(url, source, import_map); 4330 Dart_LoadLibrary(url, source);
4343 4331
4344 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 4332 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
4345 EXPECT(Dart_IsError(result)); 4333 EXPECT(Dart_IsError(result));
4346 EXPECT_STREQ("Duplicate definition : 'fooC' is defined in" 4334 EXPECT_STREQ("Duplicate definition : 'fooC' is defined in"
4347 " 'libraryF.dart' and 'libraryC.dart'\n", 4335 " 'libraryF.dart' and 'libraryC.dart'\n",
4348 Dart_GetError(result)); 4336 Dart_GetError(result));
4349 } 4337 }
4350 4338
4351 4339
4352 TEST_CASE(ImportLibrary5) { 4340 TEST_CASE(ImportLibrary5) {
4353 const char* kScriptChars = 4341 const char* kScriptChars =
4354 "#import('lib.dart');" 4342 "#import('lib.dart');"
4355 "interface Y {" 4343 "interface Y {"
4356 " void set handler(void callback(List<int> x));" 4344 " void set handler(void callback(List<int> x));"
4357 "}" 4345 "}"
4358 "void main() {}"; 4346 "void main() {}";
4359 const char* kLibraryChars = 4347 const char* kLibraryChars =
4360 "#library('lib.dart');" 4348 "#library('lib.dart');"
4361 "interface X {" 4349 "interface X {"
4362 " void set handler(void callback(List<int> x));" 4350 " void set handler(void callback(List<int> x));"
4363 "}"; 4351 "}";
4364 Dart_Handle result; 4352 Dart_Handle result;
4365 4353
4366 // Create a test library and Load up a test script in it. 4354 // Create a test library and Load up a test script in it.
4367 Dart_Handle url = Dart_NewString(TestCase::url()); 4355 Dart_Handle url = Dart_NewString(TestCase::url());
4368 Dart_Handle source = Dart_NewString(kScriptChars); 4356 Dart_Handle source = Dart_NewString(kScriptChars);
4369 Dart_Handle import_map = Dart_NewList(0);
4370 result = Dart_SetLibraryTagHandler(library_handler); 4357 result = Dart_SetLibraryTagHandler(library_handler);
4371 EXPECT_VALID(result); 4358 EXPECT_VALID(result);
4372 result = Dart_LoadScript(url, source, import_map); 4359 result = Dart_LoadScript(url, source);
4373 4360
4374 url = Dart_NewString("lib.dart"); 4361 url = Dart_NewString("lib.dart");
4375 source = Dart_NewString(kLibraryChars); 4362 source = Dart_NewString(kLibraryChars);
4376 Dart_LoadLibrary(url, source, import_map); 4363 Dart_LoadLibrary(url, source);
4377 4364
4378 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 4365 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
4379 EXPECT_VALID(result); 4366 EXPECT_VALID(result);
4380 } 4367 }
4381 4368
4382 4369
4383 void NewNativePort_send123(Dart_Port dest_port_id, 4370 void NewNativePort_send123(Dart_Port dest_port_id,
4384 Dart_Port reply_port_id, 4371 Dart_Port reply_port_id,
4385 Dart_CObject *message) { 4372 Dart_CObject *message) {
4386 // Gets a null message. 4373 // Gets a null message.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
4462 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); 4449 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result));
4463 4450
4464 Dart_ExitScope(); 4451 Dart_ExitScope();
4465 4452
4466 // Delete the native ports. 4453 // Delete the native ports.
4467 EXPECT(Dart_CloseNativePort(port_id1)); 4454 EXPECT(Dart_CloseNativePort(port_id1));
4468 EXPECT(Dart_CloseNativePort(port_id2)); 4455 EXPECT(Dart_CloseNativePort(port_id2));
4469 } 4456 }
4470 4457
4471 4458
4472 static bool RunLoopTestCallback(const char* name_prefix, 4459 static bool RunLoopTestCallback(const char* script_name,
4473 void* data, char** error) { 4460 const char* main,
4461 void* data,
4462 char** error) {
4474 const char* kScriptChars = 4463 const char* kScriptChars =
4475 "#import('builtin');\n" 4464 "#import('builtin');\n"
4476 "#import('dart:isolate');\n" 4465 "#import('dart:isolate');\n"
4477 "class MyIsolate extends Isolate {\n" 4466 "class MyIsolate extends Isolate {\n"
4478 " MyIsolate() : super() { }\n" 4467 " MyIsolate() : super() { }\n"
4479 " void main() {\n" 4468 " void main() {\n"
4480 " port.receive((message, replyTo) {\n" 4469 " port.receive((message, replyTo) {\n"
4481 " if (message) {\n" 4470 " if (message) {\n"
4482 " throw new Exception('MakeChildExit');\n" 4471 " throw new Exception('MakeChildExit');\n"
4483 " } else {\n" 4472 " } else {\n"
(...skipping 14 matching lines...) Expand all
4498 "}\n"; 4487 "}\n";
4499 4488
4500 if (Dart_CurrentIsolate() != NULL) { 4489 if (Dart_CurrentIsolate() != NULL) {
4501 Dart_ExitIsolate(); 4490 Dart_ExitIsolate();
4502 } 4491 }
4503 Dart_Isolate isolate = TestCase::CreateTestIsolate(); 4492 Dart_Isolate isolate = TestCase::CreateTestIsolate();
4504 ASSERT(isolate != NULL); 4493 ASSERT(isolate != NULL);
4505 Dart_EnterScope(); 4494 Dart_EnterScope();
4506 Dart_Handle url = Dart_NewString(TestCase::url()); 4495 Dart_Handle url = Dart_NewString(TestCase::url());
4507 Dart_Handle source = Dart_NewString(kScriptChars); 4496 Dart_Handle source = Dart_NewString(kScriptChars);
4508 Dart_Handle import_map = Dart_NewList(0);
4509 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); 4497 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler);
4510 EXPECT_VALID(result); 4498 EXPECT_VALID(result);
4511 Dart_Handle lib = Dart_LoadScript(url, source, import_map); 4499 Dart_Handle lib = Dart_LoadScript(url, source);
4512 EXPECT_VALID(lib); 4500 EXPECT_VALID(lib);
4513 Dart_ExitScope(); 4501 Dart_ExitScope();
4514 return true; 4502 return true;
4515 } 4503 }
4516 4504
4517 4505
4518 // Common code for RunLoop_Success/RunLoop_Failure. 4506 // Common code for RunLoop_Success/RunLoop_Failure.
4519 static void RunLoopTest(bool throw_exception_child, 4507 static void RunLoopTest(bool throw_exception_child,
4520 bool throw_exception_parent) { 4508 bool throw_exception_parent) {
4521 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); 4509 Dart_IsolateCreateCallback saved = Isolate::CreateCallback();
4522 Isolate::SetCreateCallback(RunLoopTestCallback); 4510 Isolate::SetCreateCallback(RunLoopTestCallback);
4523 RunLoopTestCallback(NULL, NULL, NULL); 4511 RunLoopTestCallback(NULL, NULL, NULL, NULL);
4524 4512
4525 Dart_EnterScope(); 4513 Dart_EnterScope();
4526 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); 4514 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url()));
4527 EXPECT_VALID(lib); 4515 EXPECT_VALID(lib);
4528 4516
4529 Dart_Handle result; 4517 Dart_Handle result;
4530 Dart_Handle args[2]; 4518 Dart_Handle args[2];
4531 args[0] = (throw_exception_child ? Dart_True() : Dart_False()); 4519 args[0] = (throw_exception_child ? Dart_True() : Dart_False());
4532 args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); 4520 args[1] = (throw_exception_parent ? Dart_True() : Dart_False());
4533 result = Dart_Invoke(lib, Dart_NewString("main"), 2, args); 4521 result = Dart_Invoke(lib, Dart_NewString("main"), 2, args);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
4597 " Native.markMainEntered();\n" 4585 " Native.markMainEntered();\n"
4598 " while (true) {\n" // Infinite empty loop. 4586 " while (true) {\n" // Infinite empty loop.
4599 " }\n" 4587 " }\n"
4600 "}\n"; 4588 "}\n";
4601 4589
4602 // Tell the other thread that shared_isolate is created. 4590 // Tell the other thread that shared_isolate is created.
4603 Dart_Handle lib; 4591 Dart_Handle lib;
4604 { 4592 {
4605 sync->Enter(); 4593 sync->Enter();
4606 char* error = NULL; 4594 char* error = NULL;
4607 shared_isolate = Dart_CreateIsolate(NULL, NULL, NULL, &error); 4595 shared_isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error);
4608 EXPECT(shared_isolate != NULL); 4596 EXPECT(shared_isolate != NULL);
4609 Dart_EnterScope(); 4597 Dart_EnterScope();
4610 Dart_Handle url = Dart_NewString(TestCase::url()); 4598 Dart_Handle url = Dart_NewString(TestCase::url());
4611 Dart_Handle source = Dart_NewString(kScriptChars); 4599 Dart_Handle source = Dart_NewString(kScriptChars);
4612 Dart_Handle import_map = Dart_NewList(0);
4613 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); 4600 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler);
4614 EXPECT_VALID(result); 4601 EXPECT_VALID(result);
4615 lib = Dart_LoadScript(url, source, import_map); 4602 lib = Dart_LoadScript(url, source);
4616 EXPECT_VALID(lib); 4603 EXPECT_VALID(lib);
4617 result = Dart_SetNativeResolver(lib, &IsolateInterruptTestNativeLookup); 4604 result = Dart_SetNativeResolver(lib, &IsolateInterruptTestNativeLookup);
4618 DART_CHECK_VALID(result); 4605 DART_CHECK_VALID(result);
4619 4606
4620 sync->Notify(); 4607 sync->Notify();
4621 sync->Exit(); 4608 sync->Exit();
4622 } 4609 }
4623 4610
4624 Dart_Handle result = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL); 4611 Dart_Handle result = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL);
4625 EXPECT(Dart_IsError(result)); 4612 EXPECT(Dart_IsError(result));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
4711 // We should have received the expected number of interrupts. 4698 // We should have received the expected number of interrupts.
4712 EXPECT_EQ(kInterruptCount, interrupt_count); 4699 EXPECT_EQ(kInterruptCount, interrupt_count);
4713 4700
4714 // Give the spawned thread enough time to properly exit. 4701 // Give the spawned thread enough time to properly exit.
4715 Isolate::SetInterruptCallback(saved); 4702 Isolate::SetInterruptCallback(saved);
4716 } 4703 }
4717 4704
4718 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 4705 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
4719 4706
4720 } // namespace dart 4707 } // namespace dart
OLDNEW
« runtime/lib/isolate.cc ('K') | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698