mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 13:35:05 +00:00
Fixes #27960
For "m.call(..)", the function is "m". R=jmesserly@google.com Review URL: https://codereview.chromium.org/2539033004 .
This commit is contained in:
parent
e5a16b1ca5
commit
ec81359fc0
|
@ -1315,7 +1315,7 @@ class CodeGenerator extends GeneralizingAstVisitor
|
|||
jsMethods.add(new JS.Method(
|
||||
_propertyName('constructor'),
|
||||
js.call('function(...args) { return this.new.apply(this, args); }')
|
||||
as JS.Fun));
|
||||
as JS.Fun));
|
||||
} else if (ctors.isEmpty) {
|
||||
jsMethods.add(_emitImplicitConstructor(node, fields, virtualFields));
|
||||
}
|
||||
|
@ -3396,7 +3396,7 @@ class CodeGenerator extends GeneralizingAstVisitor
|
|||
if (targetType is FunctionType) {
|
||||
// Call methods on function types should be handled as regular function
|
||||
// invocations.
|
||||
return _emitFunctionCall(node);
|
||||
return _emitFunctionCall(node, node.target);
|
||||
}
|
||||
if (targetType.isDartCoreFunction || targetType.isDynamic) {
|
||||
// TODO(vsm): Can a call method take generic type parameters?
|
||||
|
@ -3543,10 +3543,14 @@ class CodeGenerator extends GeneralizingAstVisitor
|
|||
|
||||
/// Emits a function call, to a top-level function, local function, or
|
||||
/// an expression.
|
||||
JS.Expression _emitFunctionCall(InvocationExpression node) {
|
||||
var fn = _visit(node.function);
|
||||
JS.Expression _emitFunctionCall(InvocationExpression node,
|
||||
[Expression function]) {
|
||||
if (function == null) {
|
||||
function = node.function;
|
||||
}
|
||||
var fn = _visit(function);
|
||||
var args = _visit(node.argumentList) as List<JS.Expression>;
|
||||
if (isDynamicInvoke(node.function)) {
|
||||
if (isDynamicInvoke(function)) {
|
||||
return _emitDynamicInvoke(node, fn, args);
|
||||
} else {
|
||||
return new JS.Call(_applyInvokeTypeArguments(fn, node), args);
|
||||
|
@ -3968,7 +3972,7 @@ class CodeGenerator extends GeneralizingAstVisitor
|
|||
new JS.Method(
|
||||
access,
|
||||
js.call('function() { return #; }', _visitInitializer(node))
|
||||
as JS.Fun,
|
||||
as JS.Fun,
|
||||
isGetter: true),
|
||||
node,
|
||||
_findAccessor(element, getter: true)));
|
||||
|
@ -4528,7 +4532,7 @@ class CodeGenerator extends GeneralizingAstVisitor
|
|||
}
|
||||
result = astFactory.prefixedIdentifier(
|
||||
_bindValue(scope, 'o', ident.prefix, context: context)
|
||||
as SimpleIdentifier,
|
||||
as SimpleIdentifier,
|
||||
ident.period,
|
||||
ident.identifier);
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
typedef Object Func(Object x);
|
||||
|
||||
class Bar {
|
||||
int x = 42;
|
||||
|
||||
Object call(Object x) {
|
||||
return 'Bar $x';
|
||||
}
|
||||
}
|
||||
|
||||
Object baz(Object x) => x;
|
||||
|
||||
var map = <String, Func>{
|
||||
'baz': baz,
|
||||
'bar': new Bar()
|
||||
};
|
||||
|
||||
Object test(String str, Object arg) {
|
||||
return map[str].call(arg);
|
||||
}
|
||||
|
||||
void main() {
|
||||
Expect.equals(42, test('baz', 42));
|
||||
Expect.equals('Bar 42', test('bar', 42));
|
||||
}
|
Loading…
Reference in a new issue