| 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/entities.dart'; | 8 import '../../elements/entities.dart'; |
| 9 import '../../js/js.dart' as jsAst; | 9 import '../../js/js.dart' as jsAst; |
| 10 import '../../js/js.dart' show js; | 10 import '../../js/js.dart' show js; |
| 11 import '../../world.dart' show ClosedWorld; | 11 import '../../world.dart' show ClosedWorld; |
| 12 import '../js_emitter.dart' hide Emitter, EmitterFactory; | 12 import '../js_emitter.dart' hide Emitter, EmitterFactory; |
| 13 import '../model.dart'; | 13 import '../model.dart'; |
| 14 import 'emitter.dart'; | 14 import 'emitter.dart'; |
| 15 | 15 |
| 16 class InterceptorEmitter extends CodeEmitterHelper { | 16 class InterceptorEmitter extends CodeEmitterHelper { |
| 17 final ClosedWorld closedWorld; | 17 final ClosedWorld closedWorld; |
| 18 final Set<jsAst.Name> interceptorInvocationNames = new Set<jsAst.Name>(); | 18 final Set<jsAst.Name> interceptorInvocationNames = new Set<jsAst.Name>(); |
| 19 | 19 |
| 20 InterceptorEmitter(this.closedWorld); | 20 InterceptorEmitter(this.closedWorld); |
| 21 | 21 |
| 22 void recordMangledNameOfMemberMethod(MemberEntity member, jsAst.Name name) { | 22 void recordMangledNameOfMemberMethod(MemberEntity member, jsAst.Name name) { |
| 23 if (backend.isInterceptedMethod(member)) { | 23 if (backend.interceptorData.isInterceptedMethod(member)) { |
| 24 interceptorInvocationNames.add(name); | 24 interceptorInvocationNames.add(name); |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 | 27 |
| 28 jsAst.Expression buildGetInterceptorMethod( | 28 jsAst.Expression buildGetInterceptorMethod( |
| 29 jsAst.Name key, Set<ClassEntity> classes) { | 29 jsAst.Name key, Set<ClassEntity> classes) { |
| 30 InterceptorStubGenerator stubGenerator = | 30 InterceptorStubGenerator stubGenerator = |
| 31 new InterceptorStubGenerator(compiler, namer, backend, closedWorld); | 31 new InterceptorStubGenerator(compiler, namer, backend, closedWorld); |
| 32 jsAst.Expression function = | 32 jsAst.Expression function = |
| 33 stubGenerator.generateGetInterceptorMethod(classes); | 33 stubGenerator.generateGetInterceptorMethod(classes); |
| 34 | 34 |
| 35 return function; | 35 return function; |
| 36 } | 36 } |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * Emit all versions of the [:getInterceptor:] method. | 39 * Emit all versions of the [:getInterceptor:] method. |
| 40 */ | 40 */ |
| 41 jsAst.Statement buildGetInterceptorMethods() { | 41 jsAst.Statement buildGetInterceptorMethods() { |
| 42 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 42 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
| 43 | 43 |
| 44 parts.add(js.comment('getInterceptor methods')); | 44 parts.add(js.comment('getInterceptor methods')); |
| 45 | 45 |
| 46 Map<jsAst.Name, Set<ClassEntity>> specializedGetInterceptors = | 46 Map<jsAst.Name, Set<ClassEntity>> specializedGetInterceptors = |
| 47 backend.specializedGetInterceptors; | 47 backend.interceptorData.specializedGetInterceptors; |
| 48 List<jsAst.Name> names = specializedGetInterceptors.keys.toList()..sort(); | 48 List<jsAst.Name> names = specializedGetInterceptors.keys.toList()..sort(); |
| 49 for (jsAst.Name name in names) { | 49 for (jsAst.Name name in names) { |
| 50 Set<ClassEntity> classes = specializedGetInterceptors[name]; | 50 Set<ClassEntity> classes = specializedGetInterceptors[name]; |
| 51 parts.add(js.statement('#.# = #', [ | 51 parts.add(js.statement('#.# = #', [ |
| 52 namer.globalObjectForLibrary(backend.helpers.interceptorsLibrary), | 52 namer.globalObjectForLibrary(backend.helpers.interceptorsLibrary), |
| 53 name, | 53 name, |
| 54 buildGetInterceptorMethod(name, classes) | 54 buildGetInterceptorMethod(name, classes) |
| 55 ])); | 55 ])); |
| 56 } | 56 } |
| 57 | 57 |
| 58 return new jsAst.Block(parts); | 58 return new jsAst.Block(parts); |
| 59 } | 59 } |
| 60 | 60 |
| 61 jsAst.Statement buildOneShotInterceptors() { | 61 jsAst.Statement buildOneShotInterceptors() { |
| 62 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 62 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
| 63 Iterable<jsAst.Name> names = backend.oneShotInterceptors.keys.toList() | 63 Iterable<jsAst.Name> names = |
| 64 ..sort(); | 64 backend.interceptorData.oneShotInterceptors.keys.toList()..sort(); |
| 65 | 65 |
| 66 InterceptorStubGenerator stubGenerator = | 66 InterceptorStubGenerator stubGenerator = |
| 67 new InterceptorStubGenerator(compiler, namer, backend, closedWorld); | 67 new InterceptorStubGenerator(compiler, namer, backend, closedWorld); |
| 68 String globalObject = | 68 String globalObject = |
| 69 namer.globalObjectForLibrary(backend.helpers.interceptorsLibrary); | 69 namer.globalObjectForLibrary(backend.helpers.interceptorsLibrary); |
| 70 for (jsAst.Name name in names) { | 70 for (jsAst.Name name in names) { |
| 71 jsAst.Expression function = | 71 jsAst.Expression function = |
| 72 stubGenerator.generateOneShotInterceptor(name); | 72 stubGenerator.generateOneShotInterceptor(name); |
| 73 parts.add(js.statement('${globalObject}.# = #', [name, function])); | 73 parts.add(js.statement('${globalObject}.# = #', [name, function])); |
| 74 } | 74 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 105 */ | 105 */ |
| 106 jsAst.Statement buildTypeToInterceptorMap(Program program) { | 106 jsAst.Statement buildTypeToInterceptorMap(Program program) { |
| 107 jsAst.Expression array = program.typeToInterceptorMap; | 107 jsAst.Expression array = program.typeToInterceptorMap; |
| 108 if (array == null) return js.comment("Empty type-to-interceptor map."); | 108 if (array == null) return js.comment("Empty type-to-interceptor map."); |
| 109 | 109 |
| 110 jsAst.Expression typeToInterceptorMap = emitter | 110 jsAst.Expression typeToInterceptorMap = emitter |
| 111 .generateEmbeddedGlobalAccess(embeddedNames.TYPE_TO_INTERCEPTOR_MAP); | 111 .generateEmbeddedGlobalAccess(embeddedNames.TYPE_TO_INTERCEPTOR_MAP); |
| 112 return js.statement('# = #', [typeToInterceptorMap, array]); | 112 return js.statement('# = #', [typeToInterceptorMap, array]); |
| 113 } | 113 } |
| 114 } | 114 } |
| OLD | NEW |