| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.full_emitter.interceptor_emitter; | 5 library dart2js.js_emitter.full_emitter.interceptor_emitter; |
| 6 | 6 |
| 7 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 7 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
| 8 import '../../elements/elements.dart' | 8 import '../../elements/entities.dart'; |
| 9 show | |
| 10 ClassElement, | |
| 11 MethodElement; | |
| 12 import '../../js/js.dart' as jsAst; | 9 import '../../js/js.dart' as jsAst; |
| 13 import '../../js/js.dart' show js; | 10 import '../../js/js.dart' show js; |
| 14 import '../../world.dart' show ClosedWorld; | 11 import '../../world.dart' show ClosedWorld; |
| 15 import '../js_emitter.dart' hide Emitter, EmitterFactory; | 12 import '../js_emitter.dart' hide Emitter, EmitterFactory; |
| 16 import '../model.dart'; | 13 import '../model.dart'; |
| 17 import 'emitter.dart'; | 14 import 'emitter.dart'; |
| 18 | 15 |
| 19 class InterceptorEmitter extends CodeEmitterHelper { | 16 class InterceptorEmitter extends CodeEmitterHelper { |
| 20 final ClosedWorld closedWorld; | 17 final ClosedWorld closedWorld; |
| 21 final Set<jsAst.Name> interceptorInvocationNames = new Set<jsAst.Name>(); | 18 final Set<jsAst.Name> interceptorInvocationNames = new Set<jsAst.Name>(); |
| 22 | 19 |
| 23 InterceptorEmitter(this.closedWorld); | 20 InterceptorEmitter(this.closedWorld); |
| 24 | 21 |
| 25 void recordMangledNameOfMemberMethod(MethodElement member, jsAst.Name name) { | 22 void recordMangledNameOfMemberMethod(MemberEntity member, jsAst.Name name) { |
| 26 if (backend.isInterceptedMethod(member)) { | 23 if (backend.isInterceptedMethod(member)) { |
| 27 interceptorInvocationNames.add(name); | 24 interceptorInvocationNames.add(name); |
| 28 } | 25 } |
| 29 } | 26 } |
| 30 | 27 |
| 31 jsAst.Expression buildGetInterceptorMethod( | 28 jsAst.Expression buildGetInterceptorMethod( |
| 32 jsAst.Name key, Set<ClassElement> classes) { | 29 jsAst.Name key, Set<ClassEntity> classes) { |
| 33 InterceptorStubGenerator stubGenerator = | 30 InterceptorStubGenerator stubGenerator = |
| 34 new InterceptorStubGenerator(compiler, namer, backend, closedWorld); | 31 new InterceptorStubGenerator(compiler, namer, backend, closedWorld); |
| 35 jsAst.Expression function = | 32 jsAst.Expression function = |
| 36 stubGenerator.generateGetInterceptorMethod(classes); | 33 stubGenerator.generateGetInterceptorMethod(classes); |
| 37 | 34 |
| 38 return function; | 35 return function; |
| 39 } | 36 } |
| 40 | 37 |
| 41 /** | 38 /** |
| 42 * Emit all versions of the [:getInterceptor:] method. | 39 * Emit all versions of the [:getInterceptor:] method. |
| 43 */ | 40 */ |
| 44 jsAst.Statement buildGetInterceptorMethods() { | 41 jsAst.Statement buildGetInterceptorMethods() { |
| 45 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 42 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
| 46 | 43 |
| 47 parts.add(js.comment('getInterceptor methods')); | 44 parts.add(js.comment('getInterceptor methods')); |
| 48 | 45 |
| 49 Map<jsAst.Name, Set<ClassElement>> specializedGetInterceptors = | 46 Map<jsAst.Name, Set<ClassEntity>> specializedGetInterceptors = |
| 50 backend.specializedGetInterceptors; | 47 backend.specializedGetInterceptors; |
| 51 List<jsAst.Name> names = specializedGetInterceptors.keys.toList()..sort(); | 48 List<jsAst.Name> names = specializedGetInterceptors.keys.toList()..sort(); |
| 52 for (jsAst.Name name in names) { | 49 for (jsAst.Name name in names) { |
| 53 Set<ClassElement> classes = specializedGetInterceptors[name]; | 50 Set<ClassEntity> classes = specializedGetInterceptors[name]; |
| 54 parts.add(js.statement('#.# = #', [ | 51 parts.add(js.statement('#.# = #', [ |
| 55 namer.globalObjectFor(backend.helpers.interceptorsLibrary), | 52 namer.globalObjectFor(backend.helpers.interceptorsLibrary), |
| 56 name, | 53 name, |
| 57 buildGetInterceptorMethod(name, classes) | 54 buildGetInterceptorMethod(name, classes) |
| 58 ])); | 55 ])); |
| 59 } | 56 } |
| 60 | 57 |
| 61 return new jsAst.Block(parts); | 58 return new jsAst.Block(parts); |
| 62 } | 59 } |
| 63 | 60 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 */ | 105 */ |
| 109 jsAst.Statement buildTypeToInterceptorMap(Program program) { | 106 jsAst.Statement buildTypeToInterceptorMap(Program program) { |
| 110 jsAst.Expression array = program.typeToInterceptorMap; | 107 jsAst.Expression array = program.typeToInterceptorMap; |
| 111 if (array == null) return js.comment("Empty type-to-interceptor map."); | 108 if (array == null) return js.comment("Empty type-to-interceptor map."); |
| 112 | 109 |
| 113 jsAst.Expression typeToInterceptorMap = emitter | 110 jsAst.Expression typeToInterceptorMap = emitter |
| 114 .generateEmbeddedGlobalAccess(embeddedNames.TYPE_TO_INTERCEPTOR_MAP); | 111 .generateEmbeddedGlobalAccess(embeddedNames.TYPE_TO_INTERCEPTOR_MAP); |
| 115 return js.statement('# = #', [typeToInterceptorMap, array]); | 112 return js.statement('# = #', [typeToInterceptorMap, array]); |
| 116 } | 113 } |
| 117 } | 114 } |
| OLD | NEW |