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 "include/dart_api.h" | 6 #include "include/dart_api.h" |
7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "include/dart_tools_api.h" | 9 #include "include/dart_tools_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
11 #include "platform/json.h" | 11 #include "platform/json.h" |
12 #include "platform/utils.h" | 12 #include "platform/utils.h" |
13 #include "vm/class_finalizer.h" | 13 #include "vm/class_finalizer.h" |
14 #include "vm/dart_api_impl.h" | 14 #include "vm/dart_api_impl.h" |
15 #include "vm/dart_api_state.h" | 15 #include "vm/dart_api_state.h" |
16 #include "vm/lockers.h" | 16 #include "vm/lockers.h" |
17 #include "vm/unit_test.h" | 17 #include "vm/unit_test.h" |
18 #include "vm/verifier.h" | 18 #include "vm/verifier.h" |
19 | 19 |
20 namespace dart { | 20 namespace dart { |
21 | 21 |
22 DECLARE_FLAG(int, optimization_counter_threshold); | 22 DECLARE_FLAG(int, optimization_counter_threshold); |
23 DECLARE_FLAG(bool, verify_acquired_data); | 23 DECLARE_FLAG(bool, verify_acquired_data); |
| 24 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); |
24 | 25 |
25 TEST_CASE(ErrorHandleBasics) { | 26 TEST_CASE(ErrorHandleBasics) { |
26 const char* kScriptChars = | 27 const char* kScriptChars = |
27 "void testMain() {\n" | 28 "void testMain() {\n" |
28 " throw new Exception(\"bad news\");\n" | 29 " throw new Exception(\"bad news\");\n" |
29 "}\n"; | 30 "}\n"; |
30 | 31 |
31 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 32 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
32 | 33 |
33 Dart_Handle instance = Dart_True(); | 34 Dart_Handle instance = Dart_True(); |
(...skipping 6844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6878 EXPECT_VALID(result); | 6879 EXPECT_VALID(result); |
6879 | 6880 |
6880 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); | 6881 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
6881 EXPECT_VALID(result); | 6882 EXPECT_VALID(result); |
6882 EXPECT(Dart_IsInteger(result)); | 6883 EXPECT(Dart_IsInteger(result)); |
6883 int64_t value = 0; | 6884 int64_t value = 0; |
6884 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6885 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
6885 EXPECT_EQ(42, value); | 6886 EXPECT_EQ(42, value); |
6886 } | 6887 } |
6887 | 6888 |
| 6889 TEST_CASE(LoadPatchSignatureMismatch) { |
| 6890 // This tests the sort of APIs with intentional signature mismatches we need |
| 6891 // for typed Dart-JavaScript interop where we emulated JavaScript semantics |
| 6892 // for optional arguments. |
| 6893 const char* kLibrary1Chars = |
| 6894 "library library1_name;"; |
| 6895 const char* kSourceChars = |
| 6896 "part of library1_name;\n" |
| 6897 "external int foo([int x]);\n" |
| 6898 "class Foo {\n" |
| 6899 " external static int addDefault10([int x, int y]);\n" |
| 6900 "}"; |
| 6901 const char* kPatchChars = |
| 6902 "const _UNDEFINED = const Object();\n" |
| 6903 "patch foo([x=_UNDEFINED]) => identical(x, _UNDEFINED) ? 42 : x;\n" |
| 6904 "patch class Foo {\n" |
| 6905 " static addDefault10([x=_UNDEFINED, y=_UNDEFINED]) {\n" |
| 6906 " if (identical(x, _UNDEFINED)) x = 10;\n" |
| 6907 " if (identical(y, _UNDEFINED)) y = 10;\n" |
| 6908 " return x + y;\n" |
| 6909 " }\n" |
| 6910 "}"; |
| 6911 |
| 6912 bool old_flag_value = FLAG_ignore_patch_signature_mismatch; |
| 6913 FLAG_ignore_patch_signature_mismatch = true; |
| 6914 |
| 6915 // Load up a library. |
| 6916 Dart_Handle url = NewString("library1_url"); |
| 6917 Dart_Handle source = NewString(kLibrary1Chars); |
| 6918 Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0); |
| 6919 EXPECT_VALID(lib); |
| 6920 EXPECT(Dart_IsLibrary(lib)); |
| 6921 |
| 6922 url = NewString("source_url"); |
| 6923 source = NewString(kSourceChars); |
| 6924 |
| 6925 Dart_Handle result = Dart_LoadSource(lib, url, source, 0, 0); |
| 6926 EXPECT_VALID(result); |
| 6927 |
| 6928 url = NewString("patch_url"); |
| 6929 source = NewString(kPatchChars); |
| 6930 |
| 6931 result = Dart_LibraryLoadPatch(lib, url, source); |
| 6932 EXPECT_VALID(result); |
| 6933 result = Dart_FinalizeLoading(false); |
| 6934 EXPECT_VALID(result); |
| 6935 |
| 6936 // Test a top level method |
| 6937 { |
| 6938 result = Dart_Invoke(lib, NewString("foo"), 0, NULL); |
| 6939 EXPECT_VALID(result); |
| 6940 EXPECT(Dart_IsInteger(result)); |
| 6941 int64_t value = 0; |
| 6942 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 6943 EXPECT_EQ(42, value); |
| 6944 } |
| 6945 |
| 6946 { |
| 6947 Dart_Handle dart_args[1]; |
| 6948 dart_args[0] = Dart_Null(); |
| 6949 result = Dart_Invoke(lib, NewString("foo"), 1, dart_args); |
| 6950 EXPECT_VALID(result); |
| 6951 EXPECT(Dart_IsNull(result)); |
| 6952 } |
| 6953 |
| 6954 { |
| 6955 Dart_Handle dart_args[1]; |
| 6956 dart_args[0] = Dart_NewInteger(100); |
| 6957 result = Dart_Invoke(lib, NewString("foo"), 1, dart_args); |
| 6958 EXPECT_VALID(result); |
| 6959 EXPECT(Dart_IsInteger(result)); |
| 6960 int64_t value = 0; |
| 6961 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 6962 EXPECT_EQ(100, value); |
| 6963 } |
| 6964 |
| 6965 // Test static method |
| 6966 Dart_Handle type = Dart_GetType(lib, NewString("Foo"), 0, NULL); |
| 6967 EXPECT_VALID(type); |
| 6968 |
| 6969 { |
| 6970 result = Dart_Invoke(type, NewString("addDefault10"), 0, NULL); |
| 6971 EXPECT_VALID(result); |
| 6972 EXPECT(Dart_IsInteger(result)); |
| 6973 int64_t value = 0; |
| 6974 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 6975 EXPECT_EQ(20, value); |
| 6976 } |
| 6977 |
| 6978 { |
| 6979 Dart_Handle dart_args[1]; |
| 6980 dart_args[0] = Dart_NewInteger(100); |
| 6981 result = Dart_Invoke(type, NewString("addDefault10"), 1, dart_args); |
| 6982 EXPECT_VALID(result); |
| 6983 EXPECT(Dart_IsInteger(result)); |
| 6984 int64_t value = 0; |
| 6985 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 6986 EXPECT_EQ(110, value); |
| 6987 } |
| 6988 |
| 6989 { |
| 6990 Dart_Handle dart_args[2]; |
| 6991 dart_args[0] = Dart_NewInteger(100); |
| 6992 dart_args[1] = Dart_NewInteger(100); |
| 6993 result = Dart_Invoke(type, NewString("addDefault10"), 2, dart_args); |
| 6994 EXPECT_VALID(result); |
| 6995 EXPECT(Dart_IsInteger(result)); |
| 6996 int64_t value = 0; |
| 6997 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 6998 EXPECT_EQ(200, value); |
| 6999 } |
| 7000 |
| 7001 FLAG_ignore_patch_signature_mismatch = old_flag_value; |
| 7002 } |
| 7003 |
6888 | 7004 |
6889 static void PatchNativeFunction(Dart_NativeArguments args) { | 7005 static void PatchNativeFunction(Dart_NativeArguments args) { |
6890 Dart_EnterScope(); | 7006 Dart_EnterScope(); |
6891 Dart_SetReturnValue(args, Dart_Null()); | 7007 Dart_SetReturnValue(args, Dart_Null()); |
6892 Dart_ExitScope(); | 7008 Dart_ExitScope(); |
6893 } | 7009 } |
6894 | 7010 |
6895 | 7011 |
6896 static Dart_NativeFunction PatchNativeResolver(Dart_Handle name, | 7012 static Dart_NativeFunction PatchNativeResolver(Dart_Handle name, |
6897 int arg_count, | 7013 int arg_count, |
(...skipping 2764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9662 | 9778 |
9663 // Heartbeat test for new events. | 9779 // Heartbeat test for new events. |
9664 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | 9780 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
9665 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9781 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
9666 | 9782 |
9667 // Free buffer allocated by AppendStreamConsumer | 9783 // Free buffer allocated by AppendStreamConsumer |
9668 free(data.buffer); | 9784 free(data.buffer); |
9669 } | 9785 } |
9670 | 9786 |
9671 } // namespace dart | 9787 } // namespace dart |
OLD | NEW |