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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 1385973002: Add flag specifying whether patch signature mismatches can be ignored. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index 34c5cb50e931f85b5964948e688e68997014f51c..162fdf6befa54593b6742cb6a62e62b915d726ce 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -21,6 +21,7 @@ namespace dart {
DECLARE_FLAG(int, optimization_counter_threshold);
DECLARE_FLAG(bool, verify_acquired_data);
+DECLARE_FLAG(bool, ignore_patch_signature_mismatch);
TEST_CASE(ErrorHandleBasics) {
const char* kScriptChars =
@@ -6885,6 +6886,121 @@ TEST_CASE(LoadPatch) {
EXPECT_EQ(42, value);
}
+TEST_CASE(LoadPatchSignatureMismatch) {
+ // This tests the sort of APIs with intentional signature mismatches we need
+ // for typed Dart-JavaScript interop where we emulated JavaScript semantics
+ // for optional arguments.
+ const char* kLibrary1Chars =
+ "library library1_name;";
+ const char* kSourceChars =
+ "part of library1_name;\n"
+ "external int foo([int x]);\n"
+ "class Foo {\n"
+ " external static int addDefault10([int x, int y]);\n"
+ "}";
+ const char* kPatchChars =
+ "const _UNDEFINED = const Object();\n"
+ "patch foo([x=_UNDEFINED]) => identical(x, _UNDEFINED) ? 42 : x;\n"
+ "patch class Foo {\n"
+ " static addDefault10([x=_UNDEFINED, y=_UNDEFINED]) {\n"
+ " if (identical(x, _UNDEFINED)) x = 10;\n"
+ " if (identical(y, _UNDEFINED)) y = 10;\n"
+ " return x + y;\n"
+ " }\n"
+ "}";
+
+ bool old_flag_value = FLAG_ignore_patch_signature_mismatch;
+ FLAG_ignore_patch_signature_mismatch = true;
+
+ // Load up a library.
+ Dart_Handle url = NewString("library1_url");
+ Dart_Handle source = NewString(kLibrary1Chars);
+ Dart_Handle lib = Dart_LoadLibrary(url, source, 0, 0);
+ EXPECT_VALID(lib);
+ EXPECT(Dart_IsLibrary(lib));
+
+ url = NewString("source_url");
+ source = NewString(kSourceChars);
+
+ Dart_Handle result = Dart_LoadSource(lib, url, source, 0, 0);
+ EXPECT_VALID(result);
+
+ url = NewString("patch_url");
+ source = NewString(kPatchChars);
+
+ result = Dart_LibraryLoadPatch(lib, url, source);
+ EXPECT_VALID(result);
+ result = Dart_FinalizeLoading(false);
+ EXPECT_VALID(result);
+
+ // Test a top level method
+ {
+ result = Dart_Invoke(lib, NewString("foo"), 0, NULL);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsInteger(result));
+ int64_t value = 0;
+ EXPECT_VALID(Dart_IntegerToInt64(result, &value));
+ EXPECT_EQ(42, value);
+ }
+
+ {
+ Dart_Handle dart_args[1];
+ dart_args[0] = Dart_Null();
+ result = Dart_Invoke(lib, NewString("foo"), 1, dart_args);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsNull(result));
+ }
+
+ {
+ Dart_Handle dart_args[1];
+ dart_args[0] = Dart_NewInteger(100);
+ result = Dart_Invoke(lib, NewString("foo"), 1, dart_args);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsInteger(result));
+ int64_t value = 0;
+ EXPECT_VALID(Dart_IntegerToInt64(result, &value));
+ EXPECT_EQ(100, value);
+ }
+
+ // Test static method
+ Dart_Handle type = Dart_GetType(lib, NewString("Foo"), 0, NULL);
+ EXPECT_VALID(type);
+
+ {
+ result = Dart_Invoke(type, NewString("addDefault10"), 0, NULL);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsInteger(result));
+ int64_t value = 0;
+ EXPECT_VALID(Dart_IntegerToInt64(result, &value));
+ EXPECT_EQ(20, value);
+ }
+
+ {
+ Dart_Handle dart_args[1];
+ dart_args[0] = Dart_NewInteger(100);
+ result = Dart_Invoke(type, NewString("addDefault10"), 1, dart_args);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsInteger(result));
+ int64_t value = 0;
+ EXPECT_VALID(Dart_IntegerToInt64(result, &value));
+ EXPECT_EQ(110, value);
+ }
+
+ {
+ Dart_Handle dart_args[2];
+ dart_args[0] = Dart_NewInteger(100);
+ dart_args[1] = Dart_NewInteger(100);
+ result = Dart_Invoke(type, NewString("addDefault10"), 2, dart_args);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsInteger(result));
+ int64_t value = 0;
+ EXPECT_VALID(Dart_IntegerToInt64(result, &value));
+ EXPECT_EQ(200, value);
+ }
+
+ FLAG_ignore_patch_signature_mismatch = old_flag_value;
+}
+
static void PatchNativeFunction(Dart_NativeArguments args) {
Dart_EnterScope();
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698