| 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; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 * If [JSInvocationMirror._invokeOn] has been compiled, emit all the | 99 * If [JSInvocationMirror._invokeOn] has been compiled, emit all the |
| 100 * possible selector names that are intercepted into the | 100 * possible selector names that are intercepted into the |
| 101 * [interceptedNames] embedded global. The implementation of | 101 * [interceptedNames] embedded global. The implementation of |
| 102 * [_invokeOn] will use it to determine whether it should call the | 102 * [_invokeOn] will use it to determine whether it should call the |
| 103 * method with an extra parameter. | 103 * method with an extra parameter. |
| 104 */ | 104 */ |
| 105 jsAst.ObjectInitializer generateInterceptedNamesSet() { | 105 jsAst.ObjectInitializer generateInterceptedNamesSet() { |
| 106 // We could also generate the list of intercepted names at | 106 // We could also generate the list of intercepted names at |
| 107 // runtime, by running through the subclasses of Interceptor | 107 // runtime, by running through the subclasses of Interceptor |
| 108 // (which can easily be identified). | 108 // (which can easily be identified). |
| 109 if (!backend.backendUsage.isInvokeOnUsed) return null; | 109 if (!closedWorld.backendUsage.isInvokeOnUsed) return null; |
| 110 | 110 |
| 111 Iterable<jsAst.Name> invocationNames = interceptorInvocationNames.toList() | 111 Iterable<jsAst.Name> invocationNames = interceptorInvocationNames.toList() |
| 112 ..sort(); | 112 ..sort(); |
| 113 ; | 113 ; |
| 114 List<jsAst.Property> properties = invocationNames.map((jsAst.Name name) { | 114 List<jsAst.Property> properties = invocationNames.map((jsAst.Name name) { |
| 115 return new jsAst.Property(js.quoteName(name), js.number(1)); | 115 return new jsAst.Property(js.quoteName(name), js.number(1)); |
| 116 }).toList(); | 116 }).toList(); |
| 117 return new jsAst.ObjectInitializer(properties, isOneLiner: true); | 117 return new jsAst.ObjectInitializer(properties, isOneLiner: true); |
| 118 } | 118 } |
| 119 | 119 |
| 120 /** | 120 /** |
| 121 * Emit initializer for `typeToInterceptorMap` data structure used by | 121 * Emit initializer for `typeToInterceptorMap` data structure used by |
| 122 * `findInterceptorForType`. See declaration of `typeToInterceptor` in | 122 * `findInterceptorForType`. See declaration of `typeToInterceptor` in |
| 123 * `interceptors.dart`. | 123 * `interceptors.dart`. |
| 124 */ | 124 */ |
| 125 jsAst.Statement buildTypeToInterceptorMap(Program program) { | 125 jsAst.Statement buildTypeToInterceptorMap(Program program) { |
| 126 jsAst.Expression array = program.typeToInterceptorMap; | 126 jsAst.Expression array = program.typeToInterceptorMap; |
| 127 if (array == null) return js.comment("Empty type-to-interceptor map."); | 127 if (array == null) return js.comment("Empty type-to-interceptor map."); |
| 128 | 128 |
| 129 jsAst.Expression typeToInterceptorMap = emitter | 129 jsAst.Expression typeToInterceptorMap = emitter |
| 130 .generateEmbeddedGlobalAccess(embeddedNames.TYPE_TO_INTERCEPTOR_MAP); | 130 .generateEmbeddedGlobalAccess(embeddedNames.TYPE_TO_INTERCEPTOR_MAP); |
| 131 return js.statement('# = #', [typeToInterceptorMap, array]); | 131 return js.statement('# = #', [typeToInterceptorMap, array]); |
| 132 } | 132 } |
| 133 } | 133 } |
| OLD | NEW |