Files
sdk/runtime/lib/invocation_mirror.cc
T
fschneider@google.com dfd21c06e0 Change resolving of instance methods to check early for name mismatch.
The names of actual arguments are checked at resolving time
for a mismatch instead of deferring this check to the function
prologue (emitted as part of the CopyParameters() prologue).

For example:

class A {
  foo({a:42}) => null;
}

main() {
  var a = new A();
  a.foo(b:123);  // noSuchMethod: no named parameter named "b".
}

This enables e.g. fast noSuchMethod invocation in the case
of a named argument mismatch.

It also makes the function prologue for instance functions that
use optional parameters shorter by omitting the check for a 
name mismatch there.

R=regis@google.com

Review URL: https://codereview.chromium.org//19200002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25041 260f80e4-7a28-3924-810f-c04153c831b5
2013-07-16 09:38:13 +00:00

57 lines
2.1 KiB
C++

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/bootstrap_natives.h"
#include "vm/compiler.h"
#include "vm/dart_entry.h"
#include "vm/exceptions.h"
#include "vm/native_entry.h"
#include "vm/object_store.h"
#include "vm/resolver.h"
#include "vm/symbols.h"
namespace dart {
DEFINE_NATIVE_ENTRY(InvocationMirror_invoke, 4) {
const Instance& receiver = Instance::CheckedHandle(arguments->NativeArgAt(0));
const String& fun_name = String::CheckedHandle(arguments->NativeArgAt(1));
const Array& fun_args_desc = Array::CheckedHandle(arguments->NativeArgAt(2));
const Array& fun_arguments = Array::CheckedHandle(arguments->NativeArgAt(3));
// Allocate a fixed-length array duplicating the original function arguments
// and replace the receiver.
const int num_arguments = fun_arguments.Length();
const Array& invoke_arguments = Array::Handle(Array::New(num_arguments));
invoke_arguments.SetAt(0, receiver);
Object& arg = Object::Handle();
for (int i = 1; i < num_arguments; i++) {
arg = fun_arguments.At(i);
invoke_arguments.SetAt(i, arg);
}
// Resolve dynamic function given by name.
const ArgumentsDescriptor args_desc(fun_args_desc);
const Function& function = Function::Handle(
Resolver::ResolveDynamic(receiver,
fun_name,
args_desc));
Object& result = Object::Handle();
if (function.IsNull()) {
result = DartEntry::InvokeNoSuchMethod(receiver,
fun_name,
invoke_arguments,
fun_args_desc);
} else {
result = DartEntry::InvokeFunction(function,
invoke_arguments,
fun_args_desc);
}
if (result.IsError()) {
Exceptions::PropagateError(Error::Cast(result));
}
return result.raw();
}
} // namespace dart