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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 14980002: Fix for issue 10395, call noSUchMethod if a method is not found when using the Dart C API. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
===================================================================
--- runtime/vm/dart_api_impl_test.cc (revision 22402)
+++ runtime/vm/dart_api_impl_test.cc (working copy)
@@ -3755,7 +3755,8 @@
// Instance method, wrong arg count.
EXPECT_ERROR(Dart_Invoke(instance, name, 2, bad_args),
- "did not find instance method 'Methods.instanceMethod'");
+ "Class 'Methods' has no instance method 'instanceMethod'"
+ " with matching arguments");
srdjan 2013/05/06 16:10:41 Please add a test with noSuchMethod to verify prop
siva 2013/05/06 16:20:25 I did add one, see below (InvokeNoSuchMethod). The
name = PrivateLibName(lib, "_instanceMethod");
EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args)));
@@ -3888,18 +3889,80 @@
EXPECT_VALID(Dart_StringToCString(result, &value));
EXPECT_STREQ("null", value);
- // Should throw a NullPointerException. Disabled due to bug 5415268.
- /*
- Dart_Handle function_name2 = NewString("NoNoNo");
- result = Dart_Invoke(null_receiver,
- function_name2,
- number_of_arguments,
- dart_arguments);
- EXPECT(Dart_IsError(result));
- EXPECT(Dart_ErrorHasException(result)); */
+ Dart_Handle function_name = NewString("NoNoNo");
+ result = Dart_Invoke(Dart_Null(),
+ function_name,
+ 0,
+ NULL);
+ EXPECT(Dart_IsError(result));
+ EXPECT(Dart_ErrorHasException(result));
}
+TEST_CASE(InvokeNoSuchMethod) {
+ const char* kScriptChars =
+ "import 'dart:_collection-dev' as _collection_dev;\n"
+ "class Expect {\n"
+ " static equals(a, b) {\n"
+ " if (a != b) {\n"
+ " throw 'not equal. expected: $a, got: $b';\n"
+ " }\n"
+ " }\n"
+ "}\n"
+ "class TestClass {\n"
+ " static int fld1 = 0;\n"
+ " void noSuchMethod(Invocation invocation) {\n"
+ " var name = _collection_dev.Symbol.getName(invocation.memberName);\n"
+ " if (name == 'fld') {\n"
+ " Expect.equals(true, invocation.isGetter);\n"
+ " Expect.equals(false, invocation.isMethod);\n"
+ " Expect.equals(false, invocation.isSetter);\n"
+ " } else if (name == 'setfld') {\n"
+ " Expect.equals(true, invocation.isSetter);\n"
+ " Expect.equals(false, invocation.isMethod);\n"
+ " Expect.equals(false, invocation.isGetter);\n"
+ " } else if (name == 'method') {\n"
+ " Expect.equals(true, invocation.isMethod);\n"
+ " Expect.equals(false, invocation.isSetter);\n"
+ " Expect.equals(false, invocation.isGetter);\n"
+ " }\n"
+ " TestClass.fld1 += 1;\n"
+ " }\n"
+ " static void testMain() {\n"
+ " return new TestClass();\n"
+ " }\n"
+ "}\n";
+ Dart_Handle result;
+ Dart_Handle instance;
+ // Create a test library and Load up a test script in it.
+ Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
+ Dart_Handle cls = Dart_GetClass(lib, NewString("TestClass"));
+ EXPECT_VALID(cls);
+
+ // Invoke a function which returns an object.
+ instance = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
+ EXPECT_VALID(instance);
+
+ // Try to get a field that does not exist, should call noSuchMethod.
+ result = Dart_GetField(instance, NewString("fld"));
+ EXPECT_VALID(result);
+
+ // Try to set a field that does not exist, should call noSuchMethod.
+ result = Dart_SetField(instance, NewString("setfld"), Dart_NewInteger(13));
+ EXPECT_VALID(result);
+
+ // Try to invoke a method that does not exist, should call noSuchMethod.
+ result = Dart_Invoke(instance, NewString("method"), 0, NULL);
+ EXPECT_VALID(result);
+
+ result = Dart_GetField(cls, NewString("fld1"));
+ EXPECT_VALID(result);
+ int64_t value = 0;
+ result = Dart_IntegerToInt64(result, &value);
+ EXPECT_EQ(3, value);
+}
+
+
TEST_CASE(Invoke_CrossLibrary) {
const char* kLibrary1Chars =
"library library1_name;\n"
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698