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

Unified Diff: pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart

Issue 876653002: dart2js: move mapTypeToInterceptor generation to interceptor_stub_generator. and rename to typeToIn… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart
diff --git a/pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart b/pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart
index ee78a5f4cf6b34bc8b6767d9af95735a8566bb00..9f10524d1b2abc421d9508b23bbd175fe95a66d7 100644
--- a/pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart
@@ -11,6 +11,8 @@ class InterceptorStubGenerator {
InterceptorStubGenerator(this.compiler, this.namer, this.backend);
+ Emitter get emitter => backend.emitter.emitter;
+
jsAst.Expression generateGetInterceptorMethod(Set<ClassElement> classes) {
jsAst.Expression interceptorFor(ClassElement cls) {
return backend.emitter.interceptorPrototypeAccess(cls);
@@ -316,4 +318,56 @@ class InterceptorStubGenerator {
optimizedPath,
globalObject, getInterceptorName, invocationName, parameterNames]);
}
-}
+
+ jsAst.ArrayInitializer generateTypeToInterceptorMap() {
floitsch 2015/01/26 13:42:31 code is copied over from interceptor_emitter.
+ // TODO(sra): Perhaps inject a constant instead?
+ CustomElementsAnalysis analysis = backend.customElementsAnalysis;
+ if (!analysis.needsTable) return null;
+
+ List<jsAst.Expression> elements = <jsAst.Expression>[];
+ JavaScriptConstantCompiler handler = backend.constants;
+ List<ConstantValue> constants =
+ handler.getConstantsForEmission(emitter.compareConstants);
+ for (ConstantValue constant in constants) {
+ if (constant is TypeConstantValue) {
+ TypeConstantValue typeConstant = constant;
+ Element element = typeConstant.representedType.element;
+ if (element is ClassElement) {
+ ClassElement classElement = element;
+ if (!analysis.needsClass(classElement)) continue;
+
+ elements.add(emitter.constantReference(constant));
+ elements.add(backend.emitter.interceptorClassAccess(classElement));
+
+ // Create JavaScript Object map for by-name lookup of generative
+ // constructors. For example, the class A has three generative
+ // constructors
+ //
+ // class A {
+ // A() {}
+ // A.foo() {}
+ // A.bar() {}
+ // }
+ //
+ // Which are described by the map
+ //
+ // {"": A.A$, "foo": A.A$foo, "bar": A.A$bar}
+ //
+ // We expect most of the time the map will be a singleton.
+ var properties = [];
+ for (Element member in analysis.constructors(classElement)) {
+ properties.add(
+ new jsAst.Property(
+ js.string(member.name),
+ backend.emitter.staticFunctionAccess(member)));
+ }
+
+ var map = new jsAst.ObjectInitializer(properties);
+ elements.add(map);
+ }
+ }
+ }
+
+ return new jsAst.ArrayInitializer(elements);
+ }
+}
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698