Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 1850653003: Provide ability to patch external functions in a class that has already been finalized. The follow… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code-review Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "include/dart_api.h" 7 #include "include/dart_api.h"
7 #include "include/dart_mirrors_api.h" 8 #include "include/dart_mirrors_api.h"
8 #include "include/dart_native_api.h" 9 #include "include/dart_native_api.h"
9 #include "include/dart_tools_api.h" 10 #include "include/dart_tools_api.h"
10 #include "platform/assert.h" 11 #include "platform/assert.h"
11 #include "platform/text_buffer.h" 12 #include "platform/text_buffer.h"
12 #include "platform/utils.h" 13 #include "platform/utils.h"
13 #include "vm/class_finalizer.h" 14 #include "vm/class_finalizer.h"
14 #include "vm/dart_api_impl.h" 15 #include "vm/dart_api_impl.h"
15 #include "vm/dart_api_state.h" 16 #include "vm/dart_api_state.h"
(...skipping 9830 matching lines...) Expand 10 before | Expand all | Expand 10 after
9846 9847
9847 start_called = false; 9848 start_called = false;
9848 stop_called = false; 9849 stop_called = false;
9849 EXPECT(!start_called); 9850 EXPECT(!start_called);
9850 EXPECT(!stop_called); 9851 EXPECT(!stop_called);
9851 Timeline::SetStreamEmbedderEnabled(false); 9852 Timeline::SetStreamEmbedderEnabled(false);
9852 EXPECT(!start_called); 9853 EXPECT(!start_called);
9853 EXPECT(stop_called); 9854 EXPECT(stop_called);
9854 } 9855 }
9855 9856
9857
9858 TEST_CASE(Dart_LoadLibraryPatch_1) {
9859 const char* kScriptChars1 =
9860 "class A {\n"
9861 " int foo() { return 10; }\n"
9862 " external int zoo();\n"
9863 " external static int moo();\n"
9864 "}\n"
9865 "main() { new A().foo(); }\n"
9866 "foozoo() { new A().zoo(); }\n"
9867 "foomoo() { A.moo(); }\n";
9868
9869 const char* kScriptChars2 =
9870 "patch class A {\n"
9871 " /* patch */ int zoo() { return 1; }\n"
9872 " /* patch */ static int moo() { return 1; }\n"
9873 "}\n";
9874
9875 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL);
9876 Dart_Handle result = Dart_Invoke(lib,
9877 NewString("main"),
9878 0,
9879 NULL);
9880 EXPECT_VALID(result);
9881 Dart_Handle url = NewString("test-lib-patch");
9882 Dart_Handle source = NewString(kScriptChars2);
9883 result = Dart_LibraryLoadPatch(lib, url, source);
9884 EXPECT_VALID(result);
9885 result = Dart_FinalizeLoading(false);
9886 EXPECT_VALID(result);
9887 result = Dart_Invoke(lib,
9888 NewString("foozoo"),
9889 0,
9890 NULL);
9891 EXPECT_VALID(result);
9892 result = Dart_Invoke(lib,
9893 NewString("foomoo"),
9894 0,
9895 NULL);
9896 EXPECT_VALID(result);
9897 }
9898
9899
9900 TEST_CASE(Dart_LoadLibraryPatch_Error1) {
9901 const char* kScriptChars1 =
9902 "class A {\n"
9903 " int foo() { return 10; }\n"
9904 " external int zoo();\n"
9905 "}\n"
9906 "main() { new A().foo(); }\n"
9907 "foozoo() { new A().zoo(); }\n";
9908
9909 const char* kScriptChars2 =
9910 "patch class A {\n"
9911 " /* patch */ int zoo() { return 1; }\n"
9912 " /* patch */ int fld1;\n"
9913 "}\n";
9914
9915 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL);
9916 Dart_Handle result = Dart_Invoke(lib,
9917 NewString("main"),
9918 0,
9919 NULL);
9920 EXPECT_VALID(result);
9921 Dart_Handle url = NewString("test-lib-patch");
9922 Dart_Handle source = NewString(kScriptChars2);
9923 // We don't expect to be able to patch in this case as new fields
9924 // are being added.
9925 result = Dart_LibraryLoadPatch(lib, url, source);
9926 EXPECT_VALID(result);
9927 result = Dart_FinalizeLoading(false);
9928 EXPECT_VALID(result);
9929 result = Dart_Invoke(lib,
9930 NewString("foozoo"),
9931 0,
9932 NULL);
9933 EXPECT(Dart_IsError(result));
9934 }
9935
9936
9937 TEST_CASE(Dart_LoadLibraryPatch_Error2) {
9938 const char* kScriptChars1 =
9939 "class A {\n"
9940 " int foo() { return 10; }\n"
9941 " int zoo() { return 20; }\n"
9942 "}\n"
9943 "main() { new A().foo(); }\n"
9944 "foozoo() { new A().zoo(); }\n";
9945
9946 const char* kScriptChars2 =
9947 "patch class A {\n"
9948 " /* patch */ int zoo() { return 1; }\n"
9949 "}\n";
9950
9951 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL);
9952 Dart_Handle result = Dart_Invoke(lib,
9953 NewString("main"),
9954 0,
9955 NULL);
9956 EXPECT_VALID(result);
9957 Dart_Handle url = NewString("test-lib-patch");
9958 Dart_Handle source = NewString(kScriptChars2);
9959 // We don't expect to be able to patch in this case as a non external
9960 // method is being patched.
9961 result = Dart_LibraryLoadPatch(lib, url, source);
9962 EXPECT_VALID(result);
9963 result = Dart_FinalizeLoading(false);
9964 EXPECT_VALID(result);
9965 result = Dart_Invoke(lib,
9966 NewString("foozoo"),
9967 0,
9968 NULL);
9969 EXPECT(Dart_IsError(result));
9970 OS::Print("Patched class executed\n");
9971 }
9972
9973
9974 TEST_CASE(Dart_LoadLibraryPatch_Error3) {
9975 const char* kScriptChars1 =
9976 "class A {\n"
9977 " int foo() { return 10; }\n"
9978 " external int zoo();\n"
9979 "}\n"
9980 "main() { new A().foo(); }\n"
9981 "foozoo() { new A().zoo(); }\n";
9982
9983 const char* kScriptChars2 =
9984 "patch class A {\n"
9985 " /* patch */ int zoo() { return 1; }\n"
9986 "}\n";
9987
9988 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars1, NULL);
9989 Dart_Handle result = Dart_Invoke(lib,
9990 NewString("main"),
9991 0,
9992 NULL);
9993 // We invoke the foozoo method to ensure that code for 'zoo' is generated
9994 // which throws NoSuchMethod.
9995 result = Dart_Invoke(lib,
9996 NewString("foozoo"),
9997 0,
9998 NULL);
9999 EXPECT(Dart_IsError(result));
10000 Dart_Handle url = NewString("test-lib-patch");
10001 Dart_Handle source = NewString(kScriptChars2);
10002 // We don't expect to be able to patch in this case as the function being
10003 // patched has already executed.
10004 result = Dart_LibraryLoadPatch(lib, url, source);
10005 EXPECT_VALID(result);
10006 result = Dart_FinalizeLoading(false);
10007 EXPECT_VALID(result);
10008 result = Dart_Invoke(lib,
10009 NewString("foozoo"),
10010 0,
10011 NULL);
10012 EXPECT(Dart_IsError(result));
10013 }
10014
9856 #endif // !PRODUCT 10015 #endif // !PRODUCT
9857 10016
9858 } // namespace dart 10017 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698