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

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

Issue 10407042: spawnUri. Take two. This time I'll wait for Anton before committing :-). (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
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/object.h » ('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_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 2297 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2308 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2309 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields")); 2309 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields"));
2310 EXPECT_VALID(cls); 2310 EXPECT_VALID(cls);
2311 Dart_Handle instance = Dart_Invoke(lib, Dart_NewString("test"), 0, NULL); 2311 Dart_Handle instance = Dart_Invoke(lib, Dart_NewString("test"), 0, NULL);
2312 EXPECT_VALID(instance); 2312 EXPECT_VALID(instance);
2313 Dart_Handle name; 2313 Dart_Handle name;
2314 2314
2315 // Load imported lib. 2315 // Load imported lib.
2316 Dart_Handle url = Dart_NewString("library_url"); 2316 Dart_Handle url = Dart_NewString("library_url");
2317 Dart_Handle source = Dart_NewString(kImportedScriptChars); 2317 Dart_Handle source = Dart_NewString(kImportedScriptChars);
2318 Dart_Handle import_map = Dart_NewList(0); 2318 Dart_Handle imported_lib = Dart_LoadLibrary(url, source);
2319 Dart_Handle imported_lib = Dart_LoadLibrary(url, source, import_map);
2320 EXPECT_VALID(imported_lib); 2319 EXPECT_VALID(imported_lib);
2321 Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib); 2320 Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib);
2322 EXPECT_VALID(result); 2321 EXPECT_VALID(result);
2323 result = Dart_Invoke(imported_lib, Dart_NewString("test2"), 0, NULL); 2322 result = Dart_Invoke(imported_lib, Dart_NewString("test2"), 0, NULL);
2324 EXPECT_VALID(result); 2323 EXPECT_VALID(result);
2325 2324
2326 // Instance field. 2325 // Instance field.
2327 name = Dart_NewString("instance_fld"); 2326 name = Dart_NewString("instance_fld");
2328 TestFieldNotFound(lib, name); 2327 TestFieldNotFound(lib, name);
2329 TestFieldNotFound(cls, name); 2328 TestFieldNotFound(cls, name);
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
3271 "void local() {}\n" 3270 "void local() {}\n"
3272 "void _local() {}\n"; 3271 "void _local() {}\n";
3273 const char* kLibrary2Chars = 3272 const char* kLibrary2Chars =
3274 "#library('library2_name');\n" 3273 "#library('library2_name');\n"
3275 "void imported() {}\n" 3274 "void imported() {}\n"
3276 "void _imported() {}\n"; 3275 "void _imported() {}\n";
3277 3276
3278 // Load lib1 3277 // Load lib1
3279 Dart_Handle url = Dart_NewString("library1_url"); 3278 Dart_Handle url = Dart_NewString("library1_url");
3280 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3279 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3281 Dart_Handle import_map = Dart_NewList(0); 3280 Dart_Handle lib1 = Dart_LoadLibrary(url, source);
3282 Dart_Handle lib1 = Dart_LoadLibrary(url, source, import_map);
3283 EXPECT_VALID(lib1); 3281 EXPECT_VALID(lib1);
3284 3282
3285 // Load lib2 3283 // Load lib2
3286 url = Dart_NewString("library2_url"); 3284 url = Dart_NewString("library2_url");
3287 source = Dart_NewString(kLibrary2Chars); 3285 source = Dart_NewString(kLibrary2Chars);
3288 Dart_Handle lib2 = Dart_LoadLibrary(url, source, import_map); 3286 Dart_Handle lib2 = Dart_LoadLibrary(url, source);
3289 EXPECT_VALID(lib2); 3287 EXPECT_VALID(lib2);
3290 3288
3291 // Import lib2 from lib1 3289 // Import lib2 from lib1
3292 Dart_Handle result = Dart_LibraryImportLibrary(lib1, lib2); 3290 Dart_Handle result = Dart_LibraryImportLibrary(lib1, lib2);
3293 EXPECT_VALID(result); 3291 EXPECT_VALID(result);
3294 3292
3295 // We can invoke both private and non-private local functions. 3293 // We can invoke both private and non-private local functions.
3296 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("local"), 0, NULL)); 3294 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("local"), 0, NULL));
3297 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("_local"), 0, NULL)); 3295 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("_local"), 0, NULL));
3298 3296
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
3554 EXPECT(!is_instance); 3552 EXPECT(!is_instance);
3555 3553
3556 // Check that error is returned if null is passed as a class argument. 3554 // Check that error is returned if null is passed as a class argument.
3557 result = Dart_ObjectIsType(null, null, &is_instance); 3555 result = Dart_ObjectIsType(null, null, &is_instance);
3558 EXPECT(Dart_IsError(result)); 3556 EXPECT(Dart_IsError(result));
3559 } 3557 }
3560 3558
3561 3559
3562 static Dart_Handle library_handler(Dart_LibraryTag tag, 3560 static Dart_Handle library_handler(Dart_LibraryTag tag,
3563 Dart_Handle library, 3561 Dart_Handle library,
3564 Dart_Handle url, 3562 Dart_Handle url) {
3565 Dart_Handle import_url_map) {
3566 if (tag == kCanonicalizeUrl) { 3563 if (tag == kCanonicalizeUrl) {
3567 return url; 3564 return url;
3568 } 3565 }
3569 return Api::Success(Isolate::Current()); 3566 return Api::Success(Isolate::Current());
3570 } 3567 }
3571 3568
3572 3569
3573 TEST_CASE(LoadScript) { 3570 TEST_CASE(LoadScript) {
3574 const char* kScriptChars = 3571 const char* kScriptChars =
3575 "main() {" 3572 "main() {"
3576 " return 12345;" 3573 " return 12345;"
3577 "}"; 3574 "}";
3578 Dart_Handle url = Dart_NewString(TestCase::url()); 3575 Dart_Handle url = Dart_NewString(TestCase::url());
3579 Dart_Handle source = Dart_NewString(kScriptChars); 3576 Dart_Handle source = Dart_NewString(kScriptChars);
3580 Dart_Handle error = Dart_Error("incoming error"); 3577 Dart_Handle error = Dart_Error("incoming error");
3581 Dart_Handle result; 3578 Dart_Handle result;
3582 Dart_Handle import_map = Dart_NewList(0);
3583 3579
3584 result = Dart_SetLibraryTagHandler(library_handler); 3580 result = Dart_SetLibraryTagHandler(library_handler);
3585 EXPECT_VALID(result); 3581 EXPECT_VALID(result);
3586 3582
3587 result = Dart_LoadScript(Dart_Null(), source, import_map); 3583 result = Dart_LoadScript(Dart_Null(), source);
3588 EXPECT(Dart_IsError(result)); 3584 EXPECT(Dart_IsError(result));
3589 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.", 3585 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.",
3590 Dart_GetError(result)); 3586 Dart_GetError(result));
3591 3587
3592 result = Dart_LoadScript(Dart_True(), source, import_map); 3588 result = Dart_LoadScript(Dart_True(), source);
3593 EXPECT(Dart_IsError(result)); 3589 EXPECT(Dart_IsError(result));
3594 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be of type String.", 3590 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be of type String.",
3595 Dart_GetError(result)); 3591 Dart_GetError(result));
3596 3592
3597 result = Dart_LoadScript(error, source, import_map); 3593 result = Dart_LoadScript(error, source);
3598 EXPECT(Dart_IsError(result)); 3594 EXPECT(Dart_IsError(result));
3599 EXPECT_STREQ("incoming error", Dart_GetError(result)); 3595 EXPECT_STREQ("incoming error", Dart_GetError(result));
3600 3596
3601 result = Dart_LoadScript(url, Dart_Null(), import_map); 3597 result = Dart_LoadScript(url, Dart_Null());
3602 EXPECT(Dart_IsError(result)); 3598 EXPECT(Dart_IsError(result));
3603 EXPECT_STREQ("Dart_LoadScript expects argument 'source' to be non-null.", 3599 EXPECT_STREQ("Dart_LoadScript expects argument 'source' to be non-null.",
3604 Dart_GetError(result)); 3600 Dart_GetError(result));
3605 3601
3606 result = Dart_LoadScript(url, Dart_True(), import_map); 3602 result = Dart_LoadScript(url, Dart_True());
3607 EXPECT(Dart_IsError(result)); 3603 EXPECT(Dart_IsError(result));
3608 EXPECT_STREQ( 3604 EXPECT_STREQ(
3609 "Dart_LoadScript expects argument 'source' to be of type String.", 3605 "Dart_LoadScript expects argument 'source' to be of type String.",
3610 Dart_GetError(result)); 3606 Dart_GetError(result));
3611 3607
3612 result = Dart_LoadScript(url, error, import_map); 3608 result = Dart_LoadScript(url, error);
3613 EXPECT(Dart_IsError(result)); 3609 EXPECT(Dart_IsError(result));
3614 EXPECT_STREQ("incoming error", Dart_GetError(result)); 3610 EXPECT_STREQ("incoming error", Dart_GetError(result));
3615 3611
3616 // Load a script successfully. 3612 // Load a script successfully.
3617 result = Dart_LoadScript(url, source, import_map); 3613 result = Dart_LoadScript(url, source);
3618 EXPECT_VALID(result); 3614 EXPECT_VALID(result);
3619 3615
3620 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 3616 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
3621 EXPECT_VALID(result); 3617 EXPECT_VALID(result);
3622 EXPECT(Dart_IsInteger(result)); 3618 EXPECT(Dart_IsInteger(result));
3623 int64_t value = 0; 3619 int64_t value = 0;
3624 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); 3620 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
3625 EXPECT_EQ(12345, value); 3621 EXPECT_EQ(12345, value);
3626 3622
3627 // Further calls to LoadScript are errors. 3623 // Further calls to LoadScript are errors.
3628 result = Dart_LoadScript(url, source, import_map); 3624 result = Dart_LoadScript(url, source);
3629 EXPECT(Dart_IsError(result)); 3625 EXPECT(Dart_IsError(result));
3630 EXPECT_STREQ("Dart_LoadScript: " 3626 EXPECT_STREQ("Dart_LoadScript: "
3631 "A script has already been loaded from 'dart:test-lib'.", 3627 "A script has already been loaded from 'dart:test-lib'.",
3632 Dart_GetError(result)); 3628 Dart_GetError(result));
3633 } 3629 }
3634 3630
3635 3631
3636 static const char* var_mapping[] = { 3632 static const char* var_mapping[] = {
3637 "GOOGLE3", ".", 3633 "GOOGLE3", ".",
3638 "ABC", "lala", 3634 "ABC", "lala",
3639 "var1", "", 3635 "var1", "",
3640 "var2", "winner", 3636 "var2", "winner",
3641 }; 3637 };
3642 static int index = 0; 3638 static int index = 0;
3643 3639
3644 3640
3645 static Dart_Handle import_library_handler(Dart_LibraryTag tag, 3641 static Dart_Handle import_library_handler(Dart_LibraryTag tag,
3646 Dart_Handle library, 3642 Dart_Handle library,
3647 Dart_Handle url, 3643 Dart_Handle url) {
3648 Dart_Handle import_url_map) {
3649 if (tag == kCanonicalizeUrl) { 3644 if (tag == kCanonicalizeUrl) {
3650 return url; 3645 return url;
3651 } 3646 }
3652 EXPECT(Dart_IsString(url)); 3647 EXPECT(Dart_IsString(url));
3653 const char* cstr = NULL; 3648 const char* cstr = NULL;
3654 EXPECT_VALID(Dart_StringToCString(url, &cstr)); 3649 EXPECT_VALID(Dart_StringToCString(url, &cstr));
3655 switch (index) { 3650 switch (index) {
3656 case 0: 3651 case 0:
3657 EXPECT_STREQ("./weird.dart", cstr); 3652 EXPECT_STREQ("./weird.dart", cstr);
3658 break; 3653 break;
(...skipping 30 matching lines...) Expand all
3689 "}"; 3684 "}";
3690 Dart_Handle url = Dart_NewString(TestCase::url()); 3685 Dart_Handle url = Dart_NewString(TestCase::url());
3691 Dart_Handle source = Dart_NewString(kScriptChars); 3686 Dart_Handle source = Dart_NewString(kScriptChars);
3692 intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0])); 3687 intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0]));
3693 Dart_Handle import_map = Dart_NewList(length); 3688 Dart_Handle import_map = Dart_NewList(length);
3694 for (intptr_t i = 0; i < length; i++) { 3689 for (intptr_t i = 0; i < length; i++) {
3695 Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i])); 3690 Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i]));
3696 } 3691 }
3697 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); 3692 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler);
3698 EXPECT_VALID(result); 3693 EXPECT_VALID(result);
3699 result = Dart_LoadScript(url, source, import_map); 3694 result = Dart_SetImportMap(import_map);
3695 EXPECT_VALID(result);
3696 result = Dart_LoadScript(url, source);
3700 EXPECT(!Dart_IsError(result)); 3697 EXPECT(!Dart_IsError(result));
3701 } 3698 }
3702 3699
3703 3700
3704 TEST_CASE(LoadImportScriptError1) { 3701 TEST_CASE(LoadImportScriptError1) {
3705 const char* kScriptChars = 3702 const char* kScriptChars =
3706 "#import('abc${DEF}def/extra_weird.dart');" 3703 "#import('abc${DEF}def/extra_weird.dart');"
3707 "main() {" 3704 "main() {"
3708 " return 12345;" 3705 " return 12345;"
3709 "}"; 3706 "}";
3710 Dart_Handle url = Dart_NewString(TestCase::url()); 3707 Dart_Handle url = Dart_NewString(TestCase::url());
3711 Dart_Handle source = Dart_NewString(kScriptChars); 3708 Dart_Handle source = Dart_NewString(kScriptChars);
3712 Dart_Handle import_map = Dart_NewList(0);
3713 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); 3709 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler);
3714 EXPECT_VALID(result); 3710 EXPECT_VALID(result);
3715 result = Dart_LoadScript(url, source, import_map); 3711 result = Dart_LoadScript(url, source);
3716 EXPECT(Dart_IsError(result)); 3712 EXPECT(Dart_IsError(result));
3717 EXPECT(strstr(Dart_GetError(result), 3713 EXPECT(strstr(Dart_GetError(result),
3718 "import variable 'DEF' has not been defined")); 3714 "import variable 'DEF' has not been defined"));
3719 } 3715 }
3720 3716
3721 3717
3722 TEST_CASE(LoadImportScriptError2) { 3718 TEST_CASE(LoadImportScriptError2) {
3723 const char* kScriptChars = 3719 const char* kScriptChars =
3724 "#import('abc${ABC/extra_weird.dart');" 3720 "#import('abc${ABC/extra_weird.dart');"
3725 "main() {" 3721 "main() {"
3726 " return 12345;" 3722 " return 12345;"
3727 "}"; 3723 "}";
3728 Dart_Handle url = Dart_NewString(TestCase::url()); 3724 Dart_Handle url = Dart_NewString(TestCase::url());
3729 Dart_Handle source = Dart_NewString(kScriptChars); 3725 Dart_Handle source = Dart_NewString(kScriptChars);
3730 intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0])); 3726 intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0]));
3731 Dart_Handle import_map = Dart_NewList(length); 3727 Dart_Handle import_map = Dart_NewList(length);
3732 for (intptr_t i = 0; i < length; i++) { 3728 for (intptr_t i = 0; i < length; i++) {
3733 Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i])); 3729 Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i]));
3734 } 3730 }
3735 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); 3731 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler);
3736 EXPECT_VALID(result); 3732 EXPECT_VALID(result);
3737 result = Dart_LoadScript(url, source, import_map); 3733 result = Dart_SetImportMap(import_map);
3734 EXPECT_VALID(result);
3735 result = Dart_LoadScript(url, source);
3738 EXPECT(Dart_IsError(result)); 3736 EXPECT(Dart_IsError(result));
3739 EXPECT(strstr(Dart_GetError(result), "'}' expected")); 3737 EXPECT(strstr(Dart_GetError(result), "'}' expected"));
3740 } 3738 }
3741 3739
3742 3740
3743 TEST_CASE(LoadScript_CompileError) { 3741 TEST_CASE(LoadScript_CompileError) {
3744 const char* kScriptChars = 3742 const char* kScriptChars =
3745 ")"; 3743 ")";
3746 Dart_Handle url = Dart_NewString(TestCase::url()); 3744 Dart_Handle url = Dart_NewString(TestCase::url());
3747 Dart_Handle source = Dart_NewString(kScriptChars); 3745 Dart_Handle source = Dart_NewString(kScriptChars);
3748 Dart_Handle import_map = Dart_NewList(0);
3749 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); 3746 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler);
3750 EXPECT_VALID(result); 3747 EXPECT_VALID(result);
3751 result = Dart_LoadScript(url, source, import_map); 3748 result = Dart_LoadScript(url, source);
3752 EXPECT(Dart_IsError(result)); 3749 EXPECT(Dart_IsError(result));
3753 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); 3750 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'"));
3754 } 3751 }
3755 3752
3756 3753
3757 TEST_CASE(LookupLibrary) { 3754 TEST_CASE(LookupLibrary) {
3758 const char* kScriptChars = 3755 const char* kScriptChars =
3759 "#import('library1.dart');" 3756 "#import('library1.dart');"
3760 "main() {}"; 3757 "main() {}";
3761 const char* kLibrary1Chars = 3758 const char* kLibrary1Chars =
3762 "#library('library1.dart');" 3759 "#library('library1.dart');"
3763 "#import('library2.dart');"; 3760 "#import('library2.dart');";
3764 3761
3765 // Create a test library and Load up a test script in it. 3762 // Create a test library and Load up a test script in it.
3766 Dart_Handle url = Dart_NewString(TestCase::url()); 3763 Dart_Handle url = Dart_NewString(TestCase::url());
3767 Dart_Handle source = Dart_NewString(kScriptChars); 3764 Dart_Handle source = Dart_NewString(kScriptChars);
3768 Dart_Handle import_map = Dart_NewList(0);
3769 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); 3765 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler);
3770 EXPECT_VALID(result); 3766 EXPECT_VALID(result);
3771 result = Dart_LoadScript(url, source, import_map); 3767 result = Dart_LoadScript(url, source);
3772 EXPECT_VALID(result); 3768 EXPECT_VALID(result);
3773 3769
3774 url = Dart_NewString("library1.dart"); 3770 url = Dart_NewString("library1.dart");
3775 source = Dart_NewString(kLibrary1Chars); 3771 source = Dart_NewString(kLibrary1Chars);
3776 result = Dart_LoadLibrary(url, source, import_map); 3772 result = Dart_LoadLibrary(url, source);
3777 EXPECT_VALID(result); 3773 EXPECT_VALID(result);
3778 3774
3779 result = Dart_LookupLibrary(url); 3775 result = Dart_LookupLibrary(url);
3780 EXPECT_VALID(result); 3776 EXPECT_VALID(result);
3781 3777
3782 result = Dart_LookupLibrary(Dart_Null()); 3778 result = Dart_LookupLibrary(Dart_Null());
3783 EXPECT(Dart_IsError(result)); 3779 EXPECT(Dart_IsError(result));
3784 EXPECT_STREQ("Dart_LookupLibrary expects argument 'url' to be non-null.", 3780 EXPECT_STREQ("Dart_LookupLibrary expects argument 'url' to be non-null.",
3785 Dart_GetError(result)); 3781 Dart_GetError(result));
3786 3782
(...skipping 13 matching lines...) Expand all
3800 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", 3796 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.",
3801 Dart_GetError(result)); 3797 Dart_GetError(result));
3802 } 3798 }
3803 3799
3804 3800
3805 TEST_CASE(LibraryUrl) { 3801 TEST_CASE(LibraryUrl) {
3806 const char* kLibrary1Chars = 3802 const char* kLibrary1Chars =
3807 "#library('library1_name');"; 3803 "#library('library1_name');";
3808 Dart_Handle url = Dart_NewString("library1_url"); 3804 Dart_Handle url = Dart_NewString("library1_url");
3809 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3805 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3810 Dart_Handle lib = Dart_LoadLibrary(url, source, Dart_Null()); 3806 Dart_Handle lib = Dart_LoadLibrary(url, source);
3811 Dart_Handle error = Dart_Error("incoming error"); 3807 Dart_Handle error = Dart_Error("incoming error");
3812 EXPECT_VALID(lib); 3808 EXPECT_VALID(lib);
3813 3809
3814 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); 3810 Dart_Handle result = Dart_LibraryUrl(Dart_Null());
3815 EXPECT(Dart_IsError(result)); 3811 EXPECT(Dart_IsError(result));
3816 EXPECT_STREQ("Dart_LibraryUrl expects argument 'library' to be non-null.", 3812 EXPECT_STREQ("Dart_LibraryUrl expects argument 'library' to be non-null.",
3817 Dart_GetError(result)); 3813 Dart_GetError(result));
3818 3814
3819 result = Dart_LibraryUrl(Dart_True()); 3815 result = Dart_LibraryUrl(Dart_True());
3820 EXPECT(Dart_IsError(result)); 3816 EXPECT(Dart_IsError(result));
(...skipping 17 matching lines...) Expand all
3838 TEST_CASE(LibraryImportLibrary) { 3834 TEST_CASE(LibraryImportLibrary) {
3839 const char* kLibrary1Chars = 3835 const char* kLibrary1Chars =
3840 "#library('library1_name');"; 3836 "#library('library1_name');";
3841 const char* kLibrary2Chars = 3837 const char* kLibrary2Chars =
3842 "#library('library2_name');"; 3838 "#library('library2_name');";
3843 Dart_Handle error = Dart_Error("incoming error"); 3839 Dart_Handle error = Dart_Error("incoming error");
3844 Dart_Handle result; 3840 Dart_Handle result;
3845 3841
3846 Dart_Handle url = Dart_NewString("library1_url"); 3842 Dart_Handle url = Dart_NewString("library1_url");
3847 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3843 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3848 Dart_Handle import_map = Dart_NewList(0); 3844 Dart_Handle lib1 = Dart_LoadLibrary(url, source);
3849 Dart_Handle lib1 = Dart_LoadLibrary(url, source, import_map);
3850 EXPECT_VALID(lib1); 3845 EXPECT_VALID(lib1);
3851 3846
3852 url = Dart_NewString("library2_url"); 3847 url = Dart_NewString("library2_url");
3853 source = Dart_NewString(kLibrary2Chars); 3848 source = Dart_NewString(kLibrary2Chars);
3854 Dart_Handle lib2 = Dart_LoadLibrary(url, source, import_map); 3849 Dart_Handle lib2 = Dart_LoadLibrary(url, source);
3855 EXPECT_VALID(lib2); 3850 EXPECT_VALID(lib2);
3856 3851
3857 result = Dart_LibraryImportLibrary(Dart_Null(), lib2); 3852 result = Dart_LibraryImportLibrary(Dart_Null(), lib2);
3858 EXPECT(Dart_IsError(result)); 3853 EXPECT(Dart_IsError(result));
3859 EXPECT_STREQ( 3854 EXPECT_STREQ(
3860 "Dart_LibraryImportLibrary expects argument 'library' to be non-null.", 3855 "Dart_LibraryImportLibrary expects argument 'library' to be non-null.",
3861 Dart_GetError(result)); 3856 Dart_GetError(result));
3862 3857
3863 result = Dart_LibraryImportLibrary(Dart_True(), lib2); 3858 result = Dart_LibraryImportLibrary(Dart_True(), lib2);
3864 EXPECT(Dart_IsError(result)); 3859 EXPECT(Dart_IsError(result));
(...skipping 28 matching lines...) Expand all
3893 3888
3894 3889
3895 TEST_CASE(LoadLibrary) { 3890 TEST_CASE(LoadLibrary) {
3896 const char* kLibrary1Chars = 3891 const char* kLibrary1Chars =
3897 "#library('library1_name');"; 3892 "#library('library1_name');";
3898 Dart_Handle error = Dart_Error("incoming error"); 3893 Dart_Handle error = Dart_Error("incoming error");
3899 Dart_Handle result; 3894 Dart_Handle result;
3900 3895
3901 Dart_Handle url = Dart_NewString("library1_url"); 3896 Dart_Handle url = Dart_NewString("library1_url");
3902 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3897 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3903 Dart_Handle import_map = Dart_NewList(0);
3904 3898
3905 result = Dart_LoadLibrary(Dart_Null(), source, import_map); 3899 result = Dart_LoadLibrary(Dart_Null(), source);
3906 EXPECT(Dart_IsError(result)); 3900 EXPECT(Dart_IsError(result));
3907 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.", 3901 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.",
3908 Dart_GetError(result)); 3902 Dart_GetError(result));
3909 3903
3910 result = Dart_LoadLibrary(Dart_True(), source, import_map); 3904 result = Dart_LoadLibrary(Dart_True(), source);
3911 EXPECT(Dart_IsError(result)); 3905 EXPECT(Dart_IsError(result));
3912 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be of type String.", 3906 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be of type String.",
3913 Dart_GetError(result)); 3907 Dart_GetError(result));
3914 3908
3915 result = Dart_LoadLibrary(error, source, import_map); 3909 result = Dart_LoadLibrary(error, source);
3916 EXPECT(Dart_IsError(result)); 3910 EXPECT(Dart_IsError(result));
3917 EXPECT_STREQ("incoming error", Dart_GetError(result)); 3911 EXPECT_STREQ("incoming error", Dart_GetError(result));
3918 3912
3919 result = Dart_LoadLibrary(url, Dart_Null(), import_map); 3913 result = Dart_LoadLibrary(url, Dart_Null());
3920 EXPECT(Dart_IsError(result)); 3914 EXPECT(Dart_IsError(result));
3921 EXPECT_STREQ("Dart_LoadLibrary expects argument 'source' to be non-null.", 3915 EXPECT_STREQ("Dart_LoadLibrary expects argument 'source' to be non-null.",
3922 Dart_GetError(result)); 3916 Dart_GetError(result));
3923 3917
3924 result = Dart_LoadLibrary(url, Dart_True(), import_map); 3918 result = Dart_LoadLibrary(url, Dart_True());
3925 EXPECT(Dart_IsError(result)); 3919 EXPECT(Dart_IsError(result));
3926 EXPECT_STREQ( 3920 EXPECT_STREQ(
3927 "Dart_LoadLibrary expects argument 'source' to be of type String.", 3921 "Dart_LoadLibrary expects argument 'source' to be of type String.",
3928 Dart_GetError(result)); 3922 Dart_GetError(result));
3929 3923
3930 result = Dart_LoadLibrary(url, error, import_map); 3924 result = Dart_LoadLibrary(url, error);
3931 EXPECT(Dart_IsError(result)); 3925 EXPECT(Dart_IsError(result));
3932 EXPECT_STREQ("incoming error", Dart_GetError(result)); 3926 EXPECT_STREQ("incoming error", Dart_GetError(result));
3933 3927
3934 // Success. 3928 // Success.
3935 result = Dart_LoadLibrary(url, source, import_map); 3929 result = Dart_LoadLibrary(url, source);
3936 EXPECT_VALID(result); 3930 EXPECT_VALID(result);
3937 EXPECT(Dart_IsLibrary(result)); 3931 EXPECT(Dart_IsLibrary(result));
3938 3932
3939 // Duplicate library load fails. 3933 // Duplicate library load fails.
3940 result = Dart_LoadLibrary(url, source, import_map); 3934 result = Dart_LoadLibrary(url, source);
3941 EXPECT(Dart_IsError(result)); 3935 EXPECT(Dart_IsError(result));
3942 EXPECT_STREQ( 3936 EXPECT_STREQ(
3943 "Dart_LoadLibrary: library 'library1_url' has already been loaded.", 3937 "Dart_LoadLibrary: library 'library1_url' has already been loaded.",
3944 Dart_GetError(result)); 3938 Dart_GetError(result));
3945 } 3939 }
3946 3940
3947 3941
3948 TEST_CASE(LoadLibrary_CompileError) { 3942 TEST_CASE(LoadLibrary_CompileError) {
3949 const char* kLibrary1Chars = 3943 const char* kLibrary1Chars =
3950 "#library('library1_name');" 3944 "#library('library1_name');"
3951 ")"; 3945 ")";
3952 Dart_Handle url = Dart_NewString("library1_url"); 3946 Dart_Handle url = Dart_NewString("library1_url");
3953 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3947 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3954 Dart_Handle import_map = Dart_NewList(0); 3948 Dart_Handle result = Dart_LoadLibrary(url, source);
3955 Dart_Handle result = Dart_LoadLibrary(url, source, import_map);
3956 EXPECT(Dart_IsError(result)); 3949 EXPECT(Dart_IsError(result));
3957 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); 3950 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'"));
3958 } 3951 }
3959 3952
3960 3953
3961 TEST_CASE(LoadSource) { 3954 TEST_CASE(LoadSource) {
3962 const char* kLibrary1Chars = 3955 const char* kLibrary1Chars =
3963 "#library('library1_name');"; 3956 "#library('library1_name');";
3964 const char* kSourceChars = 3957 const char* kSourceChars =
3965 "// Something innocuous"; 3958 "// Something innocuous";
3966 const char* kBadSourceChars = 3959 const char* kBadSourceChars =
3967 ")"; 3960 ")";
3968 Dart_Handle error = Dart_Error("incoming error"); 3961 Dart_Handle error = Dart_Error("incoming error");
3969 Dart_Handle result; 3962 Dart_Handle result;
3970 3963
3971 // Load up a library. 3964 // Load up a library.
3972 Dart_Handle url = Dart_NewString("library1_url"); 3965 Dart_Handle url = Dart_NewString("library1_url");
3973 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3966 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3974 Dart_Handle import_map = Dart_NewList(0); 3967 Dart_Handle lib = Dart_LoadLibrary(url, source);
3975 Dart_Handle lib = Dart_LoadLibrary(url, source, import_map);
3976 EXPECT_VALID(lib); 3968 EXPECT_VALID(lib);
3977 EXPECT(Dart_IsLibrary(lib)); 3969 EXPECT(Dart_IsLibrary(lib));
3978 3970
3979 url = Dart_NewString("source_url"); 3971 url = Dart_NewString("source_url");
3980 source = Dart_NewString(kSourceChars); 3972 source = Dart_NewString(kSourceChars);
3981 3973
3982 result = Dart_LoadSource(Dart_Null(), url, source); 3974 result = Dart_LoadSource(Dart_Null(), url, source);
3983 EXPECT(Dart_IsError(result)); 3975 EXPECT(Dart_IsError(result));
3984 EXPECT_STREQ("Dart_LoadSource expects argument 'library' to be non-null.", 3976 EXPECT_STREQ("Dart_LoadSource expects argument 'library' to be non-null.",
3985 Dart_GetError(result)); 3977 Dart_GetError(result));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
4074 " static foo() native \"SomeNativeFunction\";" 4066 " static foo() native \"SomeNativeFunction\";"
4075 " static bar() native \"SomeNativeFunction2\";" 4067 " static bar() native \"SomeNativeFunction2\";"
4076 " static baz() native \"SomeNativeFunction3\";" 4068 " static baz() native \"SomeNativeFunction3\";"
4077 "}"; 4069 "}";
4078 Dart_Handle error = Dart_Error("incoming error"); 4070 Dart_Handle error = Dart_Error("incoming error");
4079 Dart_Handle result; 4071 Dart_Handle result;
4080 4072
4081 // Load a test script. 4073 // Load a test script.
4082 Dart_Handle url = Dart_NewString(TestCase::url()); 4074 Dart_Handle url = Dart_NewString(TestCase::url());
4083 Dart_Handle source = Dart_NewString(kScriptChars); 4075 Dart_Handle source = Dart_NewString(kScriptChars);
4084 Dart_Handle import_map = Dart_NewList(0);
4085 result = Dart_SetLibraryTagHandler(library_handler); 4076 result = Dart_SetLibraryTagHandler(library_handler);
4086 EXPECT_VALID(result); 4077 EXPECT_VALID(result);
4087 Dart_Handle lib = Dart_LoadScript(url, source, import_map); 4078 Dart_Handle lib = Dart_LoadScript(url, source);
4088 EXPECT_VALID(lib); 4079 EXPECT_VALID(lib);
4089 EXPECT(Dart_IsLibrary(lib)); 4080 EXPECT(Dart_IsLibrary(lib));
4090 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Test")); 4081 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Test"));
4091 EXPECT_VALID(cls); 4082 EXPECT_VALID(cls);
4092 4083
4093 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1); 4084 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1);
4094 EXPECT(Dart_IsError(result)); 4085 EXPECT(Dart_IsError(result));
4095 EXPECT_STREQ( 4086 EXPECT_STREQ(
4096 "Dart_SetNativeResolver expects argument 'library' to be non-null.", 4087 "Dart_SetNativeResolver expects argument 'library' to be non-null.",
4097 Dart_GetError(result)); 4088 Dart_GetError(result));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
4158 "var foo1;"; 4149 "var foo1;";
4159 const char* kLibrary2Chars = 4150 const char* kLibrary2Chars =
4160 "#library('library2.dart');" 4151 "#library('library2.dart');"
4161 "var foo;"; 4152 "var foo;";
4162 Dart_Handle result; 4153 Dart_Handle result;
4163 // Create a test library and Load up a test script in it. 4154 // Create a test library and Load up a test script in it.
4164 Dart_Handle url = Dart_NewString(TestCase::url()); 4155 Dart_Handle url = Dart_NewString(TestCase::url());
4165 Dart_Handle source = Dart_NewString(kScriptChars); 4156 Dart_Handle source = Dart_NewString(kScriptChars);
4166 result = Dart_SetLibraryTagHandler(library_handler); 4157 result = Dart_SetLibraryTagHandler(library_handler);
4167 EXPECT_VALID(result); 4158 EXPECT_VALID(result);
4168 result = Dart_LoadScript(url, source, Dart_Null()); 4159 result = Dart_LoadScript(url, source);
4169 4160
4170 url = Dart_NewString("library1.dart"); 4161 url = Dart_NewString("library1.dart");
4171 source = Dart_NewString(kLibrary1Chars); 4162 source = Dart_NewString(kLibrary1Chars);
4172 Dart_LoadLibrary(url, source, Dart_Null()); 4163 Dart_LoadLibrary(url, source);
4173 4164
4174 url = Dart_NewString("library2.dart"); 4165 url = Dart_NewString("library2.dart");
4175 source = Dart_NewString(kLibrary2Chars); 4166 source = Dart_NewString(kLibrary2Chars);
4176 Dart_LoadLibrary(url, source, Dart_Null()); 4167 Dart_LoadLibrary(url, source);
4177 4168
4178 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 4169 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
4179 EXPECT(Dart_IsError(result)); 4170 EXPECT(Dart_IsError(result));
4180 EXPECT_STREQ("Duplicate definition : 'foo' is defined in" 4171 EXPECT_STREQ("Duplicate definition : 'foo' is defined in"
4181 " 'library2.dart' and 'dart:test-lib'\n", 4172 " 'library2.dart' and 'dart:test-lib'\n",
4182 Dart_GetError(result)); 4173 Dart_GetError(result));
4183 } 4174 }
4184 4175
4185 4176
4186 TEST_CASE(ImportLibrary2) { 4177 TEST_CASE(ImportLibrary2) {
4187 const char* kScriptChars = 4178 const char* kScriptChars =
4188 "#import('library1.dart');" 4179 "#import('library1.dart');"
4189 "var foo;" 4180 "var foo;"
4190 "main() {}"; 4181 "main() {}";
4191 const char* kLibrary1Chars = 4182 const char* kLibrary1Chars =
4192 "#library('library1.dart');" 4183 "#library('library1.dart');"
4193 "#import('library2.dart');" 4184 "#import('library2.dart');"
4194 "var foo1;"; 4185 "var foo1;";
4195 const char* kLibrary2Chars = 4186 const char* kLibrary2Chars =
4196 "#library('library2.dart');" 4187 "#library('library2.dart');"
4197 "#import('library1.dart');" 4188 "#import('library1.dart');"
4198 "var foo;"; 4189 "var foo;";
4199 Dart_Handle result; 4190 Dart_Handle result;
4200 // Create a test library and Load up a test script in it. 4191 // Create a test library and Load up a test script in it.
4201 Dart_Handle url = Dart_NewString(TestCase::url()); 4192 Dart_Handle url = Dart_NewString(TestCase::url());
4202 Dart_Handle source = Dart_NewString(kScriptChars); 4193 Dart_Handle source = Dart_NewString(kScriptChars);
4203 Dart_Handle import_map = Dart_NewList(0);
4204 result = Dart_SetLibraryTagHandler(library_handler); 4194 result = Dart_SetLibraryTagHandler(library_handler);
4205 EXPECT_VALID(result); 4195 EXPECT_VALID(result);
4206 result = Dart_LoadScript(url, source, import_map); 4196 result = Dart_LoadScript(url, source);
4207 4197
4208 url = Dart_NewString("library1.dart"); 4198 url = Dart_NewString("library1.dart");
4209 source = Dart_NewString(kLibrary1Chars); 4199 source = Dart_NewString(kLibrary1Chars);
4210 Dart_LoadLibrary(url, source, import_map); 4200 Dart_LoadLibrary(url, source);
4211 4201
4212 url = Dart_NewString("library2.dart"); 4202 url = Dart_NewString("library2.dart");
4213 source = Dart_NewString(kLibrary2Chars); 4203 source = Dart_NewString(kLibrary2Chars);
4214 Dart_LoadLibrary(url, source, import_map); 4204 Dart_LoadLibrary(url, source);
4215 4205
4216 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 4206 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
4217 EXPECT_VALID(result); 4207 EXPECT_VALID(result);
4218 } 4208 }
4219 4209
4220 4210
4221 TEST_CASE(ImportLibrary3) { 4211 TEST_CASE(ImportLibrary3) {
4222 const char* kScriptChars = 4212 const char* kScriptChars =
4223 "#import('library2.dart');" 4213 "#import('library2.dart');"
4224 "#import('library1.dart');" 4214 "#import('library1.dart');"
4225 "var foo_top = 10; // foo has dup def. So should be an error." 4215 "var foo_top = 10; // foo has dup def. So should be an error."
4226 "main() {}"; 4216 "main() {}";
4227 const char* kLibrary1Chars = 4217 const char* kLibrary1Chars =
4228 "#library('library1.dart');" 4218 "#library('library1.dart');"
4229 "var foo;"; 4219 "var foo;";
4230 const char* kLibrary2Chars = 4220 const char* kLibrary2Chars =
4231 "#library('library2.dart');" 4221 "#library('library2.dart');"
4232 "var foo;"; 4222 "var foo;";
4233 Dart_Handle result; 4223 Dart_Handle result;
4234 4224
4235 // Create a test library and Load up a test script in it. 4225 // Create a test library and Load up a test script in it.
4236 Dart_Handle url = Dart_NewString(TestCase::url()); 4226 Dart_Handle url = Dart_NewString(TestCase::url());
4237 Dart_Handle source = Dart_NewString(kScriptChars); 4227 Dart_Handle source = Dart_NewString(kScriptChars);
4238 Dart_Handle import_map = Dart_NewList(0);
4239 result = Dart_SetLibraryTagHandler(library_handler); 4228 result = Dart_SetLibraryTagHandler(library_handler);
4240 EXPECT_VALID(result); 4229 EXPECT_VALID(result);
4241 result = Dart_LoadScript(url, source, import_map); 4230 result = Dart_LoadScript(url, source);
4242 4231
4243 url = Dart_NewString("library2.dart"); 4232 url = Dart_NewString("library2.dart");
4244 source = Dart_NewString(kLibrary2Chars); 4233 source = Dart_NewString(kLibrary2Chars);
4245 Dart_LoadLibrary(url, source, import_map); 4234 Dart_LoadLibrary(url, source);
4246 4235
4247 url = Dart_NewString("library1.dart"); 4236 url = Dart_NewString("library1.dart");
4248 source = Dart_NewString(kLibrary1Chars); 4237 source = Dart_NewString(kLibrary1Chars);
4249 Dart_LoadLibrary(url, source, import_map); 4238 Dart_LoadLibrary(url, source);
4250 4239
4251 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 4240 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
4252 EXPECT(Dart_IsError(result)); 4241 EXPECT(Dart_IsError(result));
4253 EXPECT_STREQ("Duplicate definition : 'foo' is defined in" 4242 EXPECT_STREQ("Duplicate definition : 'foo' is defined in"
4254 " 'library1.dart' and 'library2.dart'\n", 4243 " 'library1.dart' and 'library2.dart'\n",
4255 Dart_GetError(result)); 4244 Dart_GetError(result));
4256 } 4245 }
4257 4246
4258 4247
4259 TEST_CASE(ImportLibrary4) { 4248 TEST_CASE(ImportLibrary4) {
(...skipping 25 matching lines...) Expand all
4285 "#import('libraryF.dart');" 4274 "#import('libraryF.dart');"
4286 "var fooE = 10; //fooC has duplicate def. so should be an error."; 4275 "var fooE = 10; //fooC has duplicate def. so should be an error.";
4287 const char* kLibraryFChars = 4276 const char* kLibraryFChars =
4288 "#library('libraryF.dart');" 4277 "#library('libraryF.dart');"
4289 "var fooC;"; 4278 "var fooC;";
4290 Dart_Handle result; 4279 Dart_Handle result;
4291 4280
4292 // Create a test library and Load up a test script in it. 4281 // Create a test library and Load up a test script in it.
4293 Dart_Handle url = Dart_NewString(TestCase::url()); 4282 Dart_Handle url = Dart_NewString(TestCase::url());
4294 Dart_Handle source = Dart_NewString(kScriptChars); 4283 Dart_Handle source = Dart_NewString(kScriptChars);
4295 Dart_Handle import_map = Dart_NewList(0);
4296 result = Dart_SetLibraryTagHandler(library_handler); 4284 result = Dart_SetLibraryTagHandler(library_handler);
4297 EXPECT_VALID(result); 4285 EXPECT_VALID(result);
4298 result = Dart_LoadScript(url, source, import_map); 4286 result = Dart_LoadScript(url, source);
4299 4287
4300 url = Dart_NewString("libraryA.dart"); 4288 url = Dart_NewString("libraryA.dart");
4301 source = Dart_NewString(kLibraryAChars); 4289 source = Dart_NewString(kLibraryAChars);
4302 Dart_LoadLibrary(url, source, import_map); 4290 Dart_LoadLibrary(url, source);
4303 4291
4304 url = Dart_NewString("libraryC.dart"); 4292 url = Dart_NewString("libraryC.dart");
4305 source = Dart_NewString(kLibraryCChars); 4293 source = Dart_NewString(kLibraryCChars);
4306 Dart_LoadLibrary(url, source, import_map); 4294 Dart_LoadLibrary(url, source);
4307 4295
4308 url = Dart_NewString("libraryB.dart"); 4296 url = Dart_NewString("libraryB.dart");
4309 source = Dart_NewString(kLibraryBChars); 4297 source = Dart_NewString(kLibraryBChars);
4310 Dart_LoadLibrary(url, source, import_map); 4298 Dart_LoadLibrary(url, source);
4311 4299
4312 url = Dart_NewString("libraryD.dart"); 4300 url = Dart_NewString("libraryD.dart");
4313 source = Dart_NewString(kLibraryDChars); 4301 source = Dart_NewString(kLibraryDChars);
4314 Dart_LoadLibrary(url, source, import_map); 4302 Dart_LoadLibrary(url, source);
4315 4303
4316 url = Dart_NewString("libraryF.dart"); 4304 url = Dart_NewString("libraryF.dart");
4317 source = Dart_NewString(kLibraryFChars); 4305 source = Dart_NewString(kLibraryFChars);
4318 Dart_LoadLibrary(url, source, import_map); 4306 Dart_LoadLibrary(url, source);
4319 4307
4320 url = Dart_NewString("libraryE.dart"); 4308 url = Dart_NewString("libraryE.dart");
4321 source = Dart_NewString(kLibraryEChars); 4309 source = Dart_NewString(kLibraryEChars);
4322 Dart_LoadLibrary(url, source, import_map); 4310 Dart_LoadLibrary(url, source);
4323 4311
4324 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 4312 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
4325 EXPECT(Dart_IsError(result)); 4313 EXPECT(Dart_IsError(result));
4326 EXPECT_STREQ("Duplicate definition : 'fooC' is defined in" 4314 EXPECT_STREQ("Duplicate definition : 'fooC' is defined in"
4327 " 'libraryF.dart' and 'libraryC.dart'\n", 4315 " 'libraryF.dart' and 'libraryC.dart'\n",
4328 Dart_GetError(result)); 4316 Dart_GetError(result));
4329 } 4317 }
4330 4318
4331 4319
4332 TEST_CASE(ImportLibrary5) { 4320 TEST_CASE(ImportLibrary5) {
4333 const char* kScriptChars = 4321 const char* kScriptChars =
4334 "#import('lib.dart');" 4322 "#import('lib.dart');"
4335 "interface Y {" 4323 "interface Y {"
4336 " void set handler(void callback(List<int> x));" 4324 " void set handler(void callback(List<int> x));"
4337 "}" 4325 "}"
4338 "void main() {}"; 4326 "void main() {}";
4339 const char* kLibraryChars = 4327 const char* kLibraryChars =
4340 "#library('lib.dart');" 4328 "#library('lib.dart');"
4341 "interface X {" 4329 "interface X {"
4342 " void set handler(void callback(List<int> x));" 4330 " void set handler(void callback(List<int> x));"
4343 "}"; 4331 "}";
4344 Dart_Handle result; 4332 Dart_Handle result;
4345 4333
4346 // Create a test library and Load up a test script in it. 4334 // Create a test library and Load up a test script in it.
4347 Dart_Handle url = Dart_NewString(TestCase::url()); 4335 Dart_Handle url = Dart_NewString(TestCase::url());
4348 Dart_Handle source = Dart_NewString(kScriptChars); 4336 Dart_Handle source = Dart_NewString(kScriptChars);
4349 Dart_Handle import_map = Dart_NewList(0);
4350 result = Dart_SetLibraryTagHandler(library_handler); 4337 result = Dart_SetLibraryTagHandler(library_handler);
4351 EXPECT_VALID(result); 4338 EXPECT_VALID(result);
4352 result = Dart_LoadScript(url, source, import_map); 4339 result = Dart_LoadScript(url, source);
4353 4340
4354 url = Dart_NewString("lib.dart"); 4341 url = Dart_NewString("lib.dart");
4355 source = Dart_NewString(kLibraryChars); 4342 source = Dart_NewString(kLibraryChars);
4356 Dart_LoadLibrary(url, source, import_map); 4343 Dart_LoadLibrary(url, source);
4357 4344
4358 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); 4345 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL);
4359 EXPECT_VALID(result); 4346 EXPECT_VALID(result);
4360 } 4347 }
4361 4348
4362 4349
4363 void NewNativePort_send123(Dart_Port dest_port_id, 4350 void NewNativePort_send123(Dart_Port dest_port_id,
4364 Dart_Port reply_port_id, 4351 Dart_Port reply_port_id,
4365 Dart_CObject *message) { 4352 Dart_CObject *message) {
4366 // Gets a null message. 4353 // Gets a null message.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
4442 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); 4429 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result));
4443 4430
4444 Dart_ExitScope(); 4431 Dart_ExitScope();
4445 4432
4446 // Delete the native ports. 4433 // Delete the native ports.
4447 EXPECT(Dart_CloseNativePort(port_id1)); 4434 EXPECT(Dart_CloseNativePort(port_id1));
4448 EXPECT(Dart_CloseNativePort(port_id2)); 4435 EXPECT(Dart_CloseNativePort(port_id2));
4449 } 4436 }
4450 4437
4451 4438
4452 static bool RunLoopTestCallback(const char* name_prefix, 4439 static bool RunLoopTestCallback(const char* script_name,
4453 void* data, char** error) { 4440 const char* main,
4441 void* data,
4442 char** error) {
4454 const char* kScriptChars = 4443 const char* kScriptChars =
4455 "#import('builtin');\n" 4444 "#import('builtin');\n"
4456 "#import('dart:isolate');\n" 4445 "#import('dart:isolate');\n"
4457 "class MyIsolate extends Isolate {\n" 4446 "class MyIsolate extends Isolate {\n"
4458 " MyIsolate() : super() { }\n" 4447 " MyIsolate() : super() { }\n"
4459 " void main() {\n" 4448 " void main() {\n"
4460 " port.receive((message, replyTo) {\n" 4449 " port.receive((message, replyTo) {\n"
4461 " if (message) {\n" 4450 " if (message) {\n"
4462 " throw new Exception('MakeChildExit');\n" 4451 " throw new Exception('MakeChildExit');\n"
4463 " } else {\n" 4452 " } else {\n"
(...skipping 14 matching lines...) Expand all
4478 "}\n"; 4467 "}\n";
4479 4468
4480 if (Dart_CurrentIsolate() != NULL) { 4469 if (Dart_CurrentIsolate() != NULL) {
4481 Dart_ExitIsolate(); 4470 Dart_ExitIsolate();
4482 } 4471 }
4483 Dart_Isolate isolate = TestCase::CreateTestIsolate(); 4472 Dart_Isolate isolate = TestCase::CreateTestIsolate();
4484 ASSERT(isolate != NULL); 4473 ASSERT(isolate != NULL);
4485 Dart_EnterScope(); 4474 Dart_EnterScope();
4486 Dart_Handle url = Dart_NewString(TestCase::url()); 4475 Dart_Handle url = Dart_NewString(TestCase::url());
4487 Dart_Handle source = Dart_NewString(kScriptChars); 4476 Dart_Handle source = Dart_NewString(kScriptChars);
4488 Dart_Handle import_map = Dart_NewList(0);
4489 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); 4477 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler);
4490 EXPECT_VALID(result); 4478 EXPECT_VALID(result);
4491 Dart_Handle lib = Dart_LoadScript(url, source, import_map); 4479 Dart_Handle lib = Dart_LoadScript(url, source);
4492 EXPECT_VALID(lib); 4480 EXPECT_VALID(lib);
4493 Dart_ExitScope(); 4481 Dart_ExitScope();
4494 return true; 4482 return true;
4495 } 4483 }
4496 4484
4497 4485
4498 // Common code for RunLoop_Success/RunLoop_Failure. 4486 // Common code for RunLoop_Success/RunLoop_Failure.
4499 static void RunLoopTest(bool throw_exception_child, 4487 static void RunLoopTest(bool throw_exception_child,
4500 bool throw_exception_parent) { 4488 bool throw_exception_parent) {
4501 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); 4489 Dart_IsolateCreateCallback saved = Isolate::CreateCallback();
4502 Isolate::SetCreateCallback(RunLoopTestCallback); 4490 Isolate::SetCreateCallback(RunLoopTestCallback);
4503 RunLoopTestCallback(NULL, NULL, NULL); 4491 RunLoopTestCallback(NULL, NULL, NULL, NULL);
4504 4492
4505 Dart_EnterScope(); 4493 Dart_EnterScope();
4506 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); 4494 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url()));
4507 EXPECT_VALID(lib); 4495 EXPECT_VALID(lib);
4508 4496
4509 Dart_Handle result; 4497 Dart_Handle result;
4510 Dart_Handle args[2]; 4498 Dart_Handle args[2];
4511 args[0] = (throw_exception_child ? Dart_True() : Dart_False()); 4499 args[0] = (throw_exception_child ? Dart_True() : Dart_False());
4512 args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); 4500 args[1] = (throw_exception_parent ? Dart_True() : Dart_False());
4513 result = Dart_Invoke(lib, Dart_NewString("main"), 2, args); 4501 result = Dart_Invoke(lib, Dart_NewString("main"), 2, args);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
4577 " Native.markMainEntered();\n" 4565 " Native.markMainEntered();\n"
4578 " while (true) {\n" // Infinite empty loop. 4566 " while (true) {\n" // Infinite empty loop.
4579 " }\n" 4567 " }\n"
4580 "}\n"; 4568 "}\n";
4581 4569
4582 // Tell the other thread that shared_isolate is created. 4570 // Tell the other thread that shared_isolate is created.
4583 Dart_Handle lib; 4571 Dart_Handle lib;
4584 { 4572 {
4585 sync->Enter(); 4573 sync->Enter();
4586 char* error = NULL; 4574 char* error = NULL;
4587 shared_isolate = Dart_CreateIsolate(NULL, NULL, NULL, &error); 4575 shared_isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error);
4588 EXPECT(shared_isolate != NULL); 4576 EXPECT(shared_isolate != NULL);
4589 Dart_EnterScope(); 4577 Dart_EnterScope();
4590 Dart_Handle url = Dart_NewString(TestCase::url()); 4578 Dart_Handle url = Dart_NewString(TestCase::url());
4591 Dart_Handle source = Dart_NewString(kScriptChars); 4579 Dart_Handle source = Dart_NewString(kScriptChars);
4592 Dart_Handle import_map = Dart_NewList(0);
4593 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); 4580 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler);
4594 EXPECT_VALID(result); 4581 EXPECT_VALID(result);
4595 lib = Dart_LoadScript(url, source, import_map); 4582 lib = Dart_LoadScript(url, source);
4596 EXPECT_VALID(lib); 4583 EXPECT_VALID(lib);
4597 result = Dart_SetNativeResolver(lib, &IsolateInterruptTestNativeLookup); 4584 result = Dart_SetNativeResolver(lib, &IsolateInterruptTestNativeLookup);
4598 DART_CHECK_VALID(result); 4585 DART_CHECK_VALID(result);
4599 4586
4600 sync->Notify(); 4587 sync->Notify();
4601 sync->Exit(); 4588 sync->Exit();
4602 } 4589 }
4603 4590
4604 Dart_Handle result = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL); 4591 Dart_Handle result = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL);
4605 EXPECT(Dart_IsError(result)); 4592 EXPECT(Dart_IsError(result));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
4691 // We should have received the expected number of interrupts. 4678 // We should have received the expected number of interrupts.
4692 EXPECT_EQ(kInterruptCount, interrupt_count); 4679 EXPECT_EQ(kInterruptCount, interrupt_count);
4693 4680
4694 // Give the spawned thread enough time to properly exit. 4681 // Give the spawned thread enough time to properly exit.
4695 Isolate::SetInterruptCallback(saved); 4682 Isolate::SetInterruptCallback(saved);
4696 } 4683 }
4697 4684
4698 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 4685 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
4699 4686
4700 } // namespace dart 4687 } // namespace dart
OLDNEW
« no previous file with comments | « 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