| OLD | NEW |
| 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 ClassStubGenerator { | 7 class ClassStubGenerator { |
| 8 final Namer namer; | 8 final Namer namer; |
| 9 final Compiler compiler; | 9 final Compiler compiler; |
| 10 final JavaScriptBackend backend; | 10 final JavaScriptBackend backend; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 return js('function(#, v) { return #.# = v; }', | 41 return js('function(#, v) { return #.# = v; }', |
| 42 [args, receiver, fieldName]); | 42 [args, receiver, fieldName]); |
| 43 } | 43 } |
| 44 | 44 |
| 45 /** | 45 /** |
| 46 * Documentation wanted -- johnniwinther | 46 * Documentation wanted -- johnniwinther |
| 47 * | 47 * |
| 48 * Invariant: [member] must be a declaration element. | 48 * Invariant: [member] must be a declaration element. |
| 49 */ | 49 */ |
| 50 Map<jsAst.Name, jsAst.Expression> generateCallStubsForGetter( | 50 Map<jsAst.Name, jsAst.Expression> generateCallStubsForGetter( |
| 51 Element member, Map<Selector, TypeMaskSet> selectors) { | 51 Element member, Map<Selector, ReceiverMaskSet> selectors) { |
| 52 assert(invariant(member, member.isDeclaration)); | 52 assert(invariant(member, member.isDeclaration)); |
| 53 | 53 |
| 54 // If the method is intercepted, the stub gets the | 54 // If the method is intercepted, the stub gets the |
| 55 // receiver explicitely and we need to pass it to the getter call. | 55 // receiver explicitely and we need to pass it to the getter call. |
| 56 bool isInterceptedMethod = backend.isInterceptedMethod(member); | 56 bool isInterceptedMethod = backend.isInterceptedMethod(member); |
| 57 bool isInterceptorClass = | 57 bool isInterceptorClass = |
| 58 backend.isInterceptorClass(member.enclosingClass); | 58 backend.isInterceptorClass(member.enclosingClass); |
| 59 | 59 |
| 60 const String receiverArgumentName = r'$receiver'; | 60 const String receiverArgumentName = r'$receiver'; |
| 61 | 61 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 77 Map<jsAst.Name, jsAst.Expression> generatedStubs = | 77 Map<jsAst.Name, jsAst.Expression> generatedStubs = |
| 78 <jsAst.Name, jsAst.Expression>{}; | 78 <jsAst.Name, jsAst.Expression>{}; |
| 79 | 79 |
| 80 // Two selectors may match but differ only in type. To avoid generating | 80 // Two selectors may match but differ only in type. To avoid generating |
| 81 // identical stubs for each we track untyped selectors which already have | 81 // identical stubs for each we track untyped selectors which already have |
| 82 // stubs. | 82 // stubs. |
| 83 Set<Selector> generatedSelectors = new Set<Selector>(); | 83 Set<Selector> generatedSelectors = new Set<Selector>(); |
| 84 for (Selector selector in selectors.keys) { | 84 for (Selector selector in selectors.keys) { |
| 85 if (generatedSelectors.contains(selector)) continue; | 85 if (generatedSelectors.contains(selector)) continue; |
| 86 if (!selector.appliesUnnamed(member, compiler.world)) continue; | 86 if (!selector.appliesUnnamed(member, compiler.world)) continue; |
| 87 for (TypeMask mask in selectors[selector].masks) { | 87 if (selectors[selector].applies(member, selector, compiler.world)) { |
| 88 if (mask != null && | |
| 89 !mask.canHit(member, selector, compiler.world)) { | |
| 90 continue; | |
| 91 } | |
| 92 | |
| 93 generatedSelectors.add(selector); | 88 generatedSelectors.add(selector); |
| 94 | 89 |
| 95 jsAst.Name invocationName = namer.invocationName(selector); | 90 jsAst.Name invocationName = namer.invocationName(selector); |
| 96 Selector callSelector = new Selector.callClosureFrom(selector); | 91 Selector callSelector = new Selector.callClosureFrom(selector); |
| 97 jsAst.Name closureCallName = namer.invocationName(callSelector); | 92 jsAst.Name closureCallName = namer.invocationName(callSelector); |
| 98 | 93 |
| 99 List<jsAst.Parameter> parameters = <jsAst.Parameter>[]; | 94 List<jsAst.Parameter> parameters = <jsAst.Parameter>[]; |
| 100 List<jsAst.Expression> arguments = <jsAst.Expression>[]; | 95 List<jsAst.Expression> arguments = <jsAst.Expression>[]; |
| 101 if (isInterceptedMethod) { | 96 if (isInterceptedMethod) { |
| 102 parameters.add(new jsAst.Parameter(receiverArgumentName)); | 97 parameters.add(new jsAst.Parameter(receiverArgumentName)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 122 Map<jsAst.Name, Selector> computeSelectorsForNsmHandlers() { | 117 Map<jsAst.Name, Selector> computeSelectorsForNsmHandlers() { |
| 123 | 118 |
| 124 Map<jsAst.Name, Selector> jsNames = <jsAst.Name, Selector>{}; | 119 Map<jsAst.Name, Selector> jsNames = <jsAst.Name, Selector>{}; |
| 125 | 120 |
| 126 // Do not generate no such method handlers if there is no class. | 121 // Do not generate no such method handlers if there is no class. |
| 127 if (compiler.codegenWorld.directlyInstantiatedClasses.isEmpty) { | 122 if (compiler.codegenWorld.directlyInstantiatedClasses.isEmpty) { |
| 128 return jsNames; | 123 return jsNames; |
| 129 } | 124 } |
| 130 | 125 |
| 131 void addNoSuchMethodHandlers(String ignore, | 126 void addNoSuchMethodHandlers(String ignore, |
| 132 Map<Selector, TypeMaskSet> selectors) { | 127 Map<Selector, ReceiverMaskSet> selectors) { |
| 133 TypeMask objectSubclassTypeMask = | |
| 134 new TypeMask.subclass(compiler.objectClass, compiler.world); | |
| 135 | |
| 136 for (Selector selector in selectors.keys) { | 128 for (Selector selector in selectors.keys) { |
| 137 TypeMaskSet maskSet = selectors[selector]; | 129 ReceiverMaskSet maskSet = selectors[selector]; |
| 138 for (TypeMask mask in maskSet.masks) { | 130 if (maskSet.needsNoSuchMethodHandling(selector, compiler.world)) { |
| 139 if (mask == null) mask = objectSubclassTypeMask; | 131 jsAst.Name jsName = namer.invocationMirrorInternalName(selector); |
| 140 | 132 jsNames[jsName] = selector; |
| 141 if (mask.needsNoSuchMethodHandling(selector, compiler.world)) { | |
| 142 jsAst.Name jsName = namer.invocationMirrorInternalName(selector); | |
| 143 jsNames[jsName] = selector; | |
| 144 break; | |
| 145 } | |
| 146 } | 133 } |
| 147 } | 134 } |
| 148 } | 135 } |
| 149 | 136 |
| 150 compiler.codegenWorld.forEachInvokedName(addNoSuchMethodHandlers); | 137 compiler.codegenWorld.forEachInvokedName(addNoSuchMethodHandlers); |
| 151 compiler.codegenWorld.forEachInvokedGetter(addNoSuchMethodHandlers); | 138 compiler.codegenWorld.forEachInvokedGetter(addNoSuchMethodHandlers); |
| 152 compiler.codegenWorld.forEachInvokedSetter(addNoSuchMethodHandlers); | 139 compiler.codegenWorld.forEachInvokedSetter(addNoSuchMethodHandlers); |
| 153 return jsNames; | 140 return jsNames; |
| 154 } | 141 } |
| 155 | 142 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 ? function() { | 275 ? function() { |
| 289 if (cache === void 0) cache = #tearOff( | 276 if (cache === void 0) cache = #tearOff( |
| 290 this, funcs, reflectionInfo, true, [], name).prototype; | 277 this, funcs, reflectionInfo, true, [], name).prototype; |
| 291 return cache; | 278 return cache; |
| 292 } | 279 } |
| 293 : tearOffGetter(funcs, reflectionInfo, name, isIntercepted); | 280 : tearOffGetter(funcs, reflectionInfo, name, isIntercepted); |
| 294 }''', {'tearOff': tearOffAccessExpression}); | 281 }''', {'tearOff': tearOffAccessExpression}); |
| 295 | 282 |
| 296 return <jsAst.Statement>[tearOffGetter, tearOff]; | 283 return <jsAst.Statement>[tearOffGetter, tearOff]; |
| 297 } | 284 } |
| OLD | NEW |