OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "bin/builtin.h" | 5 #include "bin/builtin.h" |
6 #include "vm/compiler.h" | 6 #include "vm/compiler.h" |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
(...skipping 3560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3571 free(err); | 3571 free(err); |
3572 } | 3572 } |
3573 EXPECT(isolate != NULL); | 3573 EXPECT(isolate != NULL); |
3574 | 3574 |
3575 { | 3575 { |
3576 Dart_EnterScope(); | 3576 Dart_EnterScope(); |
3577 Dart_Handle url = NewString(TestCase::url()); | 3577 Dart_Handle url = NewString(TestCase::url()); |
3578 Dart_Handle source = NewString(kScriptChars); | 3578 Dart_Handle source = NewString(kScriptChars); |
3579 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | 3579 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
3580 EXPECT_VALID(result); | 3580 EXPECT_VALID(result); |
3581 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); | 3581 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
3582 EXPECT_VALID(lib); | 3582 EXPECT_VALID(lib); |
3583 result = Dart_FinalizeLoading(false); | 3583 result = Dart_FinalizeLoading(false); |
3584 EXPECT_VALID(result); | 3584 EXPECT_VALID(result); |
3585 result = Dart_Invoke(lib, NewString("bad1"), 0, NULL); | 3585 result = Dart_Invoke(lib, NewString("bad1"), 0, NULL); |
3586 EXPECT_ERROR(result, "Unhandled exception:\n" | 3586 EXPECT_ERROR(result, "Unhandled exception:\n" |
3587 "type 'String' is not a subtype of type 'int' of 'foo'"); | 3587 "type 'String' is not a subtype of type 'int' of 'foo'"); |
3588 | 3588 |
3589 result = Dart_Invoke(lib, NewString("good1"), 0, NULL); | 3589 result = Dart_Invoke(lib, NewString("good1"), 0, NULL); |
3590 EXPECT_VALID(result); | 3590 EXPECT_VALID(result); |
3591 Dart_ExitScope(); | 3591 Dart_ExitScope(); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3954 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3954 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3955 Dart_Handle type = Dart_GetType(lib, NewString("Fields"), 0, NULL); | 3955 Dart_Handle type = Dart_GetType(lib, NewString("Fields"), 0, NULL); |
3956 EXPECT_VALID(type); | 3956 EXPECT_VALID(type); |
3957 Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL); | 3957 Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL); |
3958 EXPECT_VALID(instance); | 3958 EXPECT_VALID(instance); |
3959 Dart_Handle name; | 3959 Dart_Handle name; |
3960 | 3960 |
3961 // Load imported lib. | 3961 // Load imported lib. |
3962 Dart_Handle url = NewString("library_url"); | 3962 Dart_Handle url = NewString("library_url"); |
3963 Dart_Handle source = NewString(kImportedScriptChars); | 3963 Dart_Handle source = NewString(kImportedScriptChars); |
3964 Dart_Handle imported_lib = Dart_LoadLibrary(url, source, 0, 0); | 3964 Dart_Handle imported_lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
3965 Dart_Handle prefix = Dart_EmptyString(); | 3965 Dart_Handle prefix = Dart_EmptyString(); |
3966 EXPECT_VALID(imported_lib); | 3966 EXPECT_VALID(imported_lib); |
3967 Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib, prefix); | 3967 Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib, prefix); |
3968 EXPECT_VALID(result); | 3968 EXPECT_VALID(result); |
3969 result = Dart_FinalizeLoading(false); | 3969 result = Dart_FinalizeLoading(false); |
3970 EXPECT_VALID(result); | 3970 EXPECT_VALID(result); |
3971 result = Dart_Invoke(imported_lib, NewString("test2"), 0, NULL); | 3971 result = Dart_Invoke(imported_lib, NewString("test2"), 0, NULL); |
3972 EXPECT_VALID(result); | 3972 EXPECT_VALID(result); |
3973 | 3973 |
3974 // Instance field. | 3974 // Instance field. |
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5349 "void local() {}\n" | 5349 "void local() {}\n" |
5350 "void _local() {}\n"; | 5350 "void _local() {}\n"; |
5351 const char* kLibrary2Chars = | 5351 const char* kLibrary2Chars = |
5352 "library library2_name;\n" | 5352 "library library2_name;\n" |
5353 "void imported() {}\n" | 5353 "void imported() {}\n" |
5354 "void _imported() {}\n"; | 5354 "void _imported() {}\n"; |
5355 | 5355 |
5356 // Load lib1 | 5356 // Load lib1 |
5357 Dart_Handle url = NewString("library1_url"); | 5357 Dart_Handle url = NewString("library1_url"); |
5358 Dart_Handle source = NewString(kLibrary1Chars); | 5358 Dart_Handle source = NewString(kLibrary1Chars); |
5359 Dart_Handle lib1 = Dart_LoadLibrary(url, source, 0, 0); | 5359 Dart_Handle lib1 = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
5360 EXPECT_VALID(lib1); | 5360 EXPECT_VALID(lib1); |
5361 | 5361 |
5362 // Load lib2 | 5362 // Load lib2 |
5363 url = NewString("library2_url"); | 5363 url = NewString("library2_url"); |
5364 source = NewString(kLibrary2Chars); | 5364 source = NewString(kLibrary2Chars); |
5365 Dart_Handle lib2 = Dart_LoadLibrary(url, source, 0, 0); | 5365 Dart_Handle lib2 = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
5366 EXPECT_VALID(lib2); | 5366 EXPECT_VALID(lib2); |
5367 | 5367 |
5368 // Import lib2 from lib1 | 5368 // Import lib2 from lib1 |
5369 Dart_Handle result = Dart_LibraryImportLibrary(lib1, lib2, Dart_Null()); | 5369 Dart_Handle result = Dart_LibraryImportLibrary(lib1, lib2, Dart_Null()); |
5370 EXPECT_VALID(result); | 5370 EXPECT_VALID(result); |
5371 result = Dart_FinalizeLoading(false); | 5371 result = Dart_FinalizeLoading(false); |
5372 EXPECT_VALID(result); | 5372 EXPECT_VALID(result); |
5373 | 5373 |
5374 // We can invoke both private and non-private local functions. | 5374 // We can invoke both private and non-private local functions. |
5375 EXPECT_VALID(Dart_Invoke(lib1, NewString("local"), 0, NULL)); | 5375 EXPECT_VALID(Dart_Invoke(lib1, NewString("local"), 0, NULL)); |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5876 " return 12345;" | 5876 " return 12345;" |
5877 "}"; | 5877 "}"; |
5878 Dart_Handle url = NewString(TestCase::url()); | 5878 Dart_Handle url = NewString(TestCase::url()); |
5879 Dart_Handle source = NewString(kScriptChars); | 5879 Dart_Handle source = NewString(kScriptChars); |
5880 Dart_Handle error = Dart_NewApiError("incoming error"); | 5880 Dart_Handle error = Dart_NewApiError("incoming error"); |
5881 Dart_Handle result; | 5881 Dart_Handle result; |
5882 | 5882 |
5883 result = Dart_SetLibraryTagHandler(library_handler); | 5883 result = Dart_SetLibraryTagHandler(library_handler); |
5884 EXPECT_VALID(result); | 5884 EXPECT_VALID(result); |
5885 | 5885 |
5886 result = Dart_LoadScript(Dart_Null(), source, 0, 0); | 5886 result = Dart_LoadScript(Dart_Null(), Dart_Null(), source, 0, 0); |
5887 EXPECT(Dart_IsError(result)); | 5887 EXPECT(Dart_IsError(result)); |
5888 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.", | 5888 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.", |
5889 Dart_GetError(result)); | 5889 Dart_GetError(result)); |
5890 | 5890 |
5891 result = Dart_LoadScript(Dart_True(), source, 0, 0); | 5891 result = Dart_LoadScript(Dart_True(), Dart_Null(), source, 0, 0); |
5892 EXPECT(Dart_IsError(result)); | 5892 EXPECT(Dart_IsError(result)); |
5893 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be of type String.", | 5893 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be of type String.", |
5894 Dart_GetError(result)); | 5894 Dart_GetError(result)); |
5895 | 5895 |
5896 result = Dart_LoadScript(error, source, 0, 0); | 5896 result = Dart_LoadScript(error, Dart_Null(), source, 0, 0); |
5897 EXPECT(Dart_IsError(result)); | 5897 EXPECT(Dart_IsError(result)); |
5898 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 5898 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
5899 | 5899 |
5900 result = Dart_LoadScript(url, Dart_Null(), 0, 0); | 5900 result = Dart_LoadScript(url, Dart_True(), source, 0, 0); |
| 5901 EXPECT(Dart_IsError(result)); |
| 5902 EXPECT_STREQ( |
| 5903 "Dart_LoadScript expects argument 'resolved_url' to be of type String.", |
| 5904 Dart_GetError(result)); |
| 5905 |
| 5906 result = Dart_LoadScript(url, error, source, 0, 0); |
| 5907 EXPECT(Dart_IsError(result)); |
| 5908 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| 5909 |
| 5910 result = Dart_LoadScript(url, Dart_Null(), Dart_Null(), 0, 0); |
5901 EXPECT(Dart_IsError(result)); | 5911 EXPECT(Dart_IsError(result)); |
5902 EXPECT_STREQ("Dart_LoadScript expects argument 'source' to be non-null.", | 5912 EXPECT_STREQ("Dart_LoadScript expects argument 'source' to be non-null.", |
5903 Dart_GetError(result)); | 5913 Dart_GetError(result)); |
5904 | 5914 |
5905 result = Dart_LoadScript(url, Dart_True(), 0, 0); | 5915 result = Dart_LoadScript(url, Dart_Null(), Dart_True(), 0, 0); |
5906 EXPECT(Dart_IsError(result)); | 5916 EXPECT(Dart_IsError(result)); |
5907 EXPECT_STREQ( | 5917 EXPECT_STREQ( |
5908 "Dart_LoadScript expects argument 'source' to be of type String.", | 5918 "Dart_LoadScript expects argument 'source' to be of type String.", |
5909 Dart_GetError(result)); | 5919 Dart_GetError(result)); |
5910 | 5920 |
5911 result = Dart_LoadScript(url, error, 0, 0); | 5921 result = Dart_LoadScript(url, Dart_Null(), error, 0, 0); |
5912 EXPECT(Dart_IsError(result)); | 5922 EXPECT(Dart_IsError(result)); |
5913 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 5923 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
5914 | 5924 |
5915 // Load a script successfully. | 5925 // Load a script successfully. |
5916 result = Dart_LoadScript(url, source, 0, 0); | 5926 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
5917 EXPECT_VALID(result); | 5927 EXPECT_VALID(result); |
5918 Dart_FinalizeLoading(false); | 5928 Dart_FinalizeLoading(false); |
5919 | 5929 |
5920 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 5930 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
5921 EXPECT_VALID(result); | 5931 EXPECT_VALID(result); |
5922 EXPECT(Dart_IsInteger(result)); | 5932 EXPECT(Dart_IsInteger(result)); |
5923 int64_t value = 0; | 5933 int64_t value = 0; |
5924 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 5934 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
5925 EXPECT_EQ(12345, value); | 5935 EXPECT_EQ(12345, value); |
5926 | 5936 |
5927 // Further calls to LoadScript are errors. | 5937 // Further calls to LoadScript are errors. |
5928 result = Dart_LoadScript(url, source, 0, 0); | 5938 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
5929 EXPECT(Dart_IsError(result)); | 5939 EXPECT(Dart_IsError(result)); |
5930 EXPECT_STREQ("Dart_LoadScript: " | 5940 EXPECT_STREQ("Dart_LoadScript: " |
5931 "A script has already been loaded from 'test-lib'.", | 5941 "A script has already been loaded from 'test-lib'.", |
5932 Dart_GetError(result)); | 5942 Dart_GetError(result)); |
5933 } | 5943 } |
5934 | 5944 |
5935 | 5945 |
5936 TEST_CASE(RootLibrary) { | 5946 TEST_CASE(RootLibrary) { |
5937 const char* kScriptChars = | 5947 const char* kScriptChars = |
5938 "library testlib;" | 5948 "library testlib;" |
5939 "main() {" | 5949 "main() {" |
5940 " return 12345;" | 5950 " return 12345;" |
5941 "}"; | 5951 "}"; |
5942 | 5952 |
5943 Dart_Handle root_lib = Dart_RootLibrary(); | 5953 Dart_Handle root_lib = Dart_RootLibrary(); |
5944 EXPECT_VALID(root_lib); | 5954 EXPECT_VALID(root_lib); |
5945 EXPECT(Dart_IsNull(root_lib)); | 5955 EXPECT(Dart_IsNull(root_lib)); |
5946 | 5956 |
5947 // Load a script. | 5957 // Load a script. |
5948 Dart_Handle url = NewString(TestCase::url()); | 5958 Dart_Handle url = NewString(TestCase::url()); |
5949 Dart_Handle source = NewString(kScriptChars); | 5959 Dart_Handle source = NewString(kScriptChars); |
5950 EXPECT_VALID(Dart_LoadScript(url, source, 0, 0)); | 5960 EXPECT_VALID(Dart_LoadScript(url, Dart_Null(), source, 0, 0)); |
5951 | 5961 |
5952 root_lib = Dart_RootLibrary(); | 5962 root_lib = Dart_RootLibrary(); |
5953 Dart_Handle lib_name = Dart_LibraryName(root_lib); | 5963 Dart_Handle lib_name = Dart_LibraryName(root_lib); |
5954 EXPECT_VALID(lib_name); | 5964 EXPECT_VALID(lib_name); |
5955 EXPECT(!Dart_IsNull(root_lib)); | 5965 EXPECT(!Dart_IsNull(root_lib)); |
5956 const char* name_cstr = ""; | 5966 const char* name_cstr = ""; |
5957 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr)); | 5967 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr)); |
5958 EXPECT_STREQ("testlib", name_cstr); | 5968 EXPECT_STREQ("testlib", name_cstr); |
5959 | 5969 |
5960 Dart_Handle lib_uri = Dart_LibraryUrl(root_lib); | 5970 Dart_Handle lib_uri = Dart_LibraryUrl(root_lib); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6028 } | 6038 } |
6029 | 6039 |
6030 | 6040 |
6031 TEST_CASE(LoadScript_CompileError) { | 6041 TEST_CASE(LoadScript_CompileError) { |
6032 const char* kScriptChars = | 6042 const char* kScriptChars = |
6033 ")"; | 6043 ")"; |
6034 Dart_Handle url = NewString(TestCase::url()); | 6044 Dart_Handle url = NewString(TestCase::url()); |
6035 Dart_Handle source = NewString(kScriptChars); | 6045 Dart_Handle source = NewString(kScriptChars); |
6036 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); | 6046 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); |
6037 EXPECT_VALID(result); | 6047 EXPECT_VALID(result); |
6038 result = Dart_LoadScript(url, source, 0, 0); | 6048 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
6039 EXPECT(Dart_IsError(result)); | 6049 EXPECT(Dart_IsError(result)); |
6040 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); | 6050 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); |
6041 } | 6051 } |
6042 | 6052 |
6043 | 6053 |
6044 TEST_CASE(LookupLibrary) { | 6054 TEST_CASE(LookupLibrary) { |
6045 const char* kScriptChars = | 6055 const char* kScriptChars = |
6046 "import 'library1_dart';" | 6056 "import 'library1_dart';" |
6047 "main() {}"; | 6057 "main() {}"; |
6048 const char* kLibrary1Chars = | 6058 const char* kLibrary1Chars = |
6049 "library library1_dart;" | 6059 "library library1_dart;" |
6050 "import 'library2_dart';"; | 6060 "import 'library2_dart';"; |
6051 | 6061 |
6052 // Create a test library and Load up a test script in it. | 6062 // Create a test library and Load up a test script in it. |
6053 Dart_Handle url = NewString(TestCase::url()); | 6063 Dart_Handle url = NewString(TestCase::url()); |
6054 Dart_Handle source = NewString(kScriptChars); | 6064 Dart_Handle source = NewString(kScriptChars); |
6055 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); | 6065 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); |
6056 EXPECT_VALID(result); | 6066 EXPECT_VALID(result); |
6057 result = Dart_LoadScript(url, source, 0, 0); | 6067 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
6058 EXPECT_VALID(result); | 6068 EXPECT_VALID(result); |
6059 | 6069 |
6060 url = NewString("library1_dart"); | 6070 url = NewString("library1_dart"); |
6061 source = NewString(kLibrary1Chars); | 6071 source = NewString(kLibrary1Chars); |
6062 result = Dart_LoadLibrary(url, source, 0, 0); | 6072 result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6063 EXPECT_VALID(result); | 6073 EXPECT_VALID(result); |
6064 | 6074 |
6065 result = Dart_LookupLibrary(url); | 6075 result = Dart_LookupLibrary(url); |
6066 EXPECT_VALID(result); | 6076 EXPECT_VALID(result); |
6067 | 6077 |
6068 result = Dart_LookupLibrary(Dart_Null()); | 6078 result = Dart_LookupLibrary(Dart_Null()); |
6069 EXPECT(Dart_IsError(result)); | 6079 EXPECT(Dart_IsError(result)); |
6070 EXPECT_STREQ("Dart_LookupLibrary expects argument 'url' to be non-null.", | 6080 EXPECT_STREQ("Dart_LookupLibrary expects argument 'url' to be non-null.", |
6071 Dart_GetError(result)); | 6081 Dart_GetError(result)); |
6072 | 6082 |
(...skipping 13 matching lines...) Expand all Loading... |
6086 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", | 6096 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", |
6087 Dart_GetError(result)); | 6097 Dart_GetError(result)); |
6088 } | 6098 } |
6089 | 6099 |
6090 | 6100 |
6091 TEST_CASE(LibraryName) { | 6101 TEST_CASE(LibraryName) { |
6092 const char* kLibrary1Chars = | 6102 const char* kLibrary1Chars = |
6093 "library library1_name;"; | 6103 "library library1_name;"; |
6094 Dart_Handle url = NewString("library1_url"); | 6104 Dart_Handle url = NewString("library1_url"); |
6095 Dart_Handle source = NewString(kLibrary1Chars); | 6105 Dart_Handle source = NewString(kLibrary1Chars); |
6096 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); | 6106 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6097 Dart_Handle error = Dart_NewApiError("incoming error"); | 6107 Dart_Handle error = Dart_NewApiError("incoming error"); |
6098 EXPECT_VALID(lib); | 6108 EXPECT_VALID(lib); |
6099 | 6109 |
6100 Dart_Handle result = Dart_LibraryName(Dart_Null()); | 6110 Dart_Handle result = Dart_LibraryName(Dart_Null()); |
6101 EXPECT(Dart_IsError(result)); | 6111 EXPECT(Dart_IsError(result)); |
6102 EXPECT_STREQ("Dart_LibraryName expects argument 'library' to be non-null.", | 6112 EXPECT_STREQ("Dart_LibraryName expects argument 'library' to be non-null.", |
6103 Dart_GetError(result)); | 6113 Dart_GetError(result)); |
6104 | 6114 |
6105 result = Dart_LibraryName(Dart_True()); | 6115 result = Dart_LibraryName(Dart_True()); |
6106 EXPECT(Dart_IsError(result)); | 6116 EXPECT(Dart_IsError(result)); |
(...skipping 15 matching lines...) Expand all Loading... |
6122 | 6132 |
6123 | 6133 |
6124 #ifndef PRODUCT | 6134 #ifndef PRODUCT |
6125 | 6135 |
6126 | 6136 |
6127 TEST_CASE(LibraryId) { | 6137 TEST_CASE(LibraryId) { |
6128 const char* kLibrary1Chars = | 6138 const char* kLibrary1Chars = |
6129 "library library1_name;"; | 6139 "library library1_name;"; |
6130 Dart_Handle url = NewString("library1_url"); | 6140 Dart_Handle url = NewString("library1_url"); |
6131 Dart_Handle source = NewString(kLibrary1Chars); | 6141 Dart_Handle source = NewString(kLibrary1Chars); |
6132 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); | 6142 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6133 Dart_Handle error = Dart_NewApiError("incoming error"); | 6143 Dart_Handle error = Dart_NewApiError("incoming error"); |
6134 EXPECT_VALID(lib); | 6144 EXPECT_VALID(lib); |
6135 intptr_t libraryId = -1; | 6145 intptr_t libraryId = -1; |
6136 | 6146 |
6137 Dart_Handle result = Dart_LibraryId(Dart_Null(), &libraryId); | 6147 Dart_Handle result = Dart_LibraryId(Dart_Null(), &libraryId); |
6138 EXPECT(Dart_IsError(result)); | 6148 EXPECT(Dart_IsError(result)); |
6139 EXPECT_STREQ("Dart_LibraryId expects argument 'library' to be non-null.", | 6149 EXPECT_STREQ("Dart_LibraryId expects argument 'library' to be non-null.", |
6140 Dart_GetError(result)); | 6150 Dart_GetError(result)); |
6141 | 6151 |
6142 result = Dart_LibraryId(Dart_True(), &libraryId); | 6152 result = Dart_LibraryId(Dart_True(), &libraryId); |
(...skipping 19 matching lines...) Expand all Loading... |
6162 | 6172 |
6163 | 6173 |
6164 #endif // !PRODUCT | 6174 #endif // !PRODUCT |
6165 | 6175 |
6166 | 6176 |
6167 TEST_CASE(LibraryUrl) { | 6177 TEST_CASE(LibraryUrl) { |
6168 const char* kLibrary1Chars = | 6178 const char* kLibrary1Chars = |
6169 "library library1_name;"; | 6179 "library library1_name;"; |
6170 Dart_Handle url = NewString("library1_url"); | 6180 Dart_Handle url = NewString("library1_url"); |
6171 Dart_Handle source = NewString(kLibrary1Chars); | 6181 Dart_Handle source = NewString(kLibrary1Chars); |
6172 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); | 6182 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6173 Dart_Handle error = Dart_NewApiError("incoming error"); | 6183 Dart_Handle error = Dart_NewApiError("incoming error"); |
6174 EXPECT_VALID(lib); | 6184 EXPECT_VALID(lib); |
6175 | 6185 |
6176 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); | 6186 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); |
6177 EXPECT(Dart_IsError(result)); | 6187 EXPECT(Dart_IsError(result)); |
6178 EXPECT_STREQ("Dart_LibraryUrl expects argument 'library' to be non-null.", | 6188 EXPECT_STREQ("Dart_LibraryUrl expects argument 'library' to be non-null.", |
6179 Dart_GetError(result)); | 6189 Dart_GetError(result)); |
6180 | 6190 |
6181 result = Dart_LibraryUrl(Dart_True()); | 6191 result = Dart_LibraryUrl(Dart_True()); |
6182 EXPECT(Dart_IsError(result)); | 6192 EXPECT(Dart_IsError(result)); |
(...skipping 23 matching lines...) Expand all Loading... |
6206 "abstract class C {}\n" | 6216 "abstract class C {}\n" |
6207 "class _A {}\n" | 6217 "class _A {}\n" |
6208 "class _B {}\n" | 6218 "class _B {}\n" |
6209 "abstract class _C {}\n" | 6219 "abstract class _C {}\n" |
6210 "\n" | 6220 "\n" |
6211 "_compare(String a, String b) => a.compareTo(b);\n" | 6221 "_compare(String a, String b) => a.compareTo(b);\n" |
6212 "sort(list) => list.sort(_compare);\n"; | 6222 "sort(list) => list.sort(_compare);\n"; |
6213 | 6223 |
6214 Dart_Handle url = NewString("library_url"); | 6224 Dart_Handle url = NewString("library_url"); |
6215 Dart_Handle source = NewString(kLibraryChars); | 6225 Dart_Handle source = NewString(kLibraryChars); |
6216 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); | 6226 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6217 EXPECT_VALID(lib); | 6227 EXPECT_VALID(lib); |
6218 Dart_Handle result = Dart_FinalizeLoading(false); | 6228 Dart_Handle result = Dart_FinalizeLoading(false); |
6219 EXPECT_VALID(result); | 6229 EXPECT_VALID(result); |
6220 | 6230 |
6221 Dart_Handle list = Dart_LibraryGetClassNames(lib); | 6231 Dart_Handle list = Dart_LibraryGetClassNames(lib); |
6222 EXPECT_VALID(list); | 6232 EXPECT_VALID(list); |
6223 EXPECT(Dart_IsList(list)); | 6233 EXPECT(Dart_IsList(list)); |
6224 | 6234 |
6225 // Sort the list. | 6235 // Sort the list. |
6226 const int kNumArgs = 1; | 6236 const int kNumArgs = 1; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6259 " set _C2(x) { }\n" | 6269 " set _C2(x) { }\n" |
6260 " var _D2;\n" | 6270 " var _D2;\n" |
6261 "}\n" | 6271 "}\n" |
6262 "\n" | 6272 "\n" |
6263 "_compare(String a, String b) => a.compareTo(b);\n" | 6273 "_compare(String a, String b) => a.compareTo(b);\n" |
6264 "sort(list) => list.sort(_compare);\n"; | 6274 "sort(list) => list.sort(_compare);\n"; |
6265 | 6275 |
6266 // Get the functions from a library. | 6276 // Get the functions from a library. |
6267 Dart_Handle url = NewString("library_url"); | 6277 Dart_Handle url = NewString("library_url"); |
6268 Dart_Handle source = NewString(kLibraryChars); | 6278 Dart_Handle source = NewString(kLibraryChars); |
6269 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); | 6279 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6270 EXPECT_VALID(lib); | 6280 EXPECT_VALID(lib); |
6271 Dart_Handle result = Dart_FinalizeLoading(false); | 6281 Dart_Handle result = Dart_FinalizeLoading(false); |
6272 EXPECT_VALID(result); | 6282 EXPECT_VALID(result); |
6273 | 6283 |
6274 Dart_Handle list = Dart_GetFunctionNames(lib); | 6284 Dart_Handle list = Dart_GetFunctionNames(lib); |
6275 EXPECT_VALID(list); | 6285 EXPECT_VALID(list); |
6276 EXPECT(Dart_IsList(list)); | 6286 EXPECT(Dart_IsList(list)); |
6277 | 6287 |
6278 // Sort the list. | 6288 // Sort the list. |
6279 const int kNumArgs = 1; | 6289 const int kNumArgs = 1; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6311 TEST_CASE(LibraryImportLibrary) { | 6321 TEST_CASE(LibraryImportLibrary) { |
6312 const char* kLibrary1Chars = | 6322 const char* kLibrary1Chars = |
6313 "library library1_name;"; | 6323 "library library1_name;"; |
6314 const char* kLibrary2Chars = | 6324 const char* kLibrary2Chars = |
6315 "library library2_name;"; | 6325 "library library2_name;"; |
6316 Dart_Handle error = Dart_NewApiError("incoming error"); | 6326 Dart_Handle error = Dart_NewApiError("incoming error"); |
6317 Dart_Handle result; | 6327 Dart_Handle result; |
6318 | 6328 |
6319 Dart_Handle url = NewString("library1_url"); | 6329 Dart_Handle url = NewString("library1_url"); |
6320 Dart_Handle source = NewString(kLibrary1Chars); | 6330 Dart_Handle source = NewString(kLibrary1Chars); |
6321 Dart_Handle lib1 = Dart_LoadLibrary(url, source, 0, 0); | 6331 Dart_Handle lib1 = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6322 EXPECT_VALID(lib1); | 6332 EXPECT_VALID(lib1); |
6323 | 6333 |
6324 url = NewString("library2_url"); | 6334 url = NewString("library2_url"); |
6325 source = NewString(kLibrary2Chars); | 6335 source = NewString(kLibrary2Chars); |
6326 Dart_Handle lib2 = Dart_LoadLibrary(url, source, 0, 0); | 6336 Dart_Handle lib2 = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6327 EXPECT_VALID(lib2); | 6337 EXPECT_VALID(lib2); |
6328 | 6338 |
6329 result = Dart_LibraryImportLibrary(Dart_Null(), lib2, Dart_Null()); | 6339 result = Dart_LibraryImportLibrary(Dart_Null(), lib2, Dart_Null()); |
6330 EXPECT(Dart_IsError(result)); | 6340 EXPECT(Dart_IsError(result)); |
6331 EXPECT_STREQ( | 6341 EXPECT_STREQ( |
6332 "Dart_LibraryImportLibrary expects argument 'library' to be non-null.", | 6342 "Dart_LibraryImportLibrary expects argument 'library' to be non-null.", |
6333 Dart_GetError(result)); | 6343 Dart_GetError(result)); |
6334 | 6344 |
6335 result = Dart_LibraryImportLibrary(Dart_True(), lib2, Dart_Null()); | 6345 result = Dart_LibraryImportLibrary(Dart_True(), lib2, Dart_Null()); |
6336 EXPECT(Dart_IsError(result)); | 6346 EXPECT(Dart_IsError(result)); |
(...skipping 25 matching lines...) Expand all Loading... |
6362 EXPECT_VALID(result); | 6372 EXPECT_VALID(result); |
6363 } | 6373 } |
6364 | 6374 |
6365 | 6375 |
6366 TEST_CASE(ImportLibraryWithPrefix) { | 6376 TEST_CASE(ImportLibraryWithPrefix) { |
6367 const char* kLibrary1Chars = | 6377 const char* kLibrary1Chars = |
6368 "library library1_name;" | 6378 "library library1_name;" |
6369 "int bar() => 42;"; | 6379 "int bar() => 42;"; |
6370 Dart_Handle url1 = NewString("library1_url"); | 6380 Dart_Handle url1 = NewString("library1_url"); |
6371 Dart_Handle source1 = NewString(kLibrary1Chars); | 6381 Dart_Handle source1 = NewString(kLibrary1Chars); |
6372 Dart_Handle lib1 = Dart_LoadLibrary(url1, source1, 0, 0); | 6382 Dart_Handle lib1 = Dart_LoadLibrary(url1, Dart_Null(), source1, 0, 0); |
6373 EXPECT_VALID(lib1); | 6383 EXPECT_VALID(lib1); |
6374 EXPECT(Dart_IsLibrary(lib1)); | 6384 EXPECT(Dart_IsLibrary(lib1)); |
6375 | 6385 |
6376 const char* kLibrary2Chars = | 6386 const char* kLibrary2Chars = |
6377 "library library2_name;" | 6387 "library library2_name;" |
6378 "int foobar() => foo.bar();"; | 6388 "int foobar() => foo.bar();"; |
6379 Dart_Handle url2 = NewString("library2_url"); | 6389 Dart_Handle url2 = NewString("library2_url"); |
6380 Dart_Handle source2 = NewString(kLibrary2Chars); | 6390 Dart_Handle source2 = NewString(kLibrary2Chars); |
6381 Dart_Handle lib2 = Dart_LoadLibrary(url2, source2, 0, 0); | 6391 Dart_Handle lib2 = Dart_LoadLibrary(url2, Dart_Null(), source2, 0, 0); |
6382 EXPECT_VALID(lib2); | 6392 EXPECT_VALID(lib2); |
6383 EXPECT(Dart_IsLibrary(lib2)); | 6393 EXPECT(Dart_IsLibrary(lib2)); |
6384 | 6394 |
6385 Dart_Handle prefix = NewString("foo"); | 6395 Dart_Handle prefix = NewString("foo"); |
6386 Dart_Handle result = Dart_LibraryImportLibrary(lib2, lib1, prefix); | 6396 Dart_Handle result = Dart_LibraryImportLibrary(lib2, lib1, prefix); |
6387 EXPECT_VALID(result); | 6397 EXPECT_VALID(result); |
6388 result = Dart_FinalizeLoading(false); | 6398 result = Dart_FinalizeLoading(false); |
6389 EXPECT_VALID(result); | 6399 EXPECT_VALID(result); |
6390 | 6400 |
6391 // Lib1 is imported under a library prefix and therefore 'foo' should | 6401 // Lib1 is imported under a library prefix and therefore 'foo' should |
(...skipping 16 matching lines...) Expand all Loading... |
6408 | 6418 |
6409 TEST_CASE(LoadLibrary) { | 6419 TEST_CASE(LoadLibrary) { |
6410 const char* kLibrary1Chars = | 6420 const char* kLibrary1Chars = |
6411 "library library1_name;"; | 6421 "library library1_name;"; |
6412 Dart_Handle error = Dart_NewApiError("incoming error"); | 6422 Dart_Handle error = Dart_NewApiError("incoming error"); |
6413 Dart_Handle result; | 6423 Dart_Handle result; |
6414 | 6424 |
6415 Dart_Handle url = NewString("library1_url"); | 6425 Dart_Handle url = NewString("library1_url"); |
6416 Dart_Handle source = NewString(kLibrary1Chars); | 6426 Dart_Handle source = NewString(kLibrary1Chars); |
6417 | 6427 |
6418 result = Dart_LoadLibrary(Dart_Null(), source, 0, 0); | 6428 result = Dart_LoadLibrary(Dart_Null(), Dart_Null(), source, 0, 0); |
6419 EXPECT(Dart_IsError(result)); | 6429 EXPECT(Dart_IsError(result)); |
6420 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.", | 6430 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.", |
6421 Dart_GetError(result)); | 6431 Dart_GetError(result)); |
6422 | 6432 |
6423 result = Dart_LoadLibrary(Dart_True(), source, 0, 0); | 6433 result = Dart_LoadLibrary(Dart_True(), Dart_Null(), source, 0, 0); |
6424 EXPECT(Dart_IsError(result)); | 6434 EXPECT(Dart_IsError(result)); |
6425 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be of type String.", | 6435 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be of type String.", |
6426 Dart_GetError(result)); | 6436 Dart_GetError(result)); |
6427 | 6437 |
6428 result = Dart_LoadLibrary(error, source, 0, 0); | 6438 result = Dart_LoadLibrary(error, Dart_Null(), source, 0, 0); |
6429 EXPECT(Dart_IsError(result)); | 6439 EXPECT(Dart_IsError(result)); |
6430 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 6440 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
6431 | 6441 |
6432 result = Dart_LoadLibrary(url, Dart_Null(), 0, 0); | 6442 result = Dart_LoadLibrary(url, Dart_True(), source, 0, 0); |
| 6443 EXPECT(Dart_IsError(result)); |
| 6444 EXPECT_STREQ( |
| 6445 "Dart_LoadLibrary expects argument 'resolved_url' to be of type String.", |
| 6446 Dart_GetError(result)); |
| 6447 |
| 6448 result = Dart_LoadLibrary(url, error, source, 0, 0); |
| 6449 EXPECT(Dart_IsError(result)); |
| 6450 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| 6451 |
| 6452 result = Dart_LoadLibrary(url, Dart_Null(), Dart_Null(), 0, 0); |
6433 EXPECT(Dart_IsError(result)); | 6453 EXPECT(Dart_IsError(result)); |
6434 EXPECT_STREQ("Dart_LoadLibrary expects argument 'source' to be non-null.", | 6454 EXPECT_STREQ("Dart_LoadLibrary expects argument 'source' to be non-null.", |
6435 Dart_GetError(result)); | 6455 Dart_GetError(result)); |
6436 | 6456 |
6437 result = Dart_LoadLibrary(url, Dart_True(), 0, 0); | 6457 result = Dart_LoadLibrary(url, Dart_Null(), Dart_True(), 0, 0); |
6438 EXPECT(Dart_IsError(result)); | 6458 EXPECT(Dart_IsError(result)); |
6439 EXPECT_STREQ( | 6459 EXPECT_STREQ( |
6440 "Dart_LoadLibrary expects argument 'source' to be of type String.", | 6460 "Dart_LoadLibrary expects argument 'source' to be of type String.", |
6441 Dart_GetError(result)); | 6461 Dart_GetError(result)); |
6442 | 6462 |
6443 result = Dart_LoadLibrary(url, error, 0, 0); | 6463 result = Dart_LoadLibrary(url, Dart_Null(), error, 0, 0); |
6444 EXPECT(Dart_IsError(result)); | 6464 EXPECT(Dart_IsError(result)); |
6445 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 6465 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
6446 | 6466 |
6447 // Success. | 6467 // Success. |
6448 result = Dart_LoadLibrary(url, source, 0, 0); | 6468 result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6449 EXPECT_VALID(result); | 6469 EXPECT_VALID(result); |
6450 EXPECT(Dart_IsLibrary(result)); | 6470 EXPECT(Dart_IsLibrary(result)); |
6451 | 6471 |
6452 // Duplicate library load fails. | 6472 // Duplicate library load fails. |
6453 result = Dart_LoadLibrary(url, source, 0, 0); | 6473 result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6454 EXPECT(Dart_IsError(result)); | 6474 EXPECT(Dart_IsError(result)); |
6455 EXPECT_STREQ( | 6475 EXPECT_STREQ( |
6456 "Dart_LoadLibrary: library 'library1_url' has already been loaded.", | 6476 "Dart_LoadLibrary: library 'library1_url' has already been loaded.", |
6457 Dart_GetError(result)); | 6477 Dart_GetError(result)); |
6458 } | 6478 } |
6459 | 6479 |
6460 | 6480 |
6461 TEST_CASE(LoadLibrary_CompileError) { | 6481 TEST_CASE(LoadLibrary_CompileError) { |
6462 const char* kLibrary1Chars = | 6482 const char* kLibrary1Chars = |
6463 "library library1_name;" | 6483 "library library1_name;" |
6464 ")"; | 6484 ")"; |
6465 Dart_Handle url = NewString("library1_url"); | 6485 Dart_Handle url = NewString("library1_url"); |
6466 Dart_Handle source = NewString(kLibrary1Chars); | 6486 Dart_Handle source = NewString(kLibrary1Chars); |
6467 Dart_Handle result = Dart_LoadLibrary(url, source, 0, 0); | 6487 Dart_Handle result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6468 EXPECT(Dart_IsError(result)); | 6488 EXPECT(Dart_IsError(result)); |
6469 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); | 6489 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); |
6470 } | 6490 } |
6471 | 6491 |
6472 | 6492 |
6473 TEST_CASE(LoadSource) { | 6493 TEST_CASE(LoadSource) { |
6474 const char* kLibrary1Chars = | 6494 const char* kLibrary1Chars = |
6475 "library library1_name;"; | 6495 "library library1_name;"; |
6476 const char* kSourceChars = | 6496 const char* kSourceChars = |
6477 "part of library1_name;\n// Something innocuous"; | 6497 "part of library1_name;\n// Something innocuous"; |
6478 const char* kBadSourceChars = | 6498 const char* kBadSourceChars = |
6479 ")"; | 6499 ")"; |
6480 Dart_Handle error = Dart_NewApiError("incoming error"); | 6500 Dart_Handle error = Dart_NewApiError("incoming error"); |
6481 Dart_Handle result; | 6501 Dart_Handle result; |
6482 | 6502 |
6483 // Load up a library. | 6503 // Load up a library. |
6484 Dart_Handle url = NewString("library1_url"); | 6504 Dart_Handle url = NewString("library1_url"); |
6485 Dart_Handle source = NewString(kLibrary1Chars); | 6505 Dart_Handle source = NewString(kLibrary1Chars); |
6486 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); | 6506 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6487 EXPECT_VALID(lib); | 6507 EXPECT_VALID(lib); |
6488 EXPECT(Dart_IsLibrary(lib)); | 6508 EXPECT(Dart_IsLibrary(lib)); |
6489 | 6509 |
6490 url = NewString("source_url"); | 6510 url = NewString("source_url"); |
6491 source = NewString(kSourceChars); | 6511 source = NewString(kSourceChars); |
6492 | 6512 |
6493 result = Dart_LoadSource(Dart_Null(), url, source, 0, 0); | 6513 result = Dart_LoadSource(Dart_Null(), url, Dart_Null(), source, 0, 0); |
6494 EXPECT(Dart_IsError(result)); | 6514 EXPECT(Dart_IsError(result)); |
6495 EXPECT_STREQ("Dart_LoadSource expects argument 'library' to be non-null.", | 6515 EXPECT_STREQ("Dart_LoadSource expects argument 'library' to be non-null.", |
6496 Dart_GetError(result)); | 6516 Dart_GetError(result)); |
6497 | 6517 |
6498 result = Dart_LoadSource(Dart_True(), url, source, 0, 0); | 6518 result = Dart_LoadSource(Dart_True(), url, Dart_Null(), source, 0, 0); |
6499 EXPECT(Dart_IsError(result)); | 6519 EXPECT(Dart_IsError(result)); |
6500 EXPECT_STREQ( | 6520 EXPECT_STREQ( |
6501 "Dart_LoadSource expects argument 'library' to be of type Library.", | 6521 "Dart_LoadSource expects argument 'library' to be of type Library.", |
6502 Dart_GetError(result)); | 6522 Dart_GetError(result)); |
6503 | 6523 |
6504 result = Dart_LoadSource(error, url, source, 0, 0); | 6524 result = Dart_LoadSource(error, url, Dart_Null(), source, 0, 0); |
6505 EXPECT(Dart_IsError(result)); | 6525 EXPECT(Dart_IsError(result)); |
6506 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 6526 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
6507 | 6527 |
6508 result = Dart_LoadSource(lib, Dart_Null(), source, 0, 0); | 6528 result = Dart_LoadSource(lib, Dart_Null(), Dart_Null(), source, 0, 0); |
6509 EXPECT(Dart_IsError(result)); | 6529 EXPECT(Dart_IsError(result)); |
6510 EXPECT_STREQ("Dart_LoadSource expects argument 'url' to be non-null.", | 6530 EXPECT_STREQ("Dart_LoadSource expects argument 'url' to be non-null.", |
6511 Dart_GetError(result)); | 6531 Dart_GetError(result)); |
6512 | 6532 |
6513 result = Dart_LoadSource(lib, Dart_True(), source, 0, 0); | 6533 result = Dart_LoadSource(lib, Dart_True(), Dart_Null(), source, 0, 0); |
6514 EXPECT(Dart_IsError(result)); | 6534 EXPECT(Dart_IsError(result)); |
6515 EXPECT_STREQ("Dart_LoadSource expects argument 'url' to be of type String.", | 6535 EXPECT_STREQ("Dart_LoadSource expects argument 'url' to be of type String.", |
6516 Dart_GetError(result)); | 6536 Dart_GetError(result)); |
6517 | 6537 |
6518 result = Dart_LoadSource(lib, error, source, 0, 0); | 6538 result = Dart_LoadSource(lib, error, Dart_Null(), source, 0, 0); |
6519 EXPECT(Dart_IsError(result)); | 6539 EXPECT(Dart_IsError(result)); |
6520 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 6540 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
6521 | 6541 |
6522 result = Dart_LoadSource(lib, url, Dart_Null(), 0, 0); | 6542 result = Dart_LoadSource(lib, url, Dart_True(), source, 0, 0); |
| 6543 EXPECT(Dart_IsError(result)); |
| 6544 EXPECT_STREQ( |
| 6545 "Dart_LoadSource expects argument 'resolved_url' to be of type String.", |
| 6546 Dart_GetError(result)); |
| 6547 |
| 6548 result = Dart_LoadSource(lib, url, error, source, 0, 0); |
| 6549 EXPECT(Dart_IsError(result)); |
| 6550 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| 6551 |
| 6552 result = Dart_LoadSource(lib, url, Dart_Null(), Dart_Null(), 0, 0); |
6523 EXPECT(Dart_IsError(result)); | 6553 EXPECT(Dart_IsError(result)); |
6524 EXPECT_STREQ("Dart_LoadSource expects argument 'source' to be non-null.", | 6554 EXPECT_STREQ("Dart_LoadSource expects argument 'source' to be non-null.", |
6525 Dart_GetError(result)); | 6555 Dart_GetError(result)); |
6526 | 6556 |
6527 result = Dart_LoadSource(lib, url, Dart_True(), 0, 0); | 6557 result = Dart_LoadSource(lib, url, Dart_Null(), Dart_True(), 0, 0); |
6528 EXPECT(Dart_IsError(result)); | 6558 EXPECT(Dart_IsError(result)); |
6529 EXPECT_STREQ( | 6559 EXPECT_STREQ( |
6530 "Dart_LoadSource expects argument 'source' to be of type String.", | 6560 "Dart_LoadSource expects argument 'source' to be of type String.", |
6531 Dart_GetError(result)); | 6561 Dart_GetError(result)); |
6532 | 6562 |
6533 result = Dart_LoadSource(lib, error, source, 0, 0); | 6563 result = Dart_LoadSource(lib, error, Dart_Null(), source, 0, 0); |
6534 EXPECT(Dart_IsError(result)); | 6564 EXPECT(Dart_IsError(result)); |
6535 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 6565 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
6536 | 6566 |
6537 // Success. | 6567 // Success. |
6538 result = Dart_LoadSource(lib, url, source, 0, 0); | 6568 result = Dart_LoadSource(lib, url, Dart_Null(), source, 0, 0); |
6539 EXPECT_VALID(result); | 6569 EXPECT_VALID(result); |
6540 EXPECT(Dart_IsLibrary(result)); | 6570 EXPECT(Dart_IsLibrary(result)); |
6541 EXPECT(Dart_IdentityEquals(lib, result)); | 6571 EXPECT(Dart_IdentityEquals(lib, result)); |
6542 | 6572 |
6543 // Duplicate calls are okay. | 6573 // Duplicate calls are okay. |
6544 result = Dart_LoadSource(lib, url, source, 0, 0); | 6574 result = Dart_LoadSource(lib, url, Dart_Null(), source, 0, 0); |
6545 EXPECT_VALID(result); | 6575 EXPECT_VALID(result); |
6546 EXPECT(Dart_IsLibrary(result)); | 6576 EXPECT(Dart_IsLibrary(result)); |
6547 EXPECT(Dart_IdentityEquals(lib, result)); | 6577 EXPECT(Dart_IdentityEquals(lib, result)); |
6548 | 6578 |
6549 // Language errors are detected. | 6579 // Language errors are detected. |
6550 source = NewString(kBadSourceChars); | 6580 source = NewString(kBadSourceChars); |
6551 result = Dart_LoadSource(lib, url, source, 0, 0); | 6581 result = Dart_LoadSource(lib, url, Dart_Null(), source, 0, 0); |
6552 EXPECT(Dart_IsError(result)); | 6582 EXPECT(Dart_IsError(result)); |
6553 } | 6583 } |
6554 | 6584 |
6555 | 6585 |
6556 TEST_CASE(LoadSource_LateLoad) { | 6586 TEST_CASE(LoadSource_LateLoad) { |
6557 const char* kLibrary1Chars = | 6587 const char* kLibrary1Chars = |
6558 "library library1_name;\n" | 6588 "library library1_name;\n" |
6559 "class OldClass {\n" | 6589 "class OldClass {\n" |
6560 " foo() => 'foo';\n" | 6590 " foo() => 'foo';\n" |
6561 "}\n"; | 6591 "}\n"; |
6562 const char* kSourceChars = | 6592 const char* kSourceChars = |
6563 "part of library1_name;\n" | 6593 "part of library1_name;\n" |
6564 "class NewClass extends OldClass{\n" | 6594 "class NewClass extends OldClass{\n" |
6565 " bar() => 'bar';\n" | 6595 " bar() => 'bar';\n" |
6566 "}\n"; | 6596 "}\n"; |
6567 Dart_Handle url = NewString("library1_url"); | 6597 Dart_Handle url = NewString("library1_url"); |
6568 Dart_Handle source = NewString(kLibrary1Chars); | 6598 Dart_Handle source = NewString(kLibrary1Chars); |
6569 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); | 6599 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6570 EXPECT_VALID(lib); | 6600 EXPECT_VALID(lib); |
6571 EXPECT(Dart_IsLibrary(lib)); | 6601 EXPECT(Dart_IsLibrary(lib)); |
6572 Dart_Handle result = Dart_FinalizeLoading(false); | 6602 Dart_Handle result = Dart_FinalizeLoading(false); |
6573 EXPECT_VALID(result); | 6603 EXPECT_VALID(result); |
6574 | 6604 |
6575 // Call a dynamic function on OldClass. | 6605 // Call a dynamic function on OldClass. |
6576 Dart_Handle type = Dart_GetType(lib, NewString("OldClass"), 0, NULL); | 6606 Dart_Handle type = Dart_GetType(lib, NewString("OldClass"), 0, NULL); |
6577 EXPECT_VALID(type); | 6607 EXPECT_VALID(type); |
6578 Dart_Handle recv = Dart_New(type, Dart_Null(), 0, NULL); | 6608 Dart_Handle recv = Dart_New(type, Dart_Null(), 0, NULL); |
6579 result = Dart_Invoke(recv, NewString("foo"), 0, NULL); | 6609 result = Dart_Invoke(recv, NewString("foo"), 0, NULL); |
6580 EXPECT_VALID(result); | 6610 EXPECT_VALID(result); |
6581 EXPECT(Dart_IsString(result)); | 6611 EXPECT(Dart_IsString(result)); |
6582 const char* result_cstr = ""; | 6612 const char* result_cstr = ""; |
6583 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | 6613 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); |
6584 EXPECT_STREQ("foo", result_cstr); | 6614 EXPECT_STREQ("foo", result_cstr); |
6585 | 6615 |
6586 // Load a source file late. | 6616 // Load a source file late. |
6587 url = NewString("source_url"); | 6617 url = NewString("source_url"); |
6588 source = NewString(kSourceChars); | 6618 source = NewString(kSourceChars); |
6589 EXPECT_VALID(Dart_LoadSource(lib, url, source, 0, 0)); | 6619 EXPECT_VALID(Dart_LoadSource(lib, url, Dart_Null(), source, 0, 0)); |
6590 result = Dart_FinalizeLoading(false); | 6620 result = Dart_FinalizeLoading(false); |
6591 EXPECT_VALID(result); | 6621 EXPECT_VALID(result); |
6592 | 6622 |
6593 // Call a dynamic function on NewClass in the updated library. | 6623 // Call a dynamic function on NewClass in the updated library. |
6594 type = Dart_GetType(lib, NewString("NewClass"), 0, NULL); | 6624 type = Dart_GetType(lib, NewString("NewClass"), 0, NULL); |
6595 EXPECT_VALID(type); | 6625 EXPECT_VALID(type); |
6596 recv = Dart_New(type, Dart_Null(), 0, NULL); | 6626 recv = Dart_New(type, Dart_Null(), 0, NULL); |
6597 result = Dart_Invoke(recv, NewString("bar"), 0, NULL); | 6627 result = Dart_Invoke(recv, NewString("bar"), 0, NULL); |
6598 EXPECT_VALID(result); | 6628 EXPECT_VALID(result); |
6599 EXPECT(Dart_IsString(result)); | 6629 EXPECT(Dart_IsString(result)); |
6600 result_cstr = ""; | 6630 result_cstr = ""; |
6601 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | 6631 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); |
6602 EXPECT_STREQ("bar", result_cstr); | 6632 EXPECT_STREQ("bar", result_cstr); |
6603 } | 6633 } |
6604 | 6634 |
6605 | 6635 |
6606 TEST_CASE(LoadPatch) { | 6636 TEST_CASE(LoadPatch) { |
6607 const char* kLibrary1Chars = | 6637 const char* kLibrary1Chars = |
6608 "library library1_name;"; | 6638 "library library1_name;"; |
6609 const char* kSourceChars = | 6639 const char* kSourceChars = |
6610 "part of library1_name;\n" | 6640 "part of library1_name;\n" |
6611 "external int foo();"; | 6641 "external int foo();"; |
6612 const char* kPatchChars = | 6642 const char* kPatchChars = |
6613 "patch int foo() => 42;"; | 6643 "patch int foo() => 42;"; |
6614 | 6644 |
6615 // Load up a library. | 6645 // Load up a library. |
6616 Dart_Handle url = NewString("library1_url"); | 6646 Dart_Handle url = NewString("library1_url"); |
6617 Dart_Handle source = NewString(kLibrary1Chars); | 6647 Dart_Handle source = NewString(kLibrary1Chars); |
6618 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); | 6648 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6619 EXPECT_VALID(lib); | 6649 EXPECT_VALID(lib); |
6620 EXPECT(Dart_IsLibrary(lib)); | 6650 EXPECT(Dart_IsLibrary(lib)); |
6621 | 6651 |
6622 url = NewString("source_url"); | 6652 url = NewString("source_url"); |
6623 source = NewString(kSourceChars); | 6653 source = NewString(kSourceChars); |
6624 | 6654 |
6625 Dart_Handle result = Dart_LoadSource(lib, url, source, 0, 0); | 6655 Dart_Handle result = Dart_LoadSource(lib, url, Dart_Null(), source, 0, 0); |
6626 EXPECT_VALID(result); | 6656 EXPECT_VALID(result); |
6627 | 6657 |
6628 url = NewString("patch_url"); | 6658 url = NewString("patch_url"); |
6629 source = NewString(kPatchChars); | 6659 source = NewString(kPatchChars); |
6630 | 6660 |
6631 result = Dart_LibraryLoadPatch(lib, url, source); | 6661 result = Dart_LibraryLoadPatch(lib, url, source); |
6632 EXPECT_VALID(result); | 6662 EXPECT_VALID(result); |
6633 result = Dart_FinalizeLoading(false); | 6663 result = Dart_FinalizeLoading(false); |
6634 EXPECT_VALID(result); | 6664 EXPECT_VALID(result); |
6635 | 6665 |
(...skipping 27 matching lines...) Expand all Loading... |
6663 " return x + y;\n" | 6693 " return x + y;\n" |
6664 " }\n" | 6694 " }\n" |
6665 "}"; | 6695 "}"; |
6666 | 6696 |
6667 bool old_flag_value = FLAG_ignore_patch_signature_mismatch; | 6697 bool old_flag_value = FLAG_ignore_patch_signature_mismatch; |
6668 FLAG_ignore_patch_signature_mismatch = true; | 6698 FLAG_ignore_patch_signature_mismatch = true; |
6669 | 6699 |
6670 // Load up a library. | 6700 // Load up a library. |
6671 Dart_Handle url = NewString("library1_url"); | 6701 Dart_Handle url = NewString("library1_url"); |
6672 Dart_Handle source = NewString(kLibrary1Chars); | 6702 Dart_Handle source = NewString(kLibrary1Chars); |
6673 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); | 6703 Dart_Handle lib = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6674 EXPECT_VALID(lib); | 6704 EXPECT_VALID(lib); |
6675 EXPECT(Dart_IsLibrary(lib)); | 6705 EXPECT(Dart_IsLibrary(lib)); |
6676 | 6706 |
6677 url = NewString("source_url"); | 6707 url = NewString("source_url"); |
6678 source = NewString(kSourceChars); | 6708 source = NewString(kSourceChars); |
6679 | 6709 |
6680 Dart_Handle result = Dart_LoadSource(lib, url, source, 0, 0); | 6710 Dart_Handle result = Dart_LoadSource(lib, url, Dart_Null(), source, 0, 0); |
6681 EXPECT_VALID(result); | 6711 EXPECT_VALID(result); |
6682 | 6712 |
6683 url = NewString("patch_url"); | 6713 url = NewString("patch_url"); |
6684 source = NewString(kPatchChars); | 6714 source = NewString(kPatchChars); |
6685 | 6715 |
6686 result = Dart_LibraryLoadPatch(lib, url, source); | 6716 result = Dart_LibraryLoadPatch(lib, url, source); |
6687 EXPECT_VALID(result); | 6717 EXPECT_VALID(result); |
6688 result = Dart_FinalizeLoading(false); | 6718 result = Dart_FinalizeLoading(false); |
6689 EXPECT_VALID(result); | 6719 EXPECT_VALID(result); |
6690 | 6720 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6855 ; // NOLINT | 6885 ; // NOLINT |
6856 | 6886 |
6857 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); | 6887 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); |
6858 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); | 6888 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); |
6859 | 6889 |
6860 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); | 6890 Dart_Handle result = Dart_SetLibraryTagHandler(library_handler); |
6861 EXPECT_VALID(result); | 6891 EXPECT_VALID(result); |
6862 | 6892 |
6863 Dart_Handle url = NewString("theLibrary"); | 6893 Dart_Handle url = NewString("theLibrary"); |
6864 Dart_Handle source = NewString(kLibraryChars); | 6894 Dart_Handle source = NewString(kLibraryChars); |
6865 result = Dart_LoadLibrary(url, source, 0, 0); | 6895 result = Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
6866 EXPECT_VALID(result); | 6896 EXPECT_VALID(result); |
6867 | 6897 |
6868 const char* patchNames[] = { "main library patch", | 6898 const char* patchNames[] = { "main library patch", |
6869 "patch class only", | 6899 "patch class only", |
6870 "patch no class" }; | 6900 "patch no class" }; |
6871 const char* patches[] = { kPatchChars, | 6901 const char* patches[] = { kPatchChars, |
6872 kPatchClassOnlyChars, | 6902 kPatchClassOnlyChars, |
6873 kPatchNoClassChars }; | 6903 kPatchNoClassChars }; |
6874 const String& lib_url = String::Handle(String::New("theLibrary")); | 6904 const String& lib_url = String::Handle(String::New("theLibrary")); |
6875 | 6905 |
6876 const Library& lib = Library::Handle(Library::LookupLibrary(thread, lib_url)); | 6906 const Library& lib = Library::Handle(Library::LookupLibrary(thread, lib_url)); |
6877 | 6907 |
6878 for (int i = 0; i < 3; i++) { | 6908 for (int i = 0; i < 3; i++) { |
6879 const String& patch_url = String::Handle(String::New(patchNames[i])); | 6909 const String& patch_url = String::Handle(String::New(patchNames[i])); |
6880 const String& patch_source = String::Handle(String::New(patches[i])); | 6910 const String& patch_source = String::Handle(String::New(patches[i])); |
6881 const Script& patch_script = Script::Handle(Script::New( | 6911 const Script& patch_script = Script::Handle(Script::New( |
6882 patch_url, patch_source, RawScript::kPatchTag)); | 6912 patch_url, patch_source, RawScript::kPatchTag)); |
6883 | 6913 |
6884 const Error& err = Error::Handle(lib.Patch(patch_script)); | 6914 const Error& err = Error::Handle(lib.Patch(patch_script)); |
6885 if (!err.IsNull()) { | 6915 if (!err.IsNull()) { |
6886 OS::Print("Patching error: %s\n", err.ToErrorCString()); | 6916 OS::Print("Patching error: %s\n", err.ToErrorCString()); |
6887 EXPECT(false); | 6917 EXPECT(false); |
6888 } | 6918 } |
6889 } | 6919 } |
6890 result = Dart_SetNativeResolver(result, &PatchNativeResolver, NULL); | 6920 result = Dart_SetNativeResolver(result, &PatchNativeResolver, NULL); |
6891 EXPECT_VALID(result); | 6921 EXPECT_VALID(result); |
6892 | 6922 |
6893 Dart_Handle script_url = NewString("theScript"); | 6923 Dart_Handle script_url = NewString("theScript"); |
6894 source = NewString(kScriptChars); | 6924 source = NewString(kScriptChars); |
6895 Dart_Handle test_script = Dart_LoadScript(script_url, source, 0, 0); | 6925 Dart_Handle test_script = |
| 6926 Dart_LoadScript(script_url, Dart_Null(), source, 0, 0); |
6896 EXPECT_VALID(test_script); | 6927 EXPECT_VALID(test_script); |
6897 result = Dart_FinalizeLoading(false); | 6928 result = Dart_FinalizeLoading(false); |
6898 EXPECT_VALID(result); | 6929 EXPECT_VALID(result); |
6899 | 6930 |
6900 // Make sure that we can compile all of the patched code. | 6931 // Make sure that we can compile all of the patched code. |
6901 result = Dart_CompileAll(); | 6932 result = Dart_CompileAll(); |
6902 EXPECT_VALID(result); | 6933 EXPECT_VALID(result); |
6903 | 6934 |
6904 result = Dart_Invoke(test_script, NewString("e1"), 0, NULL); | 6935 result = Dart_Invoke(test_script, NewString("e1"), 0, NULL); |
6905 EXPECT_ERROR(result, "No top-level method 'unpatched'"); | 6936 EXPECT_ERROR(result, "No top-level method 'unpatched'"); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6989 " static baz() native \"SomeNativeFunction3\";\n" | 7020 " static baz() native \"SomeNativeFunction3\";\n" |
6990 "}"; | 7021 "}"; |
6991 Dart_Handle error = Dart_NewApiError("incoming error"); | 7022 Dart_Handle error = Dart_NewApiError("incoming error"); |
6992 Dart_Handle result; | 7023 Dart_Handle result; |
6993 | 7024 |
6994 // Load a test script. | 7025 // Load a test script. |
6995 Dart_Handle url = NewString(TestCase::url()); | 7026 Dart_Handle url = NewString(TestCase::url()); |
6996 Dart_Handle source = NewString(kScriptChars); | 7027 Dart_Handle source = NewString(kScriptChars); |
6997 result = Dart_SetLibraryTagHandler(library_handler); | 7028 result = Dart_SetLibraryTagHandler(library_handler); |
6998 EXPECT_VALID(result); | 7029 EXPECT_VALID(result); |
6999 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); | 7030 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
7000 EXPECT_VALID(lib); | 7031 EXPECT_VALID(lib); |
7001 result = Dart_FinalizeLoading(false); | 7032 result = Dart_FinalizeLoading(false); |
7002 EXPECT_VALID(result); | 7033 EXPECT_VALID(result); |
7003 EXPECT(Dart_IsLibrary(lib)); | 7034 EXPECT(Dart_IsLibrary(lib)); |
7004 Dart_Handle type = Dart_GetType(lib, NewString("Test"), 0, NULL); | 7035 Dart_Handle type = Dart_GetType(lib, NewString("Test"), 0, NULL); |
7005 EXPECT_VALID(type); | 7036 EXPECT_VALID(type); |
7006 | 7037 |
7007 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1, NULL); | 7038 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1, NULL); |
7008 EXPECT(Dart_IsError(result)); | 7039 EXPECT(Dart_IsError(result)); |
7009 EXPECT_STREQ( | 7040 EXPECT_STREQ( |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7075 const char* kLibrary2Chars = | 7106 const char* kLibrary2Chars = |
7076 "library library2_dart;\n" | 7107 "library library2_dart;\n" |
7077 "import 'library1_dart';\n" | 7108 "import 'library1_dart';\n" |
7078 "var foo;\n"; | 7109 "var foo;\n"; |
7079 Dart_Handle result; | 7110 Dart_Handle result; |
7080 // Create a test library and Load up a test script in it. | 7111 // Create a test library and Load up a test script in it. |
7081 Dart_Handle url = NewString(TestCase::url()); | 7112 Dart_Handle url = NewString(TestCase::url()); |
7082 Dart_Handle source = NewString(kScriptChars); | 7113 Dart_Handle source = NewString(kScriptChars); |
7083 result = Dart_SetLibraryTagHandler(library_handler); | 7114 result = Dart_SetLibraryTagHandler(library_handler); |
7084 EXPECT_VALID(result); | 7115 EXPECT_VALID(result); |
7085 result = Dart_LoadScript(url, source, 0, 0); | 7116 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
7086 | 7117 |
7087 url = NewString("library1_dart"); | 7118 url = NewString("library1_dart"); |
7088 source = NewString(kLibrary1Chars); | 7119 source = NewString(kLibrary1Chars); |
7089 Dart_LoadLibrary(url, source, 0, 0); | 7120 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
7090 | 7121 |
7091 url = NewString("library2_dart"); | 7122 url = NewString("library2_dart"); |
7092 source = NewString(kLibrary2Chars); | 7123 source = NewString(kLibrary2Chars); |
7093 Dart_LoadLibrary(url, source, 0, 0); | 7124 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
7094 | 7125 |
7095 Dart_FinalizeLoading(false); | 7126 Dart_FinalizeLoading(false); |
7096 | 7127 |
7097 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 7128 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
7098 EXPECT_VALID(result); | 7129 EXPECT_VALID(result); |
7099 } | 7130 } |
7100 | 7131 |
7101 | 7132 |
7102 // Test that if the same name is imported from two libraries, it is | 7133 // Test that if the same name is imported from two libraries, it is |
7103 // an error if that name is referenced. | 7134 // an error if that name is referenced. |
7104 TEST_CASE(ImportLibrary3) { | 7135 TEST_CASE(ImportLibrary3) { |
7105 const char* kScriptChars = | 7136 const char* kScriptChars = |
7106 "import 'library2_dart';\n" | 7137 "import 'library2_dart';\n" |
7107 "import 'library1_dart';\n" | 7138 "import 'library1_dart';\n" |
7108 "var foo_top = 10; // foo has dup def. So should be an error.\n" | 7139 "var foo_top = 10; // foo has dup def. So should be an error.\n" |
7109 "main() { foo = 0; }\n"; | 7140 "main() { foo = 0; }\n"; |
7110 const char* kLibrary1Chars = | 7141 const char* kLibrary1Chars = |
7111 "library library1_dart;\n" | 7142 "library library1_dart;\n" |
7112 "var foo;"; | 7143 "var foo;"; |
7113 const char* kLibrary2Chars = | 7144 const char* kLibrary2Chars = |
7114 "library library2_dart;\n" | 7145 "library library2_dart;\n" |
7115 "var foo;"; | 7146 "var foo;"; |
7116 Dart_Handle result; | 7147 Dart_Handle result; |
7117 | 7148 |
7118 // Create a test library and Load up a test script in it. | 7149 // Create a test library and Load up a test script in it. |
7119 Dart_Handle url = NewString(TestCase::url()); | 7150 Dart_Handle url = NewString(TestCase::url()); |
7120 Dart_Handle source = NewString(kScriptChars); | 7151 Dart_Handle source = NewString(kScriptChars); |
7121 result = Dart_SetLibraryTagHandler(library_handler); | 7152 result = Dart_SetLibraryTagHandler(library_handler); |
7122 EXPECT_VALID(result); | 7153 EXPECT_VALID(result); |
7123 result = Dart_LoadScript(url, source, 0, 0); | 7154 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
7124 EXPECT_VALID(result); | 7155 EXPECT_VALID(result); |
7125 | 7156 |
7126 url = NewString("library2_dart"); | 7157 url = NewString("library2_dart"); |
7127 source = NewString(kLibrary2Chars); | 7158 source = NewString(kLibrary2Chars); |
7128 Dart_LoadLibrary(url, source, 0, 0); | 7159 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
7129 | 7160 |
7130 url = NewString("library1_dart"); | 7161 url = NewString("library1_dart"); |
7131 source = NewString(kLibrary1Chars); | 7162 source = NewString(kLibrary1Chars); |
7132 Dart_LoadLibrary(url, source, 0, 0); | 7163 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
7133 result = Dart_FinalizeLoading(false); | 7164 result = Dart_FinalizeLoading(false); |
7134 EXPECT_VALID(result); | 7165 EXPECT_VALID(result); |
7135 | 7166 |
7136 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 7167 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
7137 EXPECT(Dart_IsError(result)); | 7168 EXPECT(Dart_IsError(result)); |
7138 EXPECT_SUBSTRING("NoSuchMethodError", Dart_GetError(result)); | 7169 EXPECT_SUBSTRING("NoSuchMethodError", Dart_GetError(result)); |
7139 } | 7170 } |
7140 | 7171 |
7141 | 7172 |
7142 // Test that if the same name is imported from two libraries, it is | 7173 // Test that if the same name is imported from two libraries, it is |
7143 // not an error if that name is not used. | 7174 // not an error if that name is not used. |
7144 TEST_CASE(ImportLibrary4) { | 7175 TEST_CASE(ImportLibrary4) { |
7145 const char* kScriptChars = | 7176 const char* kScriptChars = |
7146 "import 'library2_dart';\n" | 7177 "import 'library2_dart';\n" |
7147 "import 'library1_dart';\n" | 7178 "import 'library1_dart';\n" |
7148 "main() { }\n"; | 7179 "main() { }\n"; |
7149 const char* kLibrary1Chars = | 7180 const char* kLibrary1Chars = |
7150 "library library1_dart;\n" | 7181 "library library1_dart;\n" |
7151 "var foo;"; | 7182 "var foo;"; |
7152 const char* kLibrary2Chars = | 7183 const char* kLibrary2Chars = |
7153 "library library2_dart;\n" | 7184 "library library2_dart;\n" |
7154 "var foo;"; | 7185 "var foo;"; |
7155 Dart_Handle result; | 7186 Dart_Handle result; |
7156 | 7187 |
7157 // Create a test library and Load up a test script in it. | 7188 // Create a test library and Load up a test script in it. |
7158 Dart_Handle url = NewString(TestCase::url()); | 7189 Dart_Handle url = NewString(TestCase::url()); |
7159 Dart_Handle source = NewString(kScriptChars); | 7190 Dart_Handle source = NewString(kScriptChars); |
7160 result = Dart_SetLibraryTagHandler(library_handler); | 7191 result = Dart_SetLibraryTagHandler(library_handler); |
7161 EXPECT_VALID(result); | 7192 EXPECT_VALID(result); |
7162 result = Dart_LoadScript(url, source, 0, 0); | 7193 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
7163 EXPECT_VALID(result); | 7194 EXPECT_VALID(result); |
7164 | 7195 |
7165 url = NewString("library2_dart"); | 7196 url = NewString("library2_dart"); |
7166 source = NewString(kLibrary2Chars); | 7197 source = NewString(kLibrary2Chars); |
7167 Dart_LoadLibrary(url, source, 0, 0); | 7198 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
7168 | 7199 |
7169 url = NewString("library1_dart"); | 7200 url = NewString("library1_dart"); |
7170 source = NewString(kLibrary1Chars); | 7201 source = NewString(kLibrary1Chars); |
7171 Dart_LoadLibrary(url, source, 0, 0); | 7202 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
7172 Dart_FinalizeLoading(false); | 7203 Dart_FinalizeLoading(false); |
7173 | 7204 |
7174 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 7205 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
7175 EXPECT_VALID(result); | 7206 EXPECT_VALID(result); |
7176 } | 7207 } |
7177 | 7208 |
7178 | 7209 |
7179 TEST_CASE(ImportLibrary5) { | 7210 TEST_CASE(ImportLibrary5) { |
7180 const char* kScriptChars = | 7211 const char* kScriptChars = |
7181 "import 'lib.dart';\n" | 7212 "import 'lib.dart';\n" |
7182 "abstract class Y {\n" | 7213 "abstract class Y {\n" |
7183 " void set handler(void callback(List<int> x));\n" | 7214 " void set handler(void callback(List<int> x));\n" |
7184 "}\n" | 7215 "}\n" |
7185 "void main() {}\n"; | 7216 "void main() {}\n"; |
7186 const char* kLibraryChars = | 7217 const char* kLibraryChars = |
7187 "library lib.dart;\n" | 7218 "library lib.dart;\n" |
7188 "abstract class X {\n" | 7219 "abstract class X {\n" |
7189 " void set handler(void callback(List<int> x));\n" | 7220 " void set handler(void callback(List<int> x));\n" |
7190 "}\n"; | 7221 "}\n"; |
7191 Dart_Handle result; | 7222 Dart_Handle result; |
7192 | 7223 |
7193 // Create a test library and Load up a test script in it. | 7224 // Create a test library and Load up a test script in it. |
7194 Dart_Handle url = NewString(TestCase::url()); | 7225 Dart_Handle url = NewString(TestCase::url()); |
7195 Dart_Handle source = NewString(kScriptChars); | 7226 Dart_Handle source = NewString(kScriptChars); |
7196 result = Dart_SetLibraryTagHandler(library_handler); | 7227 result = Dart_SetLibraryTagHandler(library_handler); |
7197 EXPECT_VALID(result); | 7228 EXPECT_VALID(result); |
7198 result = Dart_LoadScript(url, source, 0, 0); | 7229 result = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
7199 | 7230 |
7200 url = NewString("lib.dart"); | 7231 url = NewString("lib.dart"); |
7201 source = NewString(kLibraryChars); | 7232 source = NewString(kLibraryChars); |
7202 Dart_LoadLibrary(url, source, 0, 0); | 7233 Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
7203 Dart_FinalizeLoading(false); | 7234 Dart_FinalizeLoading(false); |
7204 | 7235 |
7205 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 7236 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
7206 EXPECT_VALID(result); | 7237 EXPECT_VALID(result); |
7207 } | 7238 } |
7208 | 7239 |
7209 | 7240 |
7210 void NewNativePort_send123(Dart_Port dest_port_id, | 7241 void NewNativePort_send123(Dart_Port dest_port_id, |
7211 Dart_CObject *message) { | 7242 Dart_CObject *message) { |
7212 // Gets a send port message. | 7243 // Gets a send port message. |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7531 Dart_Isolate isolate = TestCase::CreateTestIsolate(script_name); | 7562 Dart_Isolate isolate = TestCase::CreateTestIsolate(script_name); |
7532 ASSERT(isolate != NULL); | 7563 ASSERT(isolate != NULL); |
7533 if (Dart_IsServiceIsolate(isolate)) { | 7564 if (Dart_IsServiceIsolate(isolate)) { |
7534 return isolate; | 7565 return isolate; |
7535 } | 7566 } |
7536 Dart_EnterScope(); | 7567 Dart_EnterScope(); |
7537 Dart_Handle url = NewString(TestCase::url()); | 7568 Dart_Handle url = NewString(TestCase::url()); |
7538 Dart_Handle source = NewString(kScriptChars); | 7569 Dart_Handle source = NewString(kScriptChars); |
7539 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | 7570 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
7540 EXPECT_VALID(result); | 7571 EXPECT_VALID(result); |
7541 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); | 7572 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
7542 EXPECT_VALID(lib); | 7573 EXPECT_VALID(lib); |
7543 result = Dart_FinalizeLoading(false); | 7574 result = Dart_FinalizeLoading(false); |
7544 EXPECT_VALID(result); | 7575 EXPECT_VALID(result); |
7545 Dart_ExitScope(); | 7576 Dart_ExitScope(); |
7546 Dart_ExitIsolate(); | 7577 Dart_ExitIsolate(); |
7547 bool retval = Dart_IsolateMakeRunnable(isolate); | 7578 bool retval = Dart_IsolateMakeRunnable(isolate); |
7548 EXPECT(retval); | 7579 EXPECT(retval); |
7549 return isolate; | 7580 return isolate; |
7550 } | 7581 } |
7551 | 7582 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7638 shared_isolate = Dart_CreateIsolate(NULL, NULL, | 7669 shared_isolate = Dart_CreateIsolate(NULL, NULL, |
7639 bin::isolate_snapshot_buffer, | 7670 bin::isolate_snapshot_buffer, |
7640 NULL, | 7671 NULL, |
7641 NULL, &error); | 7672 NULL, &error); |
7642 EXPECT(shared_isolate != NULL); | 7673 EXPECT(shared_isolate != NULL); |
7643 Dart_EnterScope(); | 7674 Dart_EnterScope(); |
7644 Dart_Handle url = NewString(TestCase::url()); | 7675 Dart_Handle url = NewString(TestCase::url()); |
7645 Dart_Handle source = NewString(kScriptChars); | 7676 Dart_Handle source = NewString(kScriptChars); |
7646 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | 7677 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
7647 EXPECT_VALID(result); | 7678 EXPECT_VALID(result); |
7648 lib = Dart_LoadScript(url, source, 0, 0); | 7679 lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
7649 EXPECT_VALID(lib); | 7680 EXPECT_VALID(lib); |
7650 result = Dart_FinalizeLoading(false); | 7681 result = Dart_FinalizeLoading(false); |
7651 EXPECT_VALID(result); | 7682 EXPECT_VALID(result); |
7652 result = | 7683 result = |
7653 Dart_SetNativeResolver(lib, &IsolateInterruptTestNativeLookup, NULL); | 7684 Dart_SetNativeResolver(lib, &IsolateInterruptTestNativeLookup, NULL); |
7654 DART_CHECK_VALID(result); | 7685 DART_CHECK_VALID(result); |
7655 | 7686 |
7656 ml.Notify(); | 7687 ml.Notify(); |
7657 } | 7688 } |
7658 | 7689 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7751 EXPECT(isolate != NULL); | 7782 EXPECT(isolate != NULL); |
7752 | 7783 |
7753 Isolate::SetShutdownCallback(IsolateShutdownRunDartCodeTestCallback); | 7784 Isolate::SetShutdownCallback(IsolateShutdownRunDartCodeTestCallback); |
7754 | 7785 |
7755 { | 7786 { |
7756 Dart_EnterScope(); | 7787 Dart_EnterScope(); |
7757 Dart_Handle url = NewString(TestCase::url()); | 7788 Dart_Handle url = NewString(TestCase::url()); |
7758 Dart_Handle source = NewString(kScriptChars); | 7789 Dart_Handle source = NewString(kScriptChars); |
7759 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | 7790 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
7760 EXPECT_VALID(result); | 7791 EXPECT_VALID(result); |
7761 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); | 7792 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
7762 EXPECT_VALID(lib); | 7793 EXPECT_VALID(lib); |
7763 result = Dart_FinalizeLoading(false); | 7794 result = Dart_FinalizeLoading(false); |
7764 EXPECT_VALID(result); | 7795 EXPECT_VALID(result); |
7765 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 7796 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
7766 EXPECT_VALID(result); | 7797 EXPECT_VALID(result); |
7767 Dart_ExitScope(); | 7798 Dart_ExitScope(); |
7768 } | 7799 } |
7769 | 7800 |
7770 | 7801 |
7771 // The shutdown callback has not been called. | 7802 // The shutdown callback has not been called. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7930 " return 0;\n" | 7961 " return 0;\n" |
7931 "}\n"; | 7962 "}\n"; |
7932 | 7963 |
7933 Dart_Handle result; | 7964 Dart_Handle result; |
7934 | 7965 |
7935 // Load a test script. | 7966 // Load a test script. |
7936 Dart_Handle url = NewString(TestCase::url()); | 7967 Dart_Handle url = NewString(TestCase::url()); |
7937 Dart_Handle source = NewString(kScriptChars); | 7968 Dart_Handle source = NewString(kScriptChars); |
7938 result = Dart_SetLibraryTagHandler(library_handler); | 7969 result = Dart_SetLibraryTagHandler(library_handler); |
7939 EXPECT_VALID(result); | 7970 EXPECT_VALID(result); |
7940 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); | 7971 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
7941 EXPECT_VALID(lib); | 7972 EXPECT_VALID(lib); |
7942 EXPECT(Dart_IsLibrary(lib)); | 7973 EXPECT(Dart_IsLibrary(lib)); |
7943 result = Dart_SetNativeResolver(lib, &MyNativeClosureResolver, NULL); | 7974 result = Dart_SetNativeResolver(lib, &MyNativeClosureResolver, NULL); |
7944 EXPECT_VALID(result); | 7975 EXPECT_VALID(result); |
7945 result = Dart_FinalizeLoading(false); | 7976 result = Dart_FinalizeLoading(false); |
7946 EXPECT_VALID(result); | 7977 EXPECT_VALID(result); |
7947 | 7978 |
7948 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 7979 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
7949 EXPECT_VALID(result); | 7980 EXPECT_VALID(result); |
7950 EXPECT(Dart_IsInteger(result)); | 7981 EXPECT(Dart_IsInteger(result)); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8079 " return 0;\n" | 8110 " return 0;\n" |
8080 "}\n"; | 8111 "}\n"; |
8081 | 8112 |
8082 Dart_Handle result; | 8113 Dart_Handle result; |
8083 | 8114 |
8084 // Load a test script. | 8115 // Load a test script. |
8085 Dart_Handle url = NewString(TestCase::url()); | 8116 Dart_Handle url = NewString(TestCase::url()); |
8086 Dart_Handle source = NewString(kScriptChars); | 8117 Dart_Handle source = NewString(kScriptChars); |
8087 result = Dart_SetLibraryTagHandler(library_handler); | 8118 result = Dart_SetLibraryTagHandler(library_handler); |
8088 EXPECT_VALID(result); | 8119 EXPECT_VALID(result); |
8089 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); | 8120 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); |
8090 EXPECT_VALID(lib); | 8121 EXPECT_VALID(lib); |
8091 EXPECT(Dart_IsLibrary(lib)); | 8122 EXPECT(Dart_IsLibrary(lib)); |
8092 result = Dart_SetNativeResolver(lib, &MyStaticNativeClosureResolver, NULL); | 8123 result = Dart_SetNativeResolver(lib, &MyStaticNativeClosureResolver, NULL); |
8093 EXPECT_VALID(result); | 8124 EXPECT_VALID(result); |
8094 result = Dart_FinalizeLoading(false); | 8125 result = Dart_FinalizeLoading(false); |
8095 EXPECT_VALID(result); | 8126 EXPECT_VALID(result); |
8096 | 8127 |
8097 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 8128 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
8098 EXPECT_VALID(result); | 8129 EXPECT_VALID(result); |
8099 EXPECT(Dart_IsInteger(result)); | 8130 EXPECT(Dart_IsInteger(result)); |
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8848 Dart_Handle result; | 8879 Dart_Handle result; |
8849 // Create a test library and Load up a test script in it. | 8880 // Create a test library and Load up a test script in it. |
8850 Dart_Handle lib1 = TestCase::LoadTestScript(kLoadFirst, NULL); | 8881 Dart_Handle lib1 = TestCase::LoadTestScript(kLoadFirst, NULL); |
8851 Dart_Handle dart_args[1]; | 8882 Dart_Handle dart_args[1]; |
8852 dart_args[0] = Dart_NewInteger(0); | 8883 dart_args[0] = Dart_NewInteger(0); |
8853 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); | 8884 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); |
8854 EXPECT_VALID(result); | 8885 EXPECT_VALID(result); |
8855 | 8886 |
8856 Dart_Handle source = NewString(kLoadSecond); | 8887 Dart_Handle source = NewString(kLoadSecond); |
8857 Dart_Handle url = NewString(TestCase::url()); | 8888 Dart_Handle url = NewString(TestCase::url()); |
8858 Dart_LoadSource(TestCase::lib(), url, source, 0, 0); | 8889 Dart_LoadSource(TestCase::lib(), url, Dart_Null(), source, 0, 0); |
8859 result = Dart_FinalizeLoading(false); | 8890 result = Dart_FinalizeLoading(false); |
8860 EXPECT_VALID(result); | 8891 EXPECT_VALID(result); |
8861 | 8892 |
8862 dart_args[0] = Dart_NewInteger(1); | 8893 dart_args[0] = Dart_NewInteger(1); |
8863 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); | 8894 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); |
8864 EXPECT_VALID(result); | 8895 EXPECT_VALID(result); |
8865 } | 8896 } |
8866 | 8897 |
8867 | 8898 |
8868 // Test external strings and optimized code. | 8899 // Test external strings and optimized code. |
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10156 result = Dart_Invoke(lib, | 10187 result = Dart_Invoke(lib, |
10157 NewString("foozoo"), | 10188 NewString("foozoo"), |
10158 0, | 10189 0, |
10159 NULL); | 10190 NULL); |
10160 EXPECT(Dart_IsError(result)); | 10191 EXPECT(Dart_IsError(result)); |
10161 } | 10192 } |
10162 | 10193 |
10163 #endif // !PRODUCT | 10194 #endif // !PRODUCT |
10164 | 10195 |
10165 } // namespace dart | 10196 } // namespace dart |
OLD | NEW |