objectMember method
What Object itself answers for name on this instance, or null when
name is not one of Object's members that can be asked of an instance
by name.
The answers every class inherits and a script class need not declare:
toString renders as '$this' does for a class with no override
(_diagnosticString, never re-dispatching to a script toString, so
super.toString() inside an override cannot recurse into it);
noSuchMethod raises a catchable NoSuchMethodError, which is what
super.noSuchMethod(invocation) inside an override means; hashCode and
runtimeType are the values get answers.
Implementation
Object? objectMember(String name) {
switch (name) {
case 'toString':
return NativeFunction(
(v, positionalArgs, namedArgs, typeArgs) => _diagnosticString,
arity: 0,
name: 'toString',
);
case 'noSuchMethod':
return NativeFunction(
(v, positionalArgs, namedArgs, typeArgs) {
final invocation = positionalArgs.isEmpty
? null
: positionalArgs.first;
final member = invocation is Invocation
? _symbolText(invocation.memberName)
: '?';
throw D4rtNoSuchMethodError(
"Instance of '${klass.name}' has no member named '$member'.",
);
},
arity: 1,
name: 'noSuchMethod',
);
case 'hashCode':
return hashCode;
case 'runtimeType':
return klass;
}
return null;
}