Chromium Code Reviews| 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/json.h" | 7 #include "platform/json.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 2590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2601 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields")); | 2601 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields")); |
| 2602 EXPECT_VALID(cls); | 2602 EXPECT_VALID(cls); |
| 2603 Dart_Handle instance = Dart_Invoke(lib, Dart_NewString("test"), 0, NULL); | 2603 Dart_Handle instance = Dart_Invoke(lib, Dart_NewString("test"), 0, NULL); |
| 2604 EXPECT_VALID(instance); | 2604 EXPECT_VALID(instance); |
| 2605 Dart_Handle name; | 2605 Dart_Handle name; |
| 2606 | 2606 |
| 2607 // Load imported lib. | 2607 // Load imported lib. |
| 2608 Dart_Handle url = Dart_NewString("library_url"); | 2608 Dart_Handle url = Dart_NewString("library_url"); |
| 2609 Dart_Handle source = Dart_NewString(kImportedScriptChars); | 2609 Dart_Handle source = Dart_NewString(kImportedScriptChars); |
| 2610 Dart_Handle imported_lib = Dart_LoadLibrary(url, source); | 2610 Dart_Handle imported_lib = Dart_LoadLibrary(url, source); |
| 2611 Dart_Handle prefix = Dart_NewString(""); | |
| 2611 EXPECT_VALID(imported_lib); | 2612 EXPECT_VALID(imported_lib); |
| 2612 Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib); | 2613 Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib, prefix); |
| 2613 EXPECT_VALID(result); | 2614 EXPECT_VALID(result); |
| 2614 result = Dart_Invoke(imported_lib, Dart_NewString("test2"), 0, NULL); | 2615 result = Dart_Invoke(imported_lib, Dart_NewString("test2"), 0, NULL); |
| 2615 EXPECT_VALID(result); | 2616 EXPECT_VALID(result); |
| 2616 | 2617 |
| 2617 // Instance field. | 2618 // Instance field. |
| 2618 name = Dart_NewString("instance_fld"); | 2619 name = Dart_NewString("instance_fld"); |
| 2619 TestFieldNotFound(lib, name); | 2620 TestFieldNotFound(lib, name); |
| 2620 TestFieldNotFound(cls, name); | 2621 TestFieldNotFound(cls, name); |
| 2621 TestFieldOk(instance, name, false, "instance"); | 2622 TestFieldOk(instance, name, false, "instance"); |
| 2622 | 2623 |
| (...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3689 // Load lib1 | 3690 // Load lib1 |
| 3690 Dart_Handle url = Dart_NewString("library1_url"); | 3691 Dart_Handle url = Dart_NewString("library1_url"); |
| 3691 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 3692 Dart_Handle source = Dart_NewString(kLibrary1Chars); |
| 3692 Dart_Handle lib1 = Dart_LoadLibrary(url, source); | 3693 Dart_Handle lib1 = Dart_LoadLibrary(url, source); |
| 3693 EXPECT_VALID(lib1); | 3694 EXPECT_VALID(lib1); |
| 3694 | 3695 |
| 3695 // Load lib2 | 3696 // Load lib2 |
| 3696 url = Dart_NewString("library2_url"); | 3697 url = Dart_NewString("library2_url"); |
| 3697 source = Dart_NewString(kLibrary2Chars); | 3698 source = Dart_NewString(kLibrary2Chars); |
| 3698 Dart_Handle lib2 = Dart_LoadLibrary(url, source); | 3699 Dart_Handle lib2 = Dart_LoadLibrary(url, source); |
| 3700 Dart_Handle prefix = Dart_NewString(""); | |
| 3699 EXPECT_VALID(lib2); | 3701 EXPECT_VALID(lib2); |
| 3700 | 3702 |
| 3701 // Import lib2 from lib1 | 3703 // Import lib2 from lib1 |
| 3702 Dart_Handle result = Dart_LibraryImportLibrary(lib1, lib2); | 3704 Dart_Handle result = Dart_LibraryImportLibrary(lib1, lib2, prefix); |
| 3703 EXPECT_VALID(result); | 3705 EXPECT_VALID(result); |
| 3704 | 3706 |
| 3705 // We can invoke both private and non-private local functions. | 3707 // We can invoke both private and non-private local functions. |
| 3706 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("local"), 0, NULL)); | 3708 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("local"), 0, NULL)); |
| 3707 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("_local"), 0, NULL)); | 3709 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("_local"), 0, NULL)); |
| 3708 | 3710 |
| 3709 // We can only invoke non-private imported functions. | 3711 // We can only invoke non-private imported functions. |
| 3710 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("imported"), 0, NULL)); | 3712 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("imported"), 0, NULL)); |
| 3711 EXPECT_ERROR(Dart_Invoke(lib1, Dart_NewString("_imported"), 0, NULL), | 3713 EXPECT_ERROR(Dart_Invoke(lib1, Dart_NewString("_imported"), 0, NULL), |
| 3712 "did not find top-level function '_imported'"); | 3714 "did not find top-level function '_imported'"); |
| (...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5236 Dart_Handle result; | 5238 Dart_Handle result; |
| 5237 | 5239 |
| 5238 Dart_Handle url = Dart_NewString("library1_url"); | 5240 Dart_Handle url = Dart_NewString("library1_url"); |
| 5239 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 5241 Dart_Handle source = Dart_NewString(kLibrary1Chars); |
| 5240 Dart_Handle lib1 = Dart_LoadLibrary(url, source); | 5242 Dart_Handle lib1 = Dart_LoadLibrary(url, source); |
| 5241 EXPECT_VALID(lib1); | 5243 EXPECT_VALID(lib1); |
| 5242 | 5244 |
| 5243 url = Dart_NewString("library2_url"); | 5245 url = Dart_NewString("library2_url"); |
| 5244 source = Dart_NewString(kLibrary2Chars); | 5246 source = Dart_NewString(kLibrary2Chars); |
| 5245 Dart_Handle lib2 = Dart_LoadLibrary(url, source); | 5247 Dart_Handle lib2 = Dart_LoadLibrary(url, source); |
| 5248 Dart_Handle prefix = Dart_NewString(""); | |
| 5246 EXPECT_VALID(lib2); | 5249 EXPECT_VALID(lib2); |
| 5247 | 5250 |
| 5248 result = Dart_LibraryImportLibrary(Dart_Null(), lib2); | 5251 result = Dart_LibraryImportLibrary(Dart_Null(), lib2, prefix); |
| 5249 EXPECT(Dart_IsError(result)); | 5252 EXPECT(Dart_IsError(result)); |
| 5250 EXPECT_STREQ( | 5253 EXPECT_STREQ( |
| 5251 "Dart_LibraryImportLibrary expects argument 'library' to be non-null.", | 5254 "Dart_LibraryImportLibrary expects argument 'library' to be non-null.", |
| 5252 Dart_GetError(result)); | 5255 Dart_GetError(result)); |
| 5253 | 5256 |
| 5254 result = Dart_LibraryImportLibrary(Dart_True(), lib2); | 5257 result = Dart_LibraryImportLibrary(Dart_True(), lib2, prefix); |
| 5255 EXPECT(Dart_IsError(result)); | 5258 EXPECT(Dart_IsError(result)); |
| 5256 EXPECT_STREQ("Dart_LibraryImportLibrary expects argument 'library' to be of " | 5259 EXPECT_STREQ("Dart_LibraryImportLibrary expects argument 'library' to be of " |
| 5257 "type Library.", | 5260 "type Library.", |
| 5258 Dart_GetError(result)); | 5261 Dart_GetError(result)); |
| 5259 | 5262 |
| 5260 result = Dart_LibraryImportLibrary(error, lib2); | 5263 result = Dart_LibraryImportLibrary(error, lib2, prefix); |
| 5261 EXPECT(Dart_IsError(result)); | 5264 EXPECT(Dart_IsError(result)); |
| 5262 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 5265 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| 5263 | 5266 |
| 5264 result = Dart_LibraryImportLibrary(lib1, Dart_Null()); | 5267 result = Dart_LibraryImportLibrary(lib1, Dart_Null(), prefix); |
| 5265 EXPECT(Dart_IsError(result)); | 5268 EXPECT(Dart_IsError(result)); |
| 5266 EXPECT_STREQ( | 5269 EXPECT_STREQ( |
| 5267 "Dart_LibraryImportLibrary expects argument 'import' to be non-null.", | 5270 "Dart_LibraryImportLibrary expects argument 'import' to be non-null.", |
| 5268 Dart_GetError(result)); | 5271 Dart_GetError(result)); |
| 5269 | 5272 |
| 5270 result = Dart_LibraryImportLibrary(lib1, Dart_True()); | 5273 result = Dart_LibraryImportLibrary(lib1, Dart_True(), prefix); |
| 5271 EXPECT(Dart_IsError(result)); | 5274 EXPECT(Dart_IsError(result)); |
| 5272 EXPECT_STREQ("Dart_LibraryImportLibrary expects argument 'import' to be of " | 5275 EXPECT_STREQ("Dart_LibraryImportLibrary expects argument 'import' to be of " |
| 5273 "type Library.", | 5276 "type Library.", |
| 5274 Dart_GetError(result)); | 5277 Dart_GetError(result)); |
| 5275 | 5278 |
| 5276 result = Dart_LibraryImportLibrary(lib1, error); | 5279 result = Dart_LibraryImportLibrary(lib1, error, prefix); |
| 5277 EXPECT(Dart_IsError(result)); | 5280 EXPECT(Dart_IsError(result)); |
| 5278 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 5281 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| 5279 | 5282 |
| 5280 result = Dart_LibraryImportLibrary(lib1, lib2); | 5283 result = Dart_LibraryImportLibrary(lib1, lib2, prefix); |
| 5281 EXPECT_VALID(result); | 5284 EXPECT_VALID(result); |
| 5282 } | 5285 } |
| 5283 | 5286 |
| 5284 | 5287 |
| 5288 TEST_CASE(ImportLibraryWithPrefix) { | |
| 5289 const char* kLibrary1Chars = | |
| 5290 "#library('library1_name');" | |
| 5291 "int foo() => 42;"; | |
| 5292 Dart_Handle url1 = Dart_NewString("library1_url"); | |
| 5293 Dart_Handle source1 = Dart_NewString(kLibrary1Chars); | |
| 5294 Dart_Handle lib1 = Dart_LoadLibrary(url1, source1); | |
| 5295 EXPECT_VALID(lib1); | |
| 5296 EXPECT(Dart_IsLibrary(lib1)); | |
| 5297 | |
| 5298 const char* kLibrary2Chars = | |
| 5299 "#library('library2_name');"; | |
|
Ivan Posva
2012/08/28 23:22:02
Also add a test that something in the prefixed lib
Mads Ager (google)
2012/08/29 05:52:10
Done.
| |
| 5300 Dart_Handle url2 = Dart_NewString("library2_url"); | |
| 5301 Dart_Handle source2 = Dart_NewString(kLibrary2Chars); | |
| 5302 Dart_Handle lib2 = Dart_LoadLibrary(url2, source2); | |
| 5303 EXPECT_VALID(lib2); | |
| 5304 EXPECT(Dart_IsLibrary(lib2)); | |
| 5305 | |
| 5306 Dart_Handle prefix = Dart_NewString("bar"); | |
| 5307 Dart_Handle result = Dart_LibraryImportLibrary(lib2, lib1, prefix); | |
| 5308 EXPECT_VALID(result); | |
| 5309 | |
| 5310 // Lib1 is imported under a library prefix and therefore 'foo' should | |
| 5311 // not be found directly in lib2. | |
| 5312 Dart_Handle method_name = Dart_NewString("foo"); | |
| 5313 result = Dart_Invoke(lib2, method_name, 0, NULL); | |
| 5314 EXPECT_ERROR(result, "Dart_Invoke: did not find top-level function 'foo'"); | |
| 5315 } | |
| 5316 | |
| 5317 | |
| 5285 | 5318 |
| 5286 TEST_CASE(LoadLibrary) { | 5319 TEST_CASE(LoadLibrary) { |
| 5287 const char* kLibrary1Chars = | 5320 const char* kLibrary1Chars = |
| 5288 "#library('library1_name');"; | 5321 "#library('library1_name');"; |
| 5289 Dart_Handle error = Dart_Error("incoming error"); | 5322 Dart_Handle error = Dart_Error("incoming error"); |
| 5290 Dart_Handle result; | 5323 Dart_Handle result; |
| 5291 | 5324 |
| 5292 Dart_Handle url = Dart_NewString("library1_url"); | 5325 Dart_Handle url = Dart_NewString("library1_url"); |
| 5293 Dart_Handle source = Dart_NewString(kLibrary1Chars); | 5326 Dart_Handle source = Dart_NewString(kLibrary1Chars); |
| 5294 | 5327 |
| (...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6522 EXPECT(Dart_IsString(str)); | 6555 EXPECT(Dart_IsString(str)); |
| 6523 len = -1; | 6556 len = -1; |
| 6524 EXPECT_VALID(Dart_StringLength(str, &len)); | 6557 EXPECT_VALID(Dart_StringLength(str, &len)); |
| 6525 EXPECT_EQ(0, len); | 6558 EXPECT_EQ(0, len); |
| 6526 } | 6559 } |
| 6527 | 6560 |
| 6528 | 6561 |
| 6529 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 6562 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 6530 | 6563 |
| 6531 } // namespace dart | 6564 } // namespace dart |
| OLD | NEW |