Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/interceptor_emitter.dart

Issue 833623003: dart2js: Merge intercepted names map. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: replace TODO with comment. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 class InterceptorEmitter extends CodeEmitterHelper { 7 class InterceptorEmitter extends CodeEmitterHelper {
8 final Set<String> interceptorInvocationNames = new Set<String>(); 8 final Set<String> interceptorInvocationNames = new Set<String>();
9 9
10 void recordMangledNameOfMemberMethod(FunctionElement member, String name) { 10 void recordMangledNameOfMemberMethod(FunctionElement member, String name) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 js('${globalObject}.# = #', [name, function]); 55 js('${globalObject}.# = #', [name, function]);
56 56
57 buffer.write(jsAst.prettyPrint(assignment, compiler)); 57 buffer.write(jsAst.prettyPrint(assignment, compiler));
58 buffer.write(N); 58 buffer.write(N);
59 } 59 }
60 } 60 }
61 61
62 /** 62 /**
63 * If [JSInvocationMirror._invokeOn] has been compiled, emit all the 63 * If [JSInvocationMirror._invokeOn] has been compiled, emit all the
64 * possible selector names that are intercepted into the 64 * possible selector names that are intercepted into the
65 * [interceptedNames] top-level variable. The implementation of 65 * [interceptedNames] embedded global. The implementation of
66 * [_invokeOn] will use it to determine whether it should call the 66 * [_invokeOn] will use it to determine whether it should call the
67 * method with an extra parameter. 67 * method with an extra parameter.
68 */ 68 */
69 void emitInterceptedNames(CodeBuffer buffer) { 69 jsAst.ObjectInitializer generateInterceptedNamesSet() {
70 // TODO(ahe): We should not generate the list of intercepted names at 70 // We could also generate the list of intercepted names at
71 // compile time, it can be generated automatically at runtime given 71 // runtime, by running through the subclasses of Interceptor
72 // subclasses of Interceptor (which can easily be identified). 72 // (which can easily be identified).
73 if (!compiler.enabledInvokeOn) return; 73 if (!compiler.enabledInvokeOn) return null;
74
75 // TODO(ahe): We should roll this into
76 // [emitStaticNonFinalFieldInitializations].
77 String name = backend.namer.getNameOfGlobalField(backend.interceptedNames);
78 74
79 int index = 0; 75 int index = 0;
80 var invocationNames = interceptorInvocationNames.toList()..sort(); 76 List<String> invocationNames = interceptorInvocationNames.toList()..sort();
81 List<jsAst.Expression> elements = invocationNames.map(js.string).toList(); 77 List<jsAst.Property> properties =
82 jsAst.ArrayInitializer array = 78 new List<jsAst.Property>(invocationNames.length);
83 new jsAst.ArrayInitializer(elements); 79 for (int i = 0; i < invocationNames.length; i++) {
84 80 String name = invocationNames[i];
85 jsAst.Expression assignment = 81 properties[i] = new jsAst.Property(js.string(name), js.number(1));
86 js('${emitter.isolateProperties}.# = #', [name, array]); 82 }
87 83 return new jsAst.ObjectInitializer(properties, isOneLiner: true);
88 buffer.write(jsAst.prettyPrint(assignment, compiler));
89 buffer.write(N);
90 } 84 }
91 85
92 /** 86 /**
93 * Emit initializer for [mapTypeToInterceptor] data structure used by 87 * Emit initializer for [mapTypeToInterceptor] data structure used by
94 * [findInterceptorForType]. See declaration of [mapTypeToInterceptor] in 88 * [findInterceptorForType]. See declaration of [mapTypeToInterceptor] in
95 * `interceptors.dart`. 89 * `interceptors.dart`.
96 */ 90 */
97 void emitMapTypeToInterceptor(CodeBuffer buffer) { 91 void emitMapTypeToInterceptor(CodeBuffer buffer) {
98 // TODO(sra): Perhaps inject a constant instead? 92 // TODO(sra): Perhaps inject a constant instead?
99 CustomElementsAnalysis analysis = backend.customElementsAnalysis; 93 CustomElementsAnalysis analysis = backend.customElementsAnalysis;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer(elements); 140 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer(elements);
147 String name = 141 String name =
148 backend.namer.getNameOfGlobalField(backend.mapTypeToInterceptor); 142 backend.namer.getNameOfGlobalField(backend.mapTypeToInterceptor);
149 jsAst.Expression assignment = 143 jsAst.Expression assignment =
150 js('${emitter.isolateProperties}.# = #', [name, array]); 144 js('${emitter.isolateProperties}.# = #', [name, array]);
151 145
152 buffer.write(jsAst.prettyPrint(assignment, compiler)); 146 buffer.write(jsAst.prettyPrint(assignment, compiler));
153 buffer.write(N); 147 buffer.write(N);
154 } 148 }
155 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698