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

Unified Diff: pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart

Issue 1431523002: Fix behavior when typed JS interop getters are called as functions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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 | tests/html/js_function_getter_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart
diff --git a/pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart b/pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart
index 5f5543926f33ac58d5bc4687c708fa304cfcba9e..aab09c46bfbd2152d1d406624e52e24e56a6e9ec 100644
--- a/pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart
+++ b/pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart
@@ -30,7 +30,9 @@ import '../../constants/values.dart' show
import '../../core_types.dart' show
CoreClasses;
import '../../dart_types.dart' show
- DartType;
+ DartType,
+ FunctionType,
+ TypedefType;
import '../../elements/elements.dart' show
ClassElement,
Element,
@@ -38,6 +40,7 @@ import '../../elements/elements.dart' show
FieldElement,
FunctionElement,
FunctionSignature,
+ GetterElement,
LibraryElement,
MethodElement,
Name,
@@ -407,7 +410,39 @@ class ProgramBuilder {
}
}
+ bool isFunctionLike = false;
+ FunctionType functionType;
+
if (member.isFunction) {
+ FunctionElement fn = member;
+ functionType = fn.type;
+ } else if (member.isGetter) {
+ GetterElement getter = member;
+ DartType returnType = getter.type.returnType;
+ if (returnType.isFunctionType) {
+ functionType = returnType;
+ } else if (_compiler.types.isSubtype(returnType, backend.coreTypes.functionType)) {
Siggi Cherem (dart-lang) 2015/10/30 16:59:57 Like we chatted in person, let's do 2 small change
Siggi Cherem (dart-lang) 2015/10/30 17:00:49 Another idea here would be to ask users to annotat
Jacob 2015/10/30 19:47:17 NOOOO. 1. this means the analyzer can't do error
+ if (returnType.isTypedef) {
+ TypedefType typedef = returnType;
+ functionType = typedef.element.functionSignature.type;
+ } else {
+ // Other misc function type such as coreTypes.Function.
+ // Allow any number of arguments.
+ isFunctionLike = true;
+ }
+ }
+ } // TODO(jacobr): handle field elements.
+
+ if (isFunctionLike || functionType != null) {
+ int minArgs;
+ int maxArgs;
+ if (functionType != null) {
+ minArgs = functionType.parameterTypes.length;
+ maxArgs = minArgs + functionType.optionalParameterTypes.length;
+ } else {
+ minArgs = 0;
+ maxArgs = 1000;
Siggi Cherem (dart-lang) 2015/10/30 16:59:57 what if I want 1001!? ;-)
Jacob 2015/10/30 19:47:17 discussed offline. switched to 32767 also cleaned
+ }
var selectors =
_compiler.codegenWorld.invocationsByName(member.name);
FunctionElement fn = member;
@@ -418,9 +453,10 @@ class ProgramBuilder {
for (var selector in selectors.keys) {
// Check whether the arity matches this member.
var argumentCount = selector.argumentCount;
- if (argumentCount > fn.parameters.length) break;
- if (argumentCount < fn.parameters.length &&
- !fn.parameters[argumentCount].isOptional) break;
+ // JS interop does not support named arguments.
+ if (selector.namedArgumentCount > 0) break;
+ if (argumentCount < minArgs) break;
+ if (argumentCount > maxArgs) break;
var stubName = namer.invocationName(selector);
if (!stubNames.add(stubName.key)) break;
var candidateParameterNames =
« no previous file with comments | « no previous file | tests/html/js_function_getter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698