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