| 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) { |
| 11 if (backend.isInterceptedMethod(member)) { | 11 if (backend.isInterceptedMethod(member)) { |
| 12 interceptorInvocationNames.add(name); | 12 interceptorInvocationNames.add(name); |
| 13 } | 13 } |
| 14 } | 14 } |
| 15 | 15 |
| 16 Set<ClassElement> interceptorsReferencedFromConstants() { | 16 Set<ClassElement> interceptorsReferencedFromConstants() { |
| 17 Set<ClassElement> classes = new Set<ClassElement>(); | 17 Set<ClassElement> classes = new Set<ClassElement>(); |
| 18 JavaScriptConstantCompiler handler = backend.constants; | 18 ConstantHandler handler = compiler.constantHandler; |
| 19 List<Constant> constants = handler.getConstantsForEmission(); | 19 List<Constant> constants = handler.getConstantsForEmission(); |
| 20 for (Constant constant in constants) { | 20 for (Constant constant in constants) { |
| 21 if (constant is InterceptorConstant) { | 21 if (constant is InterceptorConstant) { |
| 22 InterceptorConstant interceptorConstant = constant; | 22 InterceptorConstant interceptorConstant = constant; |
| 23 classes.add(interceptorConstant.dispatchedType.element); | 23 classes.add(interceptorConstant.dispatchedType.element); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 return classes; | 26 return classes; |
| 27 } | 27 } |
| 28 | 28 |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 * Emit initializer for [mapTypeToInterceptor] data structure used by | 435 * Emit initializer for [mapTypeToInterceptor] data structure used by |
| 436 * [findInterceptorForType]. See declaration of [mapTypeToInterceptor] in | 436 * [findInterceptorForType]. See declaration of [mapTypeToInterceptor] in |
| 437 * `interceptors.dart`. | 437 * `interceptors.dart`. |
| 438 */ | 438 */ |
| 439 void emitMapTypeToInterceptor(CodeBuffer buffer) { | 439 void emitMapTypeToInterceptor(CodeBuffer buffer) { |
| 440 // TODO(sra): Perhaps inject a constant instead? | 440 // TODO(sra): Perhaps inject a constant instead? |
| 441 CustomElementsAnalysis analysis = backend.customElementsAnalysis; | 441 CustomElementsAnalysis analysis = backend.customElementsAnalysis; |
| 442 if (!analysis.needsTable) return; | 442 if (!analysis.needsTable) return; |
| 443 | 443 |
| 444 List<jsAst.Expression> elements = <jsAst.Expression>[]; | 444 List<jsAst.Expression> elements = <jsAst.Expression>[]; |
| 445 JavaScriptConstantCompiler handler = backend.constants; | 445 ConstantHandler handler = compiler.constantHandler; |
| 446 List<Constant> constants = | 446 List<Constant> constants = |
| 447 handler.getConstantsForEmission(task.compareConstants); | 447 handler.getConstantsForEmission(task.compareConstants); |
| 448 for (Constant constant in constants) { | 448 for (Constant constant in constants) { |
| 449 if (constant is TypeConstant) { | 449 if (constant is TypeConstant) { |
| 450 TypeConstant typeConstant = constant; | 450 TypeConstant typeConstant = constant; |
| 451 Element element = typeConstant.representedType.element; | 451 Element element = typeConstant.representedType.element; |
| 452 if (element is ClassElement) { | 452 if (element is ClassElement) { |
| 453 ClassElement classElement = element; | 453 ClassElement classElement = element; |
| 454 if (!analysis.needsClass(classElement)) continue; | 454 if (!analysis.needsClass(classElement)) continue; |
| 455 | 455 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer.from(elements); | 489 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer.from(elements); |
| 490 String name = | 490 String name = |
| 491 backend.namer.getNameOfGlobalField(backend.mapTypeToInterceptor); | 491 backend.namer.getNameOfGlobalField(backend.mapTypeToInterceptor); |
| 492 jsAst.Expression assignment = | 492 jsAst.Expression assignment = |
| 493 js('${task.isolateProperties}.$name = #', array); | 493 js('${task.isolateProperties}.$name = #', array); |
| 494 | 494 |
| 495 buffer.write(jsAst.prettyPrint(assignment, compiler)); | 495 buffer.write(jsAst.prettyPrint(assignment, compiler)); |
| 496 buffer.write(N); | 496 buffer.write(N); |
| 497 } | 497 } |
| 498 } | 498 } |
| OLD | NEW |