invoker abstract method

Function invoker(
  1. String memberName
)

Returns an invoker builder for the given memberName. An invoker builder is a closure that takes an object and returns an invoker for that object. The returned invoker is a closure that invokes the memberName on the object it is specialized for. In other words, the invoker-builder returns a tear-off of memberName for any given object that implements the class this ClassMirror reflects on.

Example: var invokerBuilder = classMirror.invoker("foo"); var invoker = invokerBuilder(o); invoker(42); // Equivalent to o.foo(42).

More precisely, let c be the returned closure, let f be the simple name of the member denoted by memberName, and let o be an instance of the class reflected by this mirror. Consider the following invocation: c(o)(a1, ..., an, k1: v1, ..., km: vm) This invocation corresponds to the following non-reflective invocation: o.f(a1, ..., an, k1: v1, ..., km: vm) in a scope that has access to the private members of the class of o. If the invocation returns a result r, this method returns the result r. If the invocation causes a compilation error the effect is the same as if a non-reflective compilation error had been encountered. If the invocation throws an exception e (that it does not catch) this method throws e.

Note that this method is not available in the corresponding dart:mirrors interface. It was added here because it enables many invocations of a reflectively chosen method on different receivers using just one reflective operation, whereas the dart:mirrors interface requires a reflective operation for each new receiver (which is in practice likely to mean a reflective operation for each invocation).

Required capabilities: invoker for an instance method requires a matching InstanceInvokeCapability or InstanceInvokeMetaCapability; invoker for a static method requires a matching StaticInvokeCapability or StaticInvokeMetaCapability; and invoker for a top-level function requires a matching TopLevelInvokeCapability or TopLevelInvokeMetaCapability.

Implementation

//
// TODO(eernst) doc: revise language on private members when semantics known.
///
/// Required capabilities: [invoker] for an instance method requires a
/// matching [InstanceInvokeCapability] or [InstanceInvokeMetaCapability];
/// [invoker] for a static method requires a matching
/// [StaticInvokeCapability] or [StaticInvokeMetaCapability]; and [invoker]
/// for a top-level function requires a matching [TopLevelInvokeCapability]
/// or [TopLevelInvokeMetaCapability].
Function invoker(String memberName);