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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 InterceptorStubGenerator { 7 class InterceptorStubGenerator {
8 final Compiler compiler; 8 final Compiler compiler;
9 final Namer namer; 9 final Namer namer;
10 final JavaScriptBackend backend; 10 final JavaScriptBackend backend;
11 11
12 InterceptorStubGenerator(this.compiler, this.namer, this.backend); 12 InterceptorStubGenerator(this.compiler, this.namer, this.backend);
13 13
14 Emitter get emitter => backend.emitter.emitter;
15
14 jsAst.Expression generateGetInterceptorMethod(Set<ClassElement> classes) { 16 jsAst.Expression generateGetInterceptorMethod(Set<ClassElement> classes) {
15 jsAst.Expression interceptorFor(ClassElement cls) { 17 jsAst.Expression interceptorFor(ClassElement cls) {
16 return backend.emitter.interceptorPrototypeAccess(cls); 18 return backend.emitter.interceptorPrototypeAccess(cls);
17 } 19 }
18 20
19 /** 21 /**
20 * Build a JavaScrit AST node for doing a type check on 22 * Build a JavaScrit AST node for doing a type check on
21 * [cls]. [cls] must be a non-native interceptor class. 23 * [cls]. [cls] must be a non-native interceptor class.
22 */ 24 */
23 jsAst.Statement buildInterceptorCheck(ClassElement cls) { 25 jsAst.Statement buildInterceptorCheck(ClassElement cls) {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 jsAst.Statement optimizedPath = 311 jsAst.Statement optimizedPath =
310 _fastPathForOneShotInterceptor(selector, classes); 312 _fastPathForOneShotInterceptor(selector, classes);
311 if (optimizedPath == null) optimizedPath = js.statement(';'); 313 if (optimizedPath == null) optimizedPath = js.statement(';');
312 314
313 return js( 315 return js(
314 'function(#) { #; return #.#(receiver).#(#) }', 316 'function(#) { #; return #.#(receiver).#(#) }',
315 [parameterNames, 317 [parameterNames,
316 optimizedPath, 318 optimizedPath,
317 globalObject, getInterceptorName, invocationName, parameterNames]); 319 globalObject, getInterceptorName, invocationName, parameterNames]);
318 } 320 }
319 } 321
322 jsAst.ArrayInitializer generateTypeToInterceptorMap() {
floitsch 2015/01/26 13:42:31 code is copied over from interceptor_emitter.
323 // TODO(sra): Perhaps inject a constant instead?
324 CustomElementsAnalysis analysis = backend.customElementsAnalysis;
325 if (!analysis.needsTable) return null;
326
327 List<jsAst.Expression> elements = <jsAst.Expression>[];
328 JavaScriptConstantCompiler handler = backend.constants;
329 List<ConstantValue> constants =
330 handler.getConstantsForEmission(emitter.compareConstants);
331 for (ConstantValue constant in constants) {
332 if (constant is TypeConstantValue) {
333 TypeConstantValue typeConstant = constant;
334 Element element = typeConstant.representedType.element;
335 if (element is ClassElement) {
336 ClassElement classElement = element;
337 if (!analysis.needsClass(classElement)) continue;
338
339 elements.add(emitter.constantReference(constant));
340 elements.add(backend.emitter.interceptorClassAccess(classElement));
341
342 // Create JavaScript Object map for by-name lookup of generative
343 // constructors. For example, the class A has three generative
344 // constructors
345 //
346 // class A {
347 // A() {}
348 // A.foo() {}
349 // A.bar() {}
350 // }
351 //
352 // Which are described by the map
353 //
354 // {"": A.A$, "foo": A.A$foo, "bar": A.A$bar}
355 //
356 // We expect most of the time the map will be a singleton.
357 var properties = [];
358 for (Element member in analysis.constructors(classElement)) {
359 properties.add(
360 new jsAst.Property(
361 js.string(member.name),
362 backend.emitter.staticFunctionAccess(member)));
363 }
364
365 var map = new jsAst.ObjectInitializer(properties);
366 elements.add(map);
367 }
368 }
369 }
370
371 return new jsAst.ArrayInitializer(elements);
372 }
373 }
OLDNEW
« 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