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 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 handler.getConstantsForEmission(emitter.compareConstants); | 105 handler.getConstantsForEmission(emitter.compareConstants); |
106 for (ConstantValue constant in constants) { | 106 for (ConstantValue constant in constants) { |
107 if (constant is TypeConstantValue) { | 107 if (constant is TypeConstantValue) { |
108 TypeConstantValue typeConstant = constant; | 108 TypeConstantValue typeConstant = constant; |
109 Element element = typeConstant.representedType.element; | 109 Element element = typeConstant.representedType.element; |
110 if (element is ClassElement) { | 110 if (element is ClassElement) { |
111 ClassElement classElement = element; | 111 ClassElement classElement = element; |
112 if (!analysis.needsClass(classElement)) continue; | 112 if (!analysis.needsClass(classElement)) continue; |
113 | 113 |
114 elements.add(emitter.constantReference(constant)); | 114 elements.add(emitter.constantReference(constant)); |
115 elements.add(backend.emitter.classAccess(classElement)); | 115 elements.add(backend.emitter.interceptorClassAccess(classElement)); |
116 | 116 |
117 // Create JavaScript Object map for by-name lookup of generative | 117 // Create JavaScript Object map for by-name lookup of generative |
118 // constructors. For example, the class A has three generative | 118 // constructors. For example, the class A has three generative |
119 // constructors | 119 // constructors |
120 // | 120 // |
121 // class A { | 121 // class A { |
122 // A() {} | 122 // A() {} |
123 // A.foo() {} | 123 // A.foo() {} |
124 // A.bar() {} | 124 // A.bar() {} |
125 // } | 125 // } |
126 // | 126 // |
127 // Which are described by the map | 127 // Which are described by the map |
128 // | 128 // |
129 // {"": A.A$, "foo": A.A$foo, "bar": A.A$bar} | 129 // {"": A.A$, "foo": A.A$foo, "bar": A.A$bar} |
130 // | 130 // |
131 // We expect most of the time the map will be a singleton. | 131 // We expect most of the time the map will be a singleton. |
132 var properties = []; | 132 var properties = []; |
133 for (Element member in analysis.constructors(classElement)) { | 133 for (Element member in analysis.constructors(classElement)) { |
134 properties.add( | 134 properties.add( |
135 new jsAst.Property( | 135 new jsAst.Property( |
136 js.string(member.name), | 136 js.string(member.name), |
137 backend.emitter.classAccess(member))); | 137 backend.emitter.staticFunctionAccess(member))); |
138 } | 138 } |
139 | 139 |
140 var map = new jsAst.ObjectInitializer(properties); | 140 var map = new jsAst.ObjectInitializer(properties); |
141 elements.add(map); | 141 elements.add(map); |
142 } | 142 } |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer(elements); | 146 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer(elements); |
147 String name = | 147 String name = |
148 backend.namer.getNameOfGlobalField(backend.mapTypeToInterceptor); | 148 backend.namer.getNameOfGlobalField(backend.mapTypeToInterceptor); |
149 jsAst.Expression assignment = | 149 jsAst.Expression assignment = |
150 js('${emitter.isolateProperties}.# = #', [name, array]); | 150 js('${emitter.isolateProperties}.# = #', [name, array]); |
151 | 151 |
152 buffer.write(jsAst.prettyPrint(assignment, compiler)); | 152 buffer.write(jsAst.prettyPrint(assignment, compiler)); |
153 buffer.write(N); | 153 buffer.write(N); |
154 } | 154 } |
155 } | 155 } |
OLD | NEW |