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

Side by Side 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, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | tests/html/js_function_getter_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart2js.js_emitter.program_builder; 5 library dart2js.js_emitter.program_builder;
6 6
7 import '../js_emitter.dart' show 7 import '../js_emitter.dart' show
8 ClassStubGenerator, 8 ClassStubGenerator,
9 CodeEmitterTask, 9 CodeEmitterTask,
10 computeMixinClass, 10 computeMixinClass,
(...skipping 12 matching lines...) Expand all
23 Names, 23 Names,
24 Selectors; 24 Selectors;
25 import '../../compiler.dart' show 25 import '../../compiler.dart' show
26 Compiler; 26 Compiler;
27 import '../../constants/values.dart' show 27 import '../../constants/values.dart' show
28 ConstantValue, 28 ConstantValue,
29 InterceptorConstantValue; 29 InterceptorConstantValue;
30 import '../../core_types.dart' show 30 import '../../core_types.dart' show
31 CoreClasses; 31 CoreClasses;
32 import '../../dart_types.dart' show 32 import '../../dart_types.dart' show
33 DartType; 33 DartType,
34 FunctionType,
35 TypedefType;
34 import '../../elements/elements.dart' show 36 import '../../elements/elements.dart' show
35 ClassElement, 37 ClassElement,
36 Element, 38 Element,
37 Elements, 39 Elements,
38 FieldElement, 40 FieldElement,
39 FunctionElement, 41 FunctionElement,
40 FunctionSignature, 42 FunctionSignature,
43 GetterElement,
41 LibraryElement, 44 LibraryElement,
42 MethodElement, 45 MethodElement,
43 Name, 46 Name,
44 ParameterElement, 47 ParameterElement,
45 TypedefElement, 48 TypedefElement,
46 VariableElement; 49 VariableElement;
47 import '../../js/js.dart' as js; 50 import '../../js/js.dart' as js;
48 import '../../js_backend/backend_helpers.dart' show 51 import '../../js_backend/backend_helpers.dart' show
49 BackendHelpers; 52 BackendHelpers;
50 import '../../js_backend/js_backend.dart' show 53 import '../../js_backend/js_backend.dart' show
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 if (stubNames.add(stubName.key)) { 403 if (stubNames.add(stubName.key)) {
401 interceptorClass.callStubs.add(_buildStubMethod( 404 interceptorClass.callStubs.add(_buildStubMethod(
402 stubName, 405 stubName,
403 js.js('function(obj, v) { return obj.# = v }', 406 js.js('function(obj, v) { return obj.# = v }',
404 [member.name]), 407 [member.name]),
405 element: member)); 408 element: member));
406 } 409 }
407 } 410 }
408 } 411 }
409 412
413 bool isFunctionLike = false;
414 FunctionType functionType;
415
410 if (member.isFunction) { 416 if (member.isFunction) {
417 FunctionElement fn = member;
418 functionType = fn.type;
419 } else if (member.isGetter) {
420 GetterElement getter = member;
421 DartType returnType = getter.type.returnType;
422 if (returnType.isFunctionType) {
423 functionType = returnType;
424 } 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
425 if (returnType.isTypedef) {
426 TypedefType typedef = returnType;
427 functionType = typedef.element.functionSignature.type;
428 } else {
429 // Other misc function type such as coreTypes.Function.
430 // Allow any number of arguments.
431 isFunctionLike = true;
432 }
433 }
434 } // TODO(jacobr): handle field elements.
435
436 if (isFunctionLike || functionType != null) {
437 int minArgs;
438 int maxArgs;
439 if (functionType != null) {
440 minArgs = functionType.parameterTypes.length;
441 maxArgs = minArgs + functionType.optionalParameterTypes.length;
442 } else {
443 minArgs = 0;
444 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
445 }
411 var selectors = 446 var selectors =
412 _compiler.codegenWorld.invocationsByName(member.name); 447 _compiler.codegenWorld.invocationsByName(member.name);
413 FunctionElement fn = member; 448 FunctionElement fn = member;
414 // Named arguments are not yet supported. In the future we 449 // Named arguments are not yet supported. In the future we
415 // may want to map named arguments to an object literal containing 450 // may want to map named arguments to an object literal containing
416 // all named arguments. 451 // all named arguments.
417 if (selectors != null && !selectors.isEmpty) { 452 if (selectors != null && !selectors.isEmpty) {
418 for (var selector in selectors.keys) { 453 for (var selector in selectors.keys) {
419 // Check whether the arity matches this member. 454 // Check whether the arity matches this member.
420 var argumentCount = selector.argumentCount; 455 var argumentCount = selector.argumentCount;
421 if (argumentCount > fn.parameters.length) break; 456 // JS interop does not support named arguments.
422 if (argumentCount < fn.parameters.length && 457 if (selector.namedArgumentCount > 0) break;
423 !fn.parameters[argumentCount].isOptional) break; 458 if (argumentCount < minArgs) break;
459 if (argumentCount > maxArgs) break;
424 var stubName = namer.invocationName(selector); 460 var stubName = namer.invocationName(selector);
425 if (!stubNames.add(stubName.key)) break; 461 if (!stubNames.add(stubName.key)) break;
426 var candidateParameterNames = 462 var candidateParameterNames =
427 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMOPQRSTUVWXYZ'; 463 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMOPQRSTUVWXYZ';
428 var parameters = new List<String>.generate(argumentCount, 464 var parameters = new List<String>.generate(argumentCount,
429 (i) => candidateParameterNames[i]); 465 (i) => candidateParameterNames[i]);
430 466
431 interceptorClass.callStubs.add(_buildStubMethod( 467 interceptorClass.callStubs.add(_buildStubMethod(
432 stubName, 468 stubName,
433 js.js('function(receiver, #) { return receiver.#(#) }', 469 js.js('function(receiver, #) { return receiver.#(#) }',
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 Constant constant = new Constant(name, holder, constantValue); 1000 Constant constant = new Constant(name, holder, constantValue);
965 _constants[constantValue] = constant; 1001 _constants[constantValue] = constant;
966 } 1002 }
967 } 1003 }
968 1004
969 Holder _registerStaticStateHolder() { 1005 Holder _registerStaticStateHolder() {
970 return _registry.registerHolder( 1006 return _registry.registerHolder(
971 namer.staticStateHolder, isStaticStateHolder: true); 1007 namer.staticStateHolder, isStaticStateHolder: true);
972 } 1008 }
973 } 1009 }
OLDNEW
« 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