| 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 5671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5682 | 5682 |
| 5683 // A NULL resolver is okay, but resolution will fail. | 5683 // A NULL resolver is okay, but resolution will fail. |
| 5684 result = Dart_SetNativeResolver(lib, NULL); | 5684 result = Dart_SetNativeResolver(lib, NULL); |
| 5685 EXPECT_VALID(result); | 5685 EXPECT_VALID(result); |
| 5686 | 5686 |
| 5687 EXPECT_ERROR(Dart_Invoke(cls, Dart_NewString("baz"), 0, NULL), | 5687 EXPECT_ERROR(Dart_Invoke(cls, Dart_NewString("baz"), 0, NULL), |
| 5688 "native function 'SomeNativeFunction3' cannot be found"); | 5688 "native function 'SomeNativeFunction3' cannot be found"); |
| 5689 } | 5689 } |
| 5690 | 5690 |
| 5691 | 5691 |
| 5692 TEST_CASE(ImportLibrary1) { | 5692 // Test that an imported name does not clash with the same name defined |
| 5693 // in the importing library. |
| 5694 TEST_CASE(ImportLibrary2) { |
| 5693 const char* kScriptChars = | 5695 const char* kScriptChars = |
| 5694 "#import('library1.dart');" | 5696 "#import('library1.dart');\n" |
| 5695 "#import('library2.dart');" | 5697 "var foo;\n" |
| 5696 "var foo; // library2 defines foo, so should be error." | 5698 "main() { foo = 0; }\n"; |
| 5697 "main() {}"; | |
| 5698 const char* kLibrary1Chars = | 5699 const char* kLibrary1Chars = |
| 5699 "#library('library1.dart');" | 5700 "#library('library1.dart');\n" |
| 5700 "#import('library2.dart');" | 5701 "#import('library2.dart');\n" |
| 5701 "var foo1;"; | 5702 "var foo;\n"; |
| 5702 const char* kLibrary2Chars = | 5703 const char* kLibrary2Chars = |
| 5703 "#library('library2.dart');" | 5704 "#library('library2.dart');\n" |
| 5704 "var foo;"; | 5705 "#import('library1.dart');\n" |
| 5706 "var foo;\n"; |
| 5705 Dart_Handle result; | 5707 Dart_Handle result; |
| 5706 // Create a test library and Load up a test script in it. | 5708 // Create a test library and Load up a test script in it. |
| 5707 Dart_Handle url = Dart_NewString(TestCase::url()); | 5709 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 5708 Dart_Handle source = Dart_NewString(kScriptChars); | |
| 5709 result = Dart_SetLibraryTagHandler(library_handler); | |
| 5710 EXPECT_VALID(result); | |
| 5711 result = Dart_LoadScript(url, source); | |
| 5712 | |
| 5713 url = Dart_NewString("library1.dart"); | |
| 5714 source = Dart_NewString(kLibrary1Chars); | |
| 5715 Dart_LoadLibrary(url, source); | |
| 5716 | |
| 5717 url = Dart_NewString("library2.dart"); | |
| 5718 source = Dart_NewString(kLibrary2Chars); | |
| 5719 Dart_LoadLibrary(url, source); | |
| 5720 | |
| 5721 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); | |
| 5722 EXPECT(Dart_IsError(result)); | |
| 5723 EXPECT_STREQ("Duplicate definition : 'foo' is defined in" | |
| 5724 " 'library2.dart' and 'dart:test-lib'", | |
| 5725 Dart_GetError(result)); | |
| 5726 } | |
| 5727 | |
| 5728 | |
| 5729 TEST_CASE(ImportLibrary2) { | |
| 5730 const char* kScriptChars = | |
| 5731 "#import('library1.dart');" | |
| 5732 "var foo;" | |
| 5733 "main() {}"; | |
| 5734 const char* kLibrary1Chars = | |
| 5735 "#library('library1.dart');" | |
| 5736 "#import('library2.dart');" | |
| 5737 "var foo1;"; | |
| 5738 const char* kLibrary2Chars = | |
| 5739 "#library('library2.dart');" | |
| 5740 "#import('library1.dart');" | |
| 5741 "var foo;"; | |
| 5742 Dart_Handle result; | |
| 5743 // Create a test library and Load up a test script in it. | |
| 5744 Dart_Handle url = Dart_NewString(TestCase::url()); | |
| 5745 Dart_Handle source = Dart_NewString(kScriptChars); | 5710 Dart_Handle source = Dart_NewString(kScriptChars); |
| 5746 result = Dart_SetLibraryTagHandler(library_handler); | 5711 result = Dart_SetLibraryTagHandler(library_handler); |
| 5747 EXPECT_VALID(result); | 5712 EXPECT_VALID(result); |
| 5748 result = Dart_LoadScript(url, source); | 5713 result = Dart_LoadScript(url, source); |
| 5749 | 5714 |
| 5750 url = Dart_NewString("library1.dart"); | 5715 url = Dart_NewString("library1.dart"); |
| 5751 source = Dart_NewString(kLibrary1Chars); | 5716 source = Dart_NewString(kLibrary1Chars); |
| 5752 Dart_LoadLibrary(url, source); | 5717 Dart_LoadLibrary(url, source); |
| 5753 | 5718 |
| 5754 url = Dart_NewString("library2.dart"); | 5719 url = Dart_NewString("library2.dart"); |
| 5755 source = Dart_NewString(kLibrary2Chars); | 5720 source = Dart_NewString(kLibrary2Chars); |
| 5756 Dart_LoadLibrary(url, source); | 5721 Dart_LoadLibrary(url, source); |
| 5757 | 5722 |
| 5758 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); | 5723 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); |
| 5759 EXPECT_VALID(result); | 5724 EXPECT_VALID(result); |
| 5760 } | 5725 } |
| 5761 | 5726 |
| 5762 | 5727 |
| 5728 // Test that if the same name is imported from two libraries, it is |
| 5729 // an error if that name is referenced. |
| 5763 TEST_CASE(ImportLibrary3) { | 5730 TEST_CASE(ImportLibrary3) { |
| 5764 const char* kScriptChars = | 5731 const char* kScriptChars = |
| 5765 "#import('library2.dart');" | 5732 "#import('library2.dart');\n" |
| 5766 "#import('library1.dart');" | 5733 "#import('library1.dart');\n" |
| 5767 "var foo_top = 10; // foo has dup def. So should be an error." | 5734 "var foo_top = 10; // foo has dup def. So should be an error.\n" |
| 5768 "main() {}"; | 5735 "main() { foo = 0; }\n"; |
| 5769 const char* kLibrary1Chars = | 5736 const char* kLibrary1Chars = |
| 5770 "#library('library1.dart');" | 5737 "#library('library1.dart');\n" |
| 5771 "var foo;"; | 5738 "var foo;"; |
| 5772 const char* kLibrary2Chars = | 5739 const char* kLibrary2Chars = |
| 5773 "#library('library2.dart');" | 5740 "#library('library2.dart');\n" |
| 5774 "var foo;"; | 5741 "var foo;"; |
| 5775 Dart_Handle result; | 5742 Dart_Handle result; |
| 5776 | 5743 |
| 5777 // Create a test library and Load up a test script in it. | 5744 // Create a test library and Load up a test script in it. |
| 5778 Dart_Handle url = Dart_NewString(TestCase::url()); | 5745 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 5779 Dart_Handle source = Dart_NewString(kScriptChars); | 5746 Dart_Handle source = Dart_NewString(kScriptChars); |
| 5780 result = Dart_SetLibraryTagHandler(library_handler); | 5747 result = Dart_SetLibraryTagHandler(library_handler); |
| 5781 EXPECT_VALID(result); | 5748 EXPECT_VALID(result); |
| 5782 result = Dart_LoadScript(url, source); | 5749 result = Dart_LoadScript(url, source); |
| 5750 EXPECT_VALID(result); |
| 5783 | 5751 |
| 5784 url = Dart_NewString("library2.dart"); | 5752 url = Dart_NewString("library2.dart"); |
| 5785 source = Dart_NewString(kLibrary2Chars); | 5753 source = Dart_NewString(kLibrary2Chars); |
| 5786 Dart_LoadLibrary(url, source); | 5754 Dart_LoadLibrary(url, source); |
| 5787 | 5755 |
| 5788 url = Dart_NewString("library1.dart"); | 5756 url = Dart_NewString("library1.dart"); |
| 5789 source = Dart_NewString(kLibrary1Chars); | 5757 source = Dart_NewString(kLibrary1Chars); |
| 5790 Dart_LoadLibrary(url, source); | 5758 Dart_LoadLibrary(url, source); |
| 5791 | 5759 |
| 5792 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); | 5760 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); |
| 5793 EXPECT(Dart_IsError(result)); | 5761 EXPECT(Dart_IsError(result)); |
| 5794 EXPECT_STREQ("Duplicate definition : 'foo' is defined in" | 5762 EXPECT_SUBSTRING("ambiguous reference: 'foo'", Dart_GetError(result)); |
| 5795 " 'library2.dart' and 'library1.dart'", | |
| 5796 Dart_GetError(result)); | |
| 5797 } | 5763 } |
| 5798 | 5764 |
| 5799 | 5765 |
| 5766 // Test that if the same name is imported from two libraries, it is |
| 5767 // not an error if that name is not used. |
| 5800 TEST_CASE(ImportLibrary4) { | 5768 TEST_CASE(ImportLibrary4) { |
| 5801 const char* kScriptChars = | 5769 const char* kScriptChars = |
| 5802 "#import('libraryA.dart');" | 5770 "#import('library2.dart');\n" |
| 5803 "#import('libraryB.dart');" | 5771 "#import('library1.dart');\n" |
| 5804 "#import('libraryD.dart');" | 5772 "main() { }\n"; |
| 5805 "#import('libraryE.dart');" | 5773 const char* kLibrary1Chars = |
| 5806 "var fooApp;" | 5774 "#library('library1.dart');\n" |
| 5807 "main() {}"; | 5775 "var foo;"; |
| 5808 const char* kLibraryAChars = | 5776 const char* kLibrary2Chars = |
| 5809 "#library('libraryA.dart');" | 5777 "#library('library2.dart');\n" |
| 5810 "#import('libraryC.dart');" | 5778 "var foo;"; |
| 5811 "var fooA;"; | |
| 5812 const char* kLibraryBChars = | |
| 5813 "#library('libraryB.dart');" | |
| 5814 "#import('libraryC.dart');" | |
| 5815 "var fooB;"; | |
| 5816 const char* kLibraryCChars = | |
| 5817 "#library('libraryC.dart');" | |
| 5818 "var fooC;"; | |
| 5819 const char* kLibraryDChars = | |
| 5820 "#library('libraryD.dart');" | |
| 5821 "#import('libraryF.dart');" | |
| 5822 "var fooD;"; | |
| 5823 const char* kLibraryEChars = | |
| 5824 "#library('libraryE.dart');" | |
| 5825 "#import('libraryC.dart');" | |
| 5826 "#import('libraryF.dart');" | |
| 5827 "var fooE = 10; //fooC has duplicate def. so should be an error."; | |
| 5828 const char* kLibraryFChars = | |
| 5829 "#library('libraryF.dart');" | |
| 5830 "var fooC;"; | |
| 5831 Dart_Handle result; | 5779 Dart_Handle result; |
| 5832 | 5780 |
| 5833 // Create a test library and Load up a test script in it. | 5781 // Create a test library and Load up a test script in it. |
| 5834 Dart_Handle url = Dart_NewString(TestCase::url()); | 5782 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 5835 Dart_Handle source = Dart_NewString(kScriptChars); | 5783 Dart_Handle source = Dart_NewString(kScriptChars); |
| 5836 result = Dart_SetLibraryTagHandler(library_handler); | 5784 result = Dart_SetLibraryTagHandler(library_handler); |
| 5837 EXPECT_VALID(result); | 5785 EXPECT_VALID(result); |
| 5838 result = Dart_LoadScript(url, source); | 5786 result = Dart_LoadScript(url, source); |
| 5787 EXPECT_VALID(result); |
| 5839 | 5788 |
| 5840 url = Dart_NewString("libraryA.dart"); | 5789 url = Dart_NewString("library2.dart"); |
| 5841 source = Dart_NewString(kLibraryAChars); | 5790 source = Dart_NewString(kLibrary2Chars); |
| 5842 Dart_LoadLibrary(url, source); | 5791 Dart_LoadLibrary(url, source); |
| 5843 | 5792 |
| 5844 url = Dart_NewString("libraryC.dart"); | 5793 url = Dart_NewString("library1.dart"); |
| 5845 source = Dart_NewString(kLibraryCChars); | 5794 source = Dart_NewString(kLibrary1Chars); |
| 5846 Dart_LoadLibrary(url, source); | |
| 5847 | |
| 5848 url = Dart_NewString("libraryB.dart"); | |
| 5849 source = Dart_NewString(kLibraryBChars); | |
| 5850 Dart_LoadLibrary(url, source); | |
| 5851 | |
| 5852 url = Dart_NewString("libraryD.dart"); | |
| 5853 source = Dart_NewString(kLibraryDChars); | |
| 5854 Dart_LoadLibrary(url, source); | |
| 5855 | |
| 5856 url = Dart_NewString("libraryF.dart"); | |
| 5857 source = Dart_NewString(kLibraryFChars); | |
| 5858 Dart_LoadLibrary(url, source); | |
| 5859 | |
| 5860 url = Dart_NewString("libraryE.dart"); | |
| 5861 source = Dart_NewString(kLibraryEChars); | |
| 5862 Dart_LoadLibrary(url, source); | 5795 Dart_LoadLibrary(url, source); |
| 5863 | 5796 |
| 5864 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); | 5797 result = Dart_Invoke(result, Dart_NewString("main"), 0, NULL); |
| 5865 EXPECT(Dart_IsError(result)); | 5798 EXPECT_VALID(result); |
| 5866 EXPECT_STREQ("Duplicate definition : 'fooC' is defined in" | |
| 5867 " 'libraryC.dart' and 'libraryF.dart'", | |
| 5868 Dart_GetError(result)); | |
| 5869 } | 5799 } |
| 5870 | 5800 |
| 5871 | 5801 |
| 5872 TEST_CASE(ImportLibrary5) { | 5802 TEST_CASE(ImportLibrary5) { |
| 5873 const char* kScriptChars = | 5803 const char* kScriptChars = |
| 5874 "#import('lib.dart');" | 5804 "#import('lib.dart');\n" |
| 5875 "interface Y {" | 5805 "interface Y {\n" |
| 5876 " void set handler(void callback(List<int> x));" | 5806 " void set handler(void callback(List<int> x));\n" |
| 5877 "}" | 5807 "}\n" |
| 5878 "void main() {}"; | 5808 "void main() {}\n"; |
| 5879 const char* kLibraryChars = | 5809 const char* kLibraryChars = |
| 5880 "#library('lib.dart');" | 5810 "#library('lib.dart');\n" |
| 5881 "interface X {" | 5811 "interface X {\n" |
| 5882 " void set handler(void callback(List<int> x));" | 5812 " void set handler(void callback(List<int> x));\n" |
| 5883 "}"; | 5813 "}\n"; |
| 5884 Dart_Handle result; | 5814 Dart_Handle result; |
| 5885 | 5815 |
| 5886 // Create a test library and Load up a test script in it. | 5816 // Create a test library and Load up a test script in it. |
| 5887 Dart_Handle url = Dart_NewString(TestCase::url()); | 5817 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 5888 Dart_Handle source = Dart_NewString(kScriptChars); | 5818 Dart_Handle source = Dart_NewString(kScriptChars); |
| 5889 result = Dart_SetLibraryTagHandler(library_handler); | 5819 result = Dart_SetLibraryTagHandler(library_handler); |
| 5890 EXPECT_VALID(result); | 5820 EXPECT_VALID(result); |
| 5891 result = Dart_LoadScript(url, source); | 5821 result = Dart_LoadScript(url, source); |
| 5892 | 5822 |
| 5893 url = Dart_NewString("lib.dart"); | 5823 url = Dart_NewString("lib.dart"); |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6592 EXPECT(Dart_IsString(str)); | 6522 EXPECT(Dart_IsString(str)); |
| 6593 len = -1; | 6523 len = -1; |
| 6594 EXPECT_VALID(Dart_StringLength(str, &len)); | 6524 EXPECT_VALID(Dart_StringLength(str, &len)); |
| 6595 EXPECT_EQ(0, len); | 6525 EXPECT_EQ(0, len); |
| 6596 } | 6526 } |
| 6597 | 6527 |
| 6598 | 6528 |
| 6599 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 6529 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 6600 | 6530 |
| 6601 } // namespace dart | 6531 } // namespace dart |
| OLD | NEW |