| 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 ClosureTask, ClosureFieldElement; | 10 import '../../closure.dart' show ClosureTask, 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 ConstructorBodyElement, | 20 ConstructorBodyElement, |
| 21 Element, | |
| 22 Elements, | 21 Elements, |
| 23 FieldElement, | 22 FieldElement, |
| 24 FunctionElement, | |
| 25 FunctionSignature, | 23 FunctionSignature, |
| 26 GetterElement, | 24 GetterElement, |
| 27 LibraryElement, | 25 LibraryElement, |
| 28 MemberElement, | 26 MemberElement, |
| 29 MethodElement, | 27 MethodElement, |
| 30 ParameterElement, | 28 ParameterElement, |
| 31 TypedefElement; | 29 TypedefElement; |
| 32 import '../../elements/entities.dart'; | 30 import '../../elements/entities.dart'; |
| 33 import '../../elements/resolution_types.dart' | 31 import '../../elements/resolution_types.dart' |
| 34 show ResolutionDartType, ResolutionFunctionType, ResolutionTypedefType; | 32 show ResolutionDartType, ResolutionFunctionType, ResolutionTypedefType; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 // a method in the case where there exist multiple JavaScript classes | 512 // a method in the case where there exist multiple JavaScript classes |
| 515 // that conflict on whether the member is a getter or a method. | 513 // that conflict on whether the member is a getter or a method. |
| 516 var interceptorClass = _classes[_commonElements.jsJavaScriptObjectClass]; | 514 var interceptorClass = _classes[_commonElements.jsJavaScriptObjectClass]; |
| 517 var stubNames = new Set<String>(); | 515 var stubNames = new Set<String>(); |
| 518 librariesMap | 516 librariesMap |
| 519 .forEach((LibraryEntity library, List<ClassEntity> classElements, _) { | 517 .forEach((LibraryEntity library, List<ClassEntity> classElements, _) { |
| 520 for (ClassEntity cls in classElements) { | 518 for (ClassEntity cls in classElements) { |
| 521 if (_nativeData.isJsInteropClass(cls)) { | 519 if (_nativeData.isJsInteropClass(cls)) { |
| 522 // TODO(johnniwinther): Handle class entities. | 520 // TODO(johnniwinther): Handle class entities. |
| 523 ClassElement e = cls; | 521 ClassElement e = cls; |
| 524 e.declaration.forEachMember((_, Element member) { | 522 e.declaration.forEachMember((_, MemberElement member) { |
| 525 var jsName = _nativeData.computeUnescapedJSInteropName(member.name); | 523 var jsName = _nativeData.computeUnescapedJSInteropName(member.name); |
| 526 if (!member.isInstanceMember) return; | 524 if (!member.isInstanceMember) return; |
| 527 if (member.isGetter || member.isField || member.isFunction) { | 525 if (member.isGetter || member.isField || member.isFunction) { |
| 528 var selectors = | 526 var selectors = |
| 529 _worldBuilder.getterInvocationsByName(member.name); | 527 _worldBuilder.getterInvocationsByName(member.name); |
| 530 if (selectors != null && !selectors.isEmpty) { | 528 if (selectors != null && !selectors.isEmpty) { |
| 531 for (var selector in selectors.keys) { | 529 for (var selector in selectors.keys) { |
| 532 var stubName = _namer.invocationName(selector); | 530 var stubName = _namer.invocationName(selector); |
| 533 if (stubNames.add(stubName.key)) { | 531 if (stubNames.add(stubName.key)) { |
| 534 interceptorClass.callStubs.add(_buildStubMethod(stubName, | 532 interceptorClass.callStubs.add(_buildStubMethod(stubName, |
| 535 js.js('function(obj) { return obj.# }', [jsName]), | 533 js.js('function(obj) { return obj.# }', [jsName]), |
| 536 element: member)); | 534 element: member)); |
| 537 } | 535 } |
| 538 } | 536 } |
| 539 } | 537 } |
| 540 } | 538 } |
| 541 | 539 |
| 542 if (member.isSetter || (member.isField && !member.isConst)) { | 540 if (member.isSetter || (member.isField && !member.isConst)) { |
| 543 var selectors = | 541 var selectors = |
| 544 _worldBuilder.setterInvocationsByName(member.name); | 542 _worldBuilder.setterInvocationsByName(member.name); |
| 545 if (selectors != null && !selectors.isEmpty) { | 543 if (selectors != null && !selectors.isEmpty) { |
| 546 var stubName = _namer.setterForElement(member); | 544 var stubName = _namer.setterForMember(member); |
| 547 if (stubNames.add(stubName.key)) { | 545 if (stubNames.add(stubName.key)) { |
| 548 interceptorClass.callStubs.add(_buildStubMethod(stubName, | 546 interceptorClass.callStubs.add(_buildStubMethod(stubName, |
| 549 js.js('function(obj, v) { return obj.# = v }', [jsName]), | 547 js.js('function(obj, v) { return obj.# = v }', [jsName]), |
| 550 element: member)); | 548 element: member)); |
| 551 } | 549 } |
| 552 } | 550 } |
| 553 } | 551 } |
| 554 | 552 |
| 555 // Generating stubs for direct calls and stubs for call-through | 553 // Generating stubs for direct calls and stubs for call-through |
| 556 // of getters that happen to be functions. | 554 // of getters that happen to be functions. |
| 557 bool isFunctionLike = false; | 555 bool isFunctionLike = false; |
| 558 ResolutionFunctionType functionType = null; | 556 ResolutionFunctionType functionType = null; |
| 559 | 557 |
| 560 if (member.isFunction) { | 558 if (member.isFunction) { |
| 561 FunctionElement fn = member; | 559 MethodElement fn = member; |
| 562 functionType = fn.type; | 560 functionType = fn.type; |
| 563 } else if (member.isGetter) { | 561 } else if (member.isGetter) { |
| 564 if (_options.trustTypeAnnotations) { | 562 if (_options.trustTypeAnnotations) { |
| 565 GetterElement getter = member; | 563 GetterElement getter = member; |
| 566 ResolutionDartType returnType = getter.type.returnType; | 564 ResolutionDartType returnType = getter.type.returnType; |
| 567 if (returnType.isFunctionType) { | 565 if (returnType.isFunctionType) { |
| 568 functionType = returnType; | 566 functionType = returnType; |
| 569 } else if (returnType.treatAsDynamic || | 567 } else if (returnType.treatAsDynamic || |
| 570 _types.isSubtype( | 568 _types.isSubtype( |
| 571 returnType, | 569 returnType, |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 }); | 1035 }); |
| 1038 } | 1036 } |
| 1039 | 1037 |
| 1040 List<Field> _buildFields( | 1038 List<Field> _buildFields( |
| 1041 {bool visitStatics: false, | 1039 {bool visitStatics: false, |
| 1042 bool isHolderInterceptedClass: false, | 1040 bool isHolderInterceptedClass: false, |
| 1043 LibraryEntity library, | 1041 LibraryEntity library, |
| 1044 ClassEntity cls}) { | 1042 ClassEntity cls}) { |
| 1045 List<Field> fields = <Field>[]; | 1043 List<Field> fields = <Field>[]; |
| 1046 | 1044 |
| 1047 void visitField(FieldElement field, js.Name name, js.Name accessorName, | 1045 void visitField(FieldEntity field, js.Name name, js.Name accessorName, |
| 1048 bool needsGetter, bool needsSetter, bool needsCheckedSetter) { | 1046 bool needsGetter, bool needsSetter, bool needsCheckedSetter) { |
| 1049 assert(field.isDeclaration, failedAt(field)); | 1047 assert(!(field is FieldElement && !field.isDeclaration), failedAt(field)); |
| 1050 | 1048 |
| 1051 int getterFlags = 0; | 1049 int getterFlags = 0; |
| 1052 if (needsGetter) { | 1050 if (needsGetter) { |
| 1053 if (visitStatics || | 1051 if (visitStatics || |
| 1054 !_interceptorData.fieldHasInterceptedGetter(field)) { | 1052 !_interceptorData.fieldHasInterceptedGetter(field)) { |
| 1055 getterFlags = 1; | 1053 getterFlags = 1; |
| 1056 } else { | 1054 } else { |
| 1057 getterFlags += 2; | 1055 getterFlags += 2; |
| 1058 // TODO(sra): 'isInterceptedClass' might not be the correct test | 1056 // TODO(sra): 'isInterceptedClass' might not be the correct test |
| 1059 // for methods forced to use the interceptor convention because | 1057 // for methods forced to use the interceptor convention because |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 Constant constant = new Constant(name, holder, constantValue); | 1180 Constant constant = new Constant(name, holder, constantValue); |
| 1183 _constants[constantValue] = constant; | 1181 _constants[constantValue] = constant; |
| 1184 } | 1182 } |
| 1185 } | 1183 } |
| 1186 | 1184 |
| 1187 Holder _registerStaticStateHolder() { | 1185 Holder _registerStaticStateHolder() { |
| 1188 return _registry.registerHolder(_namer.staticStateHolder, | 1186 return _registry.registerHolder(_namer.staticStateHolder, |
| 1189 isStaticStateHolder: true); | 1187 isStaticStateHolder: true); |
| 1190 } | 1188 } |
| 1191 } | 1189 } |
| OLD | NEW |