| 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.interceptorData.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 = new InterceptorStubGenerator( |
| 31 new InterceptorStubGenerator(compiler, namer, backend, closedWorld); | 31 compiler.options, |
| 32 compiler.commonElements, |
| 33 backend.emitter, |
| 34 backend.nativeCodegenEnqueuer, |
| 35 backend.constants, |
| 36 namer, |
| 37 backend.nativeData, |
| 38 backend.interceptorData, |
| 39 backend.oneShotInterceptorData, |
| 40 backend.customElementsCodegenAnalysis, |
| 41 compiler.codegenWorldBuilder, |
| 42 closedWorld); |
| 32 jsAst.Expression function = | 43 jsAst.Expression function = |
| 33 stubGenerator.generateGetInterceptorMethod(classes); | 44 stubGenerator.generateGetInterceptorMethod(classes); |
| 34 | 45 |
| 35 return function; | 46 return function; |
| 36 } | 47 } |
| 37 | 48 |
| 38 /** | 49 /** |
| 39 * Emit all versions of the [:getInterceptor:] method. | 50 * Emit all versions of the [:getInterceptor:] method. |
| 40 */ | 51 */ |
| 41 jsAst.Statement buildGetInterceptorMethods() { | 52 jsAst.Statement buildGetInterceptorMethods() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 57 } | 68 } |
| 58 | 69 |
| 59 return new jsAst.Block(parts); | 70 return new jsAst.Block(parts); |
| 60 } | 71 } |
| 61 | 72 |
| 62 jsAst.Statement buildOneShotInterceptors() { | 73 jsAst.Statement buildOneShotInterceptors() { |
| 63 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 74 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
| 64 Iterable<jsAst.Name> names = | 75 Iterable<jsAst.Name> names = |
| 65 backend.oneShotInterceptorData.oneShotInterceptorNames; | 76 backend.oneShotInterceptorData.oneShotInterceptorNames; |
| 66 | 77 |
| 67 InterceptorStubGenerator stubGenerator = | 78 InterceptorStubGenerator stubGenerator = new InterceptorStubGenerator( |
| 68 new InterceptorStubGenerator(compiler, namer, backend, closedWorld); | 79 compiler.options, |
| 80 compiler.commonElements, |
| 81 backend.emitter, |
| 82 backend.nativeCodegenEnqueuer, |
| 83 backend.constants, |
| 84 namer, |
| 85 backend.nativeData, |
| 86 backend.interceptorData, |
| 87 backend.oneShotInterceptorData, |
| 88 backend.customElementsCodegenAnalysis, |
| 89 compiler.codegenWorldBuilder, |
| 90 closedWorld); |
| 69 String globalObject = namer | 91 String globalObject = namer |
| 70 .globalObjectForLibrary(backend.commonElements.interceptorsLibrary); | 92 .globalObjectForLibrary(backend.commonElements.interceptorsLibrary); |
| 71 for (jsAst.Name name in names) { | 93 for (jsAst.Name name in names) { |
| 72 jsAst.Expression function = | 94 jsAst.Expression function = |
| 73 stubGenerator.generateOneShotInterceptor(name); | 95 stubGenerator.generateOneShotInterceptor(name); |
| 74 parts.add(js.statement('${globalObject}.# = #', [name, function])); | 96 parts.add(js.statement('${globalObject}.# = #', [name, function])); |
| 75 } | 97 } |
| 76 | 98 |
| 77 return new jsAst.Block(parts); | 99 return new jsAst.Block(parts); |
| 78 } | 100 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 106 */ | 128 */ |
| 107 jsAst.Statement buildTypeToInterceptorMap(Program program) { | 129 jsAst.Statement buildTypeToInterceptorMap(Program program) { |
| 108 jsAst.Expression array = program.typeToInterceptorMap; | 130 jsAst.Expression array = program.typeToInterceptorMap; |
| 109 if (array == null) return js.comment("Empty type-to-interceptor map."); | 131 if (array == null) return js.comment("Empty type-to-interceptor map."); |
| 110 | 132 |
| 111 jsAst.Expression typeToInterceptorMap = emitter | 133 jsAst.Expression typeToInterceptorMap = emitter |
| 112 .generateEmbeddedGlobalAccess(embeddedNames.TYPE_TO_INTERCEPTOR_MAP); | 134 .generateEmbeddedGlobalAccess(embeddedNames.TYPE_TO_INTERCEPTOR_MAP); |
| 113 return js.statement('# = #', [typeToInterceptorMap, array]); | 135 return js.statement('# = #', [typeToInterceptorMap, array]); |
| 114 } | 136 } |
| 115 } | 137 } |
| OLD | NEW |