| 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.full_emitter; | 5 part of dart2js.js_emitter.full_emitter; |
| 6 | 6 |
| 7 class InterceptorEmitter extends CodeEmitterHelper { | 7 class InterceptorEmitter extends CodeEmitterHelper { |
| 8 final ClosedWorld closedWorld; |
| 8 final Set<jsAst.Name> interceptorInvocationNames = new Set<jsAst.Name>(); | 9 final Set<jsAst.Name> interceptorInvocationNames = new Set<jsAst.Name>(); |
| 9 | 10 |
| 11 InterceptorEmitter(this.closedWorld); |
| 12 |
| 10 void recordMangledNameOfMemberMethod( | 13 void recordMangledNameOfMemberMethod( |
| 11 FunctionElement member, jsAst.Name name) { | 14 FunctionElement member, jsAst.Name name) { |
| 12 if (backend.isInterceptedMethod(member)) { | 15 if (backend.isInterceptedMethod(member)) { |
| 13 interceptorInvocationNames.add(name); | 16 interceptorInvocationNames.add(name); |
| 14 } | 17 } |
| 15 } | 18 } |
| 16 | 19 |
| 17 jsAst.Expression buildGetInterceptorMethod( | 20 jsAst.Expression buildGetInterceptorMethod( |
| 18 jsAst.Name key, Set<ClassElement> classes) { | 21 jsAst.Name key, Set<ClassElement> classes) { |
| 19 InterceptorStubGenerator stubGenerator = | 22 InterceptorStubGenerator stubGenerator = |
| 20 new InterceptorStubGenerator(compiler, namer, backend); | 23 new InterceptorStubGenerator(compiler, namer, backend, closedWorld); |
| 21 jsAst.Expression function = | 24 jsAst.Expression function = |
| 22 stubGenerator.generateGetInterceptorMethod(classes); | 25 stubGenerator.generateGetInterceptorMethod(classes); |
| 23 | 26 |
| 24 return function; | 27 return function; |
| 25 } | 28 } |
| 26 | 29 |
| 27 /** | 30 /** |
| 28 * Emit all versions of the [:getInterceptor:] method. | 31 * Emit all versions of the [:getInterceptor:] method. |
| 29 */ | 32 */ |
| 30 jsAst.Statement buildGetInterceptorMethods() { | 33 jsAst.Statement buildGetInterceptorMethods() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 46 | 49 |
| 47 return new jsAst.Block(parts); | 50 return new jsAst.Block(parts); |
| 48 } | 51 } |
| 49 | 52 |
| 50 jsAst.Statement buildOneShotInterceptors() { | 53 jsAst.Statement buildOneShotInterceptors() { |
| 51 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 54 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
| 52 Iterable<jsAst.Name> names = backend.oneShotInterceptors.keys.toList() | 55 Iterable<jsAst.Name> names = backend.oneShotInterceptors.keys.toList() |
| 53 ..sort(); | 56 ..sort(); |
| 54 | 57 |
| 55 InterceptorStubGenerator stubGenerator = | 58 InterceptorStubGenerator stubGenerator = |
| 56 new InterceptorStubGenerator(compiler, namer, backend); | 59 new InterceptorStubGenerator(compiler, namer, backend, closedWorld); |
| 57 String globalObject = | 60 String globalObject = |
| 58 namer.globalObjectFor(backend.helpers.interceptorsLibrary); | 61 namer.globalObjectFor(backend.helpers.interceptorsLibrary); |
| 59 for (jsAst.Name name in names) { | 62 for (jsAst.Name name in names) { |
| 60 jsAst.Expression function = | 63 jsAst.Expression function = |
| 61 stubGenerator.generateOneShotInterceptor(name); | 64 stubGenerator.generateOneShotInterceptor(name); |
| 62 parts.add(js.statement('${globalObject}.# = #', [name, function])); | 65 parts.add(js.statement('${globalObject}.# = #', [name, function])); |
| 63 } | 66 } |
| 64 | 67 |
| 65 return new jsAst.Block(parts); | 68 return new jsAst.Block(parts); |
| 66 } | 69 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 94 */ | 97 */ |
| 95 jsAst.Statement buildTypeToInterceptorMap(Program program) { | 98 jsAst.Statement buildTypeToInterceptorMap(Program program) { |
| 96 jsAst.Expression array = program.typeToInterceptorMap; | 99 jsAst.Expression array = program.typeToInterceptorMap; |
| 97 if (array == null) return js.comment("Empty type-to-interceptor map."); | 100 if (array == null) return js.comment("Empty type-to-interceptor map."); |
| 98 | 101 |
| 99 jsAst.Expression typeToInterceptorMap = emitter | 102 jsAst.Expression typeToInterceptorMap = emitter |
| 100 .generateEmbeddedGlobalAccess(embeddedNames.TYPE_TO_INTERCEPTOR_MAP); | 103 .generateEmbeddedGlobalAccess(embeddedNames.TYPE_TO_INTERCEPTOR_MAP); |
| 101 return js.statement('# = #', [typeToInterceptorMap, array]); | 104 return js.statement('# = #', [typeToInterceptorMap, array]); |
| 102 } | 105 } |
| 103 } | 106 } |
| OLD | NEW |