| OLD | NEW |
| 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 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:convert' show JSON; | 8 import 'dart:convert' show JSON; |
| 9 | 9 |
| 10 import '../../closure.dart' show ClosureConversionTask, ClosureFieldElement; | 10 import '../../closure.dart' show ClosureConversionTask, ClosureFieldElement; |
| 11 import '../../common.dart'; | 11 import '../../common.dart'; |
| 12 import '../../common/names.dart' show Names, Selectors; | 12 import '../../common/names.dart' show Names, Selectors; |
| 13 import '../../constants/values.dart' | 13 import '../../constants/values.dart' |
| 14 show ConstantValue, InterceptorConstantValue; | 14 show ConstantValue, InterceptorConstantValue; |
| 15 import '../../common_elements.dart' show CommonElements, ElementEnvironment; | 15 import '../../common_elements.dart' show CommonElements, ElementEnvironment; |
| 16 import '../../deferred_load.dart' show DeferredLoadTask, OutputUnit; | 16 import '../../deferred_load.dart' show DeferredLoadTask, OutputUnit; |
| 17 import '../../elements/elements.dart' | 17 import '../../elements/elements.dart' |
| 18 show | 18 show |
| 19 ClassElement, | 19 ClassElement, |
| 20 FieldElement, | 20 FieldElement, |
| 21 FunctionSignature, | 21 FunctionSignature, |
| 22 GetterElement, |
| 22 LibraryElement, | 23 LibraryElement, |
| 23 MemberElement, | 24 MemberElement, |
| 24 MethodElement, | 25 MethodElement, |
| 25 ParameterElement; | 26 ParameterElement; |
| 26 import '../../elements/entities.dart'; | 27 import '../../elements/entities.dart'; |
| 27 import '../../elements/resolution_types.dart' show ResolutionDartType; | 28 import '../../elements/resolution_types.dart' |
| 28 import '../../elements/types.dart'; | 29 show ResolutionDartType, ResolutionFunctionType, ResolutionTypedefType; |
| 30 import '../../elements/types.dart' show DartType, DartTypes, FunctionType; |
| 29 import '../../js/js.dart' as js; | 31 import '../../js/js.dart' as js; |
| 30 import '../../js_backend/backend.dart' show SuperMemberData; | 32 import '../../js_backend/backend.dart' show SuperMemberData; |
| 31 import '../../js_backend/backend_usage.dart'; | 33 import '../../js_backend/backend_usage.dart'; |
| 32 import '../../js_backend/constant_handler_javascript.dart' | 34 import '../../js_backend/constant_handler_javascript.dart' |
| 33 show JavaScriptConstantCompiler; | 35 show JavaScriptConstantCompiler; |
| 34 import '../../js_backend/custom_elements_analysis.dart'; | 36 import '../../js_backend/custom_elements_analysis.dart'; |
| 35 import '../../js_backend/namer.dart' show Namer, StringBackedName; | 37 import '../../js_backend/namer.dart' show Namer, StringBackedName; |
| 36 import '../../js_backend/native_data.dart'; | 38 import '../../js_backend/native_data.dart'; |
| 37 import '../../js_backend/interceptor_data.dart'; | 39 import '../../js_backend/interceptor_data.dart'; |
| 38 import '../../js_backend/mirrors_data.dart'; | 40 import '../../js_backend/mirrors_data.dart'; |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 // tearing off JavaScript methods as we cannot distinguish between calling | 517 // tearing off JavaScript methods as we cannot distinguish between calling |
| 516 // a regular getter that returns a JavaScript function and tearing off | 518 // a regular getter that returns a JavaScript function and tearing off |
| 517 // a method in the case where there exist multiple JavaScript classes | 519 // a method in the case where there exist multiple JavaScript classes |
| 518 // that conflict on whether the member is a getter or a method. | 520 // that conflict on whether the member is a getter or a method. |
| 519 var interceptorClass = _classes[_commonElements.jsJavaScriptObjectClass]; | 521 var interceptorClass = _classes[_commonElements.jsJavaScriptObjectClass]; |
| 520 var stubNames = new Set<String>(); | 522 var stubNames = new Set<String>(); |
| 521 librariesMap | 523 librariesMap |
| 522 .forEach((LibraryEntity library, List<ClassEntity> classElements, _) { | 524 .forEach((LibraryEntity library, List<ClassEntity> classElements, _) { |
| 523 for (ClassEntity cls in classElements) { | 525 for (ClassEntity cls in classElements) { |
| 524 if (_nativeData.isJsInteropClass(cls)) { | 526 if (_nativeData.isJsInteropClass(cls)) { |
| 525 _elementEnvironment.forEachClassMember(cls, (_, MemberEntity member) { | 527 // TODO(redemption): Handle class entities. |
| 528 ClassElement e = cls; |
| 529 e.declaration.forEachMember((_, _member) { |
| 530 MemberElement member = _member; |
| 526 var jsName = _nativeData.computeUnescapedJSInteropName(member.name); | 531 var jsName = _nativeData.computeUnescapedJSInteropName(member.name); |
| 527 if (!member.isInstanceMember) return; | 532 if (!member.isInstanceMember) return; |
| 528 if (member.isGetter || member.isField || member.isFunction) { | 533 if (member.isGetter || member.isField || member.isFunction) { |
| 529 var selectors = | 534 var selectors = |
| 530 _worldBuilder.getterInvocationsByName(member.name); | 535 _worldBuilder.getterInvocationsByName(member.name); |
| 531 if (selectors != null && !selectors.isEmpty) { | 536 if (selectors != null && !selectors.isEmpty) { |
| 532 for (var selector in selectors.keys) { | 537 for (var selector in selectors.keys) { |
| 533 var stubName = _namer.invocationName(selector); | 538 var stubName = _namer.invocationName(selector); |
| 534 if (stubNames.add(stubName.key)) { | 539 if (stubNames.add(stubName.key)) { |
| 535 interceptorClass.callStubs.add(_buildStubMethod(stubName, | 540 interceptorClass.callStubs.add(_buildStubMethod(stubName, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 549 interceptorClass.callStubs.add(_buildStubMethod(stubName, | 554 interceptorClass.callStubs.add(_buildStubMethod(stubName, |
| 550 js.js('function(obj, v) { return obj.# = v }', [jsName]), | 555 js.js('function(obj, v) { return obj.# = v }', [jsName]), |
| 551 element: member)); | 556 element: member)); |
| 552 } | 557 } |
| 553 } | 558 } |
| 554 } | 559 } |
| 555 | 560 |
| 556 // Generating stubs for direct calls and stubs for call-through | 561 // Generating stubs for direct calls and stubs for call-through |
| 557 // of getters that happen to be functions. | 562 // of getters that happen to be functions. |
| 558 bool isFunctionLike = false; | 563 bool isFunctionLike = false; |
| 559 FunctionType functionType = null; | 564 ResolutionFunctionType functionType = null; |
| 560 | 565 |
| 561 if (member.isFunction) { | 566 if (member.isFunction) { |
| 562 MethodElement fn = member; | 567 MethodElement fn = member; |
| 563 functionType = fn.type; | 568 functionType = fn.type; |
| 564 } else if (member.isGetter) { | 569 } else if (member.isGetter) { |
| 565 if (_options.trustTypeAnnotations) { | 570 if (_options.trustTypeAnnotations) { |
| 566 DartType returnType = | 571 GetterElement getter = member; |
| 567 _elementEnvironment.getFunctionType(member).returnType; | 572 ResolutionDartType returnType = getter.type.returnType; |
| 568 if (returnType.isFunctionType) { | 573 if (returnType.isFunctionType) { |
| 569 functionType = returnType; | 574 functionType = returnType; |
| 570 } else if (returnType.treatAsDynamic || | 575 } else if (returnType.treatAsDynamic || |
| 571 _types.isSubtype( | 576 _types.isSubtype( |
| 572 returnType, | 577 returnType, |
| 573 // ignore: UNNECESSARY_CAST | 578 // ignore: UNNECESSARY_CAST |
| 574 _commonElements.functionType as DartType)) { | 579 _commonElements.functionType as DartType)) { |
| 575 if (returnType.isTypedef) { | 580 if (returnType.isTypedef) { |
| 576 TypedefType typedef = returnType; | 581 ResolutionTypedefType typedef = returnType; |
| 577 functionType = typedef.unaliased; | 582 // TODO(jacobr): can we just use typdef.unaliased instead? |
| 583 functionType = typedef.element.functionSignature.type; |
| 578 } else { | 584 } else { |
| 579 // Other misc function type such as commonElements.Function. | 585 // Other misc function type such as commonElements.Function. |
| 580 // Allow any number of arguments. | 586 // Allow any number of arguments. |
| 581 isFunctionLike = true; | 587 isFunctionLike = true; |
| 582 } | 588 } |
| 583 } | 589 } |
| 584 } else { | 590 } else { |
| 585 isFunctionLike = true; | 591 isFunctionLike = true; |
| 586 } | 592 } |
| 587 } // TODO(jacobr): handle field elements. | 593 } // TODO(jacobr): handle field elements. |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 Constant constant = new Constant(name, holder, constantValue); | 1190 Constant constant = new Constant(name, holder, constantValue); |
| 1185 _constants[constantValue] = constant; | 1191 _constants[constantValue] = constant; |
| 1186 } | 1192 } |
| 1187 } | 1193 } |
| 1188 | 1194 |
| 1189 Holder _registerStaticStateHolder() { | 1195 Holder _registerStaticStateHolder() { |
| 1190 return _registry.registerHolder(_namer.staticStateHolder, | 1196 return _registry.registerHolder(_namer.staticStateHolder, |
| 1191 isStaticStateHolder: true); | 1197 isStaticStateHolder: true); |
| 1192 } | 1198 } |
| 1193 } | 1199 } |
| OLD | NEW |