mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:00:09 +00:00
Fix Dart_InvokeDynamic api to handle the null receiver properly: call Object's methods (e.g., "toString", "noSuchMethod").
Review URL: https://chromereviews.googleplex.com/3525014 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@48 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
da2581daa9
commit
665b268641
|
@ -952,9 +952,9 @@ DART_EXPORT Dart_Result Dart_InvokeDynamic(Dart_Handle object,
|
||||||
HandleScope scope; // Setup a VM handle scope.
|
HandleScope scope; // Setup a VM handle scope.
|
||||||
const Object& obj = Object::Handle(Api::UnwrapHandle(object));
|
const Object& obj = Object::Handle(Api::UnwrapHandle(object));
|
||||||
if (obj.IsNull()) {
|
if (obj.IsNull()) {
|
||||||
RETURN_FAILURE("Null receiver passed in to invoke dynamic");
|
// Let the resolver figure out the correct target.
|
||||||
}
|
// E.g., (null).toString() should execute correctly.
|
||||||
if (!obj.IsInstance()) {
|
} else if (!obj.IsInstance()) {
|
||||||
RETURN_FAILURE("Invalid receiver (not instance) passed to invoke dynamic");
|
RETURN_FAILURE("Invalid receiver (not instance) passed to invoke dynamic");
|
||||||
}
|
}
|
||||||
if (function_name == NULL) {
|
if (function_name == NULL) {
|
||||||
|
@ -972,7 +972,8 @@ DART_EXPORT Dart_Result Dart_InvokeDynamic(Dart_Handle object,
|
||||||
(number_of_arguments + 1),
|
(number_of_arguments + 1),
|
||||||
0)); // Named args not yet supported in API.
|
0)); // Named args not yet supported in API.
|
||||||
if (function.IsNull()) {
|
if (function.IsNull()) {
|
||||||
OS::PrintErr("Unable to find instance function: %s\n", function_name);
|
// TODO(5415268): Invoke noSuchMethod instead of failing.
|
||||||
|
OS::PrintErr("Unable to find instance function: %s\n", name.ToCString());
|
||||||
RETURN_FAILURE("Unable to find instance function");
|
RETURN_FAILURE("Unable to find instance function");
|
||||||
}
|
}
|
||||||
Dart_Result retval;
|
Dart_Result retval;
|
||||||
|
|
|
@ -1363,6 +1363,41 @@ UNIT_TEST_CASE(InstanceOf) {
|
||||||
Dart_ShutdownIsolate();
|
Dart_ShutdownIsolate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UNIT_TEST_CASE(NullReceiver) {
|
||||||
|
Dart_CreateIsolate(NULL, NULL);
|
||||||
|
Dart_EnterScope(); // Enter a Dart API scope for the unit test.
|
||||||
|
{
|
||||||
|
Zone zone;
|
||||||
|
HandleScope hs;
|
||||||
|
|
||||||
|
Dart_Handle function_name = Dart_NewString("toString");
|
||||||
|
const int number_of_arguments = 0;
|
||||||
|
Dart_Handle null_receiver = Api::NewLocalHandle(Object::Handle());
|
||||||
|
Dart_Handle dart_arguments[0];
|
||||||
|
Dart_Result result = Dart_InvokeDynamic(null_receiver,
|
||||||
|
function_name,
|
||||||
|
number_of_arguments,
|
||||||
|
dart_arguments);
|
||||||
|
EXPECT(Dart_IsValidResult(result));
|
||||||
|
Dart_Handle retobj = Dart_GetResult(result);
|
||||||
|
EXPECT(Dart_IsString(retobj));
|
||||||
|
|
||||||
|
// Should throw a NullPointerException. Disabled due to bug 5415268.
|
||||||
|
/*
|
||||||
|
Dart_Handle function_name2 = Dart_NewString("NoNoNo");
|
||||||
|
result = Dart_InvokeDynamic(null_receiver,
|
||||||
|
function_name2,
|
||||||
|
number_of_arguments,
|
||||||
|
dart_arguments);
|
||||||
|
EXPECT(Dart_IsValidResult(result));
|
||||||
|
retobj = Dart_GetResult(result);
|
||||||
|
EXPECT(Dart_ExceptionOccurred(retobj)); */
|
||||||
|
}
|
||||||
|
Dart_ExitScope(); // Exit the Dart API scope.
|
||||||
|
Dart_ShutdownIsolate();
|
||||||
|
}
|
||||||
|
|
||||||
#endif // TARGET_ARCH_IA32.
|
#endif // TARGET_ARCH_IA32.
|
||||||
|
|
||||||
} // namespace dart
|
} // namespace dart
|
||||||
|
|
Loading…
Reference in a new issue