Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Unified Diff: lib/src/compiler/code_generator.dart

Issue 2255993002: Support call methods on functions (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Add fix for dynamic Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/codegen/language/call_function_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler/code_generator.dart
diff --git a/lib/src/compiler/code_generator.dart b/lib/src/compiler/code_generator.dart
index d7567ad260abebecce0c34284790d804364f9cf9..08c9ec69fa886a0f748f852245ae2a8a439c4c57 100644
--- a/lib/src/compiler/code_generator.dart
+++ b/lib/src/compiler/code_generator.dart
@@ -3180,6 +3180,19 @@ class CodeGenerator extends GeneralizingAstVisitor
if (target == null || isLibraryPrefix(target)) {
return _emitFunctionCall(node);
}
+ if (node.methodName.name == 'call') {
+ var targetType = target.staticType;
+ if (targetType is FunctionType) {
+ // Call methods on function types should be handled as regular function
+ // invocations.
+ return _emitFunctionCall(node);
+ }
+ if (targetType.isDartCoreFunction || targetType.isDynamic) {
+ // TODO(vsm): Can a call method take generic type parameters?
+ return _emitDynamicInvoke(node, _visit(target),
+ _visit(node.argumentList) as List<JS.Expression>);
+ }
+ }
return _emitMethodCall(target, node);
}
@@ -3273,22 +3286,27 @@ class CodeGenerator extends GeneralizingAstVisitor
return new JS.Call(jsTarget, args);
}
+ JS.Expression _emitDynamicInvoke(
+ InvocationExpression node, JS.Expression fn, List<JS.Expression> args) {
+ var typeArgs = _emitInvokeTypeArguments(node);
+ if (typeArgs != null) {
+ return js.call('dart.dgcall(#, #, #)',
+ [fn, new JS.ArrayInitializer(typeArgs), args]);
+ } else {
+ if (_inWhitelistCode(node, isCall: true)) {
+ return new JS.Call(fn, args);
+ }
+ return js.call('dart.dcall(#, #)', [fn, args]);
+ }
+ }
+
/// Emits a function call, to a top-level function, local function, or
/// an expression.
JS.Expression _emitFunctionCall(InvocationExpression node) {
var fn = _visit(node.function);
var args = _visit(node.argumentList) as List<JS.Expression>;
if (isDynamicInvoke(node.function)) {
- var typeArgs = _emitInvokeTypeArguments(node);
- if (typeArgs != null) {
- return js.call('dart.dgcall(#, #, #)',
- [fn, new JS.ArrayInitializer(typeArgs), args]);
- } else {
- if (_inWhitelistCode(node, isCall: true)) {
- return new JS.Call(fn, args);
- }
- return js.call('dart.dcall(#, #)', [fn, args]);
- }
+ return _emitDynamicInvoke(node, fn, args);
} else {
return new JS.Call(_applyInvokeTypeArguments(fn, node), args);
}
« no previous file with comments | « no previous file | test/codegen/language/call_function_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698