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 6824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6835 " external int method();\n" | 6835 " external int method();\n" |
6836 "}\n" | 6836 "}\n" |
6837 "\n" | 6837 "\n" |
6838 "external int unpatched();\n" | 6838 "external int unpatched();\n" |
6839 "external int topLevel(var value);\n" | 6839 "external int topLevel(var value);\n" |
6840 "external int topLevel2(var value);\n" | 6840 "external int topLevel2(var value);\n" |
6841 "external int get topLevelGetter;\n" | 6841 "external int get topLevelGetter;\n" |
6842 "external void set topLevelSetter(int value);\n"; | 6842 "external void set topLevelSetter(int value);\n"; |
6843 | 6843 |
6844 const char* kPatchChars = | 6844 const char* kPatchChars = |
6845 "patch class A {\n" | 6845 "@patch class A {\n" |
6846 " var _g;\n" | 6846 " var _g;\n" |
6847 " A() : fvalue = 13;\n" | 6847 " A() : fvalue = 13;\n" |
6848 " get _field => _g;\n" | 6848 " get _field => _g;\n" |
6849 " /*patch*/ void method(var value) {\n" | 6849 " @patch void method(var value) {\n" |
6850 " int closeYourEyes(var eggs) { return eggs * -1; }\n" | 6850 " int closeYourEyes(var eggs) { return eggs * -1; }\n" |
6851 " value = callFunc(closeYourEyes, value);\n" | 6851 " value = callFunc(closeYourEyes, value);\n" |
6852 " _g = value * 5;\n" | 6852 " _g = value * 5;\n" |
6853 " }\n" | 6853 " }\n" |
6854 "}\n" | 6854 "}\n" |
6855 "patch class B {\n" | 6855 "@patch class B {\n" |
6856 " B._internal(x) : val = x;\n" | 6856 " B._internal(x) : val = x;\n" |
6857 " /*patch*/ factory B.named(x) { return new B._internal(x); }\n" | 6857 " @patch factory B.named(x) { return new B._internal(x); }\n" |
6858 " /*patch*/ factory B(v) native \"const_B_factory\";\n" | 6858 " @patch factory B(v) native \"const_B_factory\";\n" |
6859 "}\n" | 6859 "}\n" |
6860 "var _topLevelValue = -1;\n" | 6860 "var _topLevelValue = -1;\n" |
6861 "patch int topLevel(var value) => value * value;\n" | 6861 "@patch int topLevel(var value) => value * value;\n" |
6862 "patch int set topLevelSetter(value) { _topLevelValue = value; }\n" | 6862 "@patch int set topLevelSetter(value) { _topLevelValue = value; }\n" |
6863 "patch int get topLevelGetter => 2 * _topLevelValue;\n" | 6863 "@patch int get topLevelGetter => 2 * _topLevelValue;\n" |
6864 // Allow top level methods named patch. | 6864 // Allow top level methods named patch. |
6865 "patch(x) => x*3;\n" | 6865 "patch(x) => x*3;\n" |
6866 ; // NOLINT | 6866 ; // NOLINT |
6867 | 6867 |
6868 const char* kPatchClassOnlyChars = | 6868 const char* kPatchClassOnlyChars = |
6869 "patch class C {\n" | 6869 "@patch class C {\n" |
6870 " /*patch*/ int method() {\n" | 6870 " @patch int method() {\n" |
6871 " return 42;\n" | 6871 " return 42;\n" |
6872 " }\n" | 6872 " }\n" |
6873 "}\n" | 6873 "}\n" |
6874 ; // NOLINT | 6874 ; // NOLINT |
6875 | 6875 |
6876 const char* kPatchNoClassChars = | 6876 const char* kPatchNoClassChars = |
6877 "patch topLevel2(x) => x * 2;\n"; | 6877 "@patch topLevel2(x) => x * 2;\n"; |
6878 | 6878 |
6879 const char* kScriptChars = | 6879 const char* kScriptChars = |
6880 "import 'theLibrary';\n" | 6880 "import 'theLibrary';\n" |
6881 "e1() => unpatched();\n" | 6881 "e1() => unpatched();\n" |
6882 "m1() => topLevel(2);\n" | 6882 "m1() => topLevel(2);\n" |
6883 "m2() {\n" | 6883 "m2() {\n" |
6884 " topLevelSetter = 20;\n" | 6884 " topLevelSetter = 20;\n" |
6885 " return topLevelGetter;\n" | 6885 " return topLevelGetter;\n" |
6886 "}\n" | 6886 "}\n" |
6887 "m3() => patch(7);\n" | 6887 "m3() => patch(7);\n" |
(...skipping 3164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10052 "class A {\n" | 10052 "class A {\n" |
10053 " int foo() { return 10; }\n" | 10053 " int foo() { return 10; }\n" |
10054 " external int zoo();\n" | 10054 " external int zoo();\n" |
10055 " external static int moo();\n" | 10055 " external static int moo();\n" |
10056 "}\n" | 10056 "}\n" |
10057 "main() { new A().foo(); }\n" | 10057 "main() { new A().foo(); }\n" |
10058 "foozoo() { new A().zoo(); }\n" | 10058 "foozoo() { new A().zoo(); }\n" |
10059 "foomoo() { A.moo(); }\n"; | 10059 "foomoo() { A.moo(); }\n"; |
10060 | 10060 |
10061 const char* kScriptChars2 = | 10061 const char* kScriptChars2 = |
10062 "patch class A {\n" | 10062 "@patch class A {\n" |
10063 " /* patch */ int zoo() { return 1; }\n" | 10063 " @patch int zoo() { return 1; }\n" |
10064 " /* patch */ static int moo() { return 1; }\n" | 10064 " @patch static int moo() { return 1; }\n" |
10065 "}\n"; | 10065 "}\n"; |
10066 | 10066 |
10067 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); | 10067 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); |
10068 Dart_Handle result = Dart_Invoke(lib, | 10068 Dart_Handle result = Dart_Invoke(lib, |
10069 NewString("main"), | 10069 NewString("main"), |
10070 0, | 10070 0, |
10071 NULL); | 10071 NULL); |
10072 EXPECT_VALID(result); | 10072 EXPECT_VALID(result); |
10073 Dart_Handle url = NewString("test-lib-patch"); | 10073 Dart_Handle url = NewString("test-lib-patch"); |
10074 Dart_Handle source = NewString(kScriptChars2); | 10074 Dart_Handle source = NewString(kScriptChars2); |
(...skipping 17 matching lines...) Expand all Loading... |
10092 TEST_CASE(Dart_LoadLibraryPatch_Error1) { | 10092 TEST_CASE(Dart_LoadLibraryPatch_Error1) { |
10093 const char* kScriptChars1 = | 10093 const char* kScriptChars1 = |
10094 "class A {\n" | 10094 "class A {\n" |
10095 " int foo() { return 10; }\n" | 10095 " int foo() { return 10; }\n" |
10096 " external int zoo();\n" | 10096 " external int zoo();\n" |
10097 "}\n" | 10097 "}\n" |
10098 "main() { new A().foo(); }\n" | 10098 "main() { new A().foo(); }\n" |
10099 "foozoo() { new A().zoo(); }\n"; | 10099 "foozoo() { new A().zoo(); }\n"; |
10100 | 10100 |
10101 const char* kScriptChars2 = | 10101 const char* kScriptChars2 = |
10102 "patch class A {\n" | 10102 "@patch class A {\n" |
10103 " /* patch */ int zoo() { return 1; }\n" | 10103 " @patch int zoo() { return 1; }\n" |
10104 " /* patch */ int fld1;\n" | 10104 " @patch int fld1;\n" |
10105 "}\n"; | 10105 "}\n"; |
10106 | 10106 |
10107 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); | 10107 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); |
10108 Dart_Handle result = Dart_Invoke(lib, | 10108 Dart_Handle result = Dart_Invoke(lib, |
10109 NewString("main"), | 10109 NewString("main"), |
10110 0, | 10110 0, |
10111 NULL); | 10111 NULL); |
10112 EXPECT_VALID(result); | 10112 EXPECT_VALID(result); |
10113 Dart_Handle url = NewString("test-lib-patch"); | 10113 Dart_Handle url = NewString("test-lib-patch"); |
10114 Dart_Handle source = NewString(kScriptChars2); | 10114 Dart_Handle source = NewString(kScriptChars2); |
(...skipping 14 matching lines...) Expand all Loading... |
10129 TEST_CASE(Dart_LoadLibraryPatch_Error2) { | 10129 TEST_CASE(Dart_LoadLibraryPatch_Error2) { |
10130 const char* kScriptChars1 = | 10130 const char* kScriptChars1 = |
10131 "class A {\n" | 10131 "class A {\n" |
10132 " int foo() { return 10; }\n" | 10132 " int foo() { return 10; }\n" |
10133 " int zoo() { return 20; }\n" | 10133 " int zoo() { return 20; }\n" |
10134 "}\n" | 10134 "}\n" |
10135 "main() { new A().foo(); }\n" | 10135 "main() { new A().foo(); }\n" |
10136 "foozoo() { new A().zoo(); }\n"; | 10136 "foozoo() { new A().zoo(); }\n"; |
10137 | 10137 |
10138 const char* kScriptChars2 = | 10138 const char* kScriptChars2 = |
10139 "patch class A {\n" | 10139 "@patch class A {\n" |
10140 " /* patch */ int zoo() { return 1; }\n" | 10140 " @patch int zoo() { return 1; }\n" |
10141 "}\n"; | 10141 "}\n"; |
10142 | 10142 |
10143 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); | 10143 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); |
10144 Dart_Handle result = Dart_Invoke(lib, | 10144 Dart_Handle result = Dart_Invoke(lib, |
10145 NewString("main"), | 10145 NewString("main"), |
10146 0, | 10146 0, |
10147 NULL); | 10147 NULL); |
10148 EXPECT_VALID(result); | 10148 EXPECT_VALID(result); |
10149 Dart_Handle url = NewString("test-lib-patch"); | 10149 Dart_Handle url = NewString("test-lib-patch"); |
10150 Dart_Handle source = NewString(kScriptChars2); | 10150 Dart_Handle source = NewString(kScriptChars2); |
(...skipping 15 matching lines...) Expand all Loading... |
10166 TEST_CASE(Dart_LoadLibraryPatch_Error3) { | 10166 TEST_CASE(Dart_LoadLibraryPatch_Error3) { |
10167 const char* kScriptChars1 = | 10167 const char* kScriptChars1 = |
10168 "class A {\n" | 10168 "class A {\n" |
10169 " int foo() { return 10; }\n" | 10169 " int foo() { return 10; }\n" |
10170 " external int zoo();\n" | 10170 " external int zoo();\n" |
10171 "}\n" | 10171 "}\n" |
10172 "main() { new A().foo(); }\n" | 10172 "main() { new A().foo(); }\n" |
10173 "foozoo() { new A().zoo(); }\n"; | 10173 "foozoo() { new A().zoo(); }\n"; |
10174 | 10174 |
10175 const char* kScriptChars2 = | 10175 const char* kScriptChars2 = |
10176 "patch class A {\n" | 10176 "@patch class A {\n" |
10177 " /* patch */ int zoo() { return 1; }\n" | 10177 " @patch int zoo() { return 1; }\n" |
10178 "}\n"; | 10178 "}\n"; |
10179 | 10179 |
10180 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); | 10180 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL); |
10181 Dart_Handle result = Dart_Invoke(lib, | 10181 Dart_Handle result = Dart_Invoke(lib, |
10182 NewString("main"), | 10182 NewString("main"), |
10183 0, | 10183 0, |
10184 NULL); | 10184 NULL); |
10185 // We invoke the foozoo method to ensure that code for 'zoo' is generated | 10185 // We invoke the foozoo method to ensure that code for 'zoo' is generated |
10186 // which throws NoSuchMethod. | 10186 // which throws NoSuchMethod. |
10187 result = Dart_Invoke(lib, | 10187 result = Dart_Invoke(lib, |
(...skipping 12 matching lines...) Expand all Loading... |
10200 result = Dart_Invoke(lib, | 10200 result = Dart_Invoke(lib, |
10201 NewString("foozoo"), | 10201 NewString("foozoo"), |
10202 0, | 10202 0, |
10203 NULL); | 10203 NULL); |
10204 EXPECT(Dart_IsError(result)); | 10204 EXPECT(Dart_IsError(result)); |
10205 } | 10205 } |
10206 | 10206 |
10207 #endif // !PRODUCT | 10207 #endif // !PRODUCT |
10208 | 10208 |
10209 } // namespace dart | 10209 } // namespace dart |
OLD | NEW |