| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 * If [JSInvocationMirror._invokeOn] has been compiled, emit all the | 80 * If [JSInvocationMirror._invokeOn] has been compiled, emit all the |
| 81 * possible selector names that are intercepted into the | 81 * possible selector names that are intercepted into the |
| 82 * [interceptedNames] embedded global. The implementation of | 82 * [interceptedNames] embedded global. The implementation of |
| 83 * [_invokeOn] will use it to determine whether it should call the | 83 * [_invokeOn] will use it to determine whether it should call the |
| 84 * method with an extra parameter. | 84 * method with an extra parameter. |
| 85 */ | 85 */ |
| 86 jsAst.ObjectInitializer generateInterceptedNamesSet() { | 86 jsAst.ObjectInitializer generateInterceptedNamesSet() { |
| 87 // We could also generate the list of intercepted names at | 87 // We could also generate the list of intercepted names at |
| 88 // runtime, by running through the subclasses of Interceptor | 88 // runtime, by running through the subclasses of Interceptor |
| 89 // (which can easily be identified). | 89 // (which can easily be identified). |
| 90 if (!backend.hasInvokeOnSupport) return null; | 90 if (!backend.backendUsage.isInvokeOnUsed) return null; |
| 91 | 91 |
| 92 Iterable<jsAst.Name> invocationNames = interceptorInvocationNames.toList() | 92 Iterable<jsAst.Name> invocationNames = interceptorInvocationNames.toList() |
| 93 ..sort(); | 93 ..sort(); |
| 94 ; | 94 ; |
| 95 List<jsAst.Property> properties = invocationNames.map((jsAst.Name name) { | 95 List<jsAst.Property> properties = invocationNames.map((jsAst.Name name) { |
| 96 return new jsAst.Property(js.quoteName(name), js.number(1)); | 96 return new jsAst.Property(js.quoteName(name), js.number(1)); |
| 97 }).toList(); | 97 }).toList(); |
| 98 return new jsAst.ObjectInitializer(properties, isOneLiner: true); | 98 return new jsAst.ObjectInitializer(properties, isOneLiner: true); |
| 99 } | 99 } |
| 100 | 100 |
| 101 /** | 101 /** |
| 102 * Emit initializer for `typeToInterceptorMap` data structure used by | 102 * Emit initializer for `typeToInterceptorMap` data structure used by |
| 103 * `findInterceptorForType`. See declaration of `typeToInterceptor` in | 103 * `findInterceptorForType`. See declaration of `typeToInterceptor` in |
| 104 * `interceptors.dart`. | 104 * `interceptors.dart`. |
| 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 |