| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 new List.generate(selector.argumentCount, (i) => '\$$i'); | 151 new List.generate(selector.argumentCount, (i) => '\$$i'); |
| 152 | 152 |
| 153 List<jsAst.Expression> argNames = | 153 List<jsAst.Expression> argNames = |
| 154 selector.callStructure.getOrderedNamedArguments().map((String name) => | 154 selector.callStructure.getOrderedNamedArguments().map((String name) => |
| 155 js.string(name)).toList(); | 155 js.string(name)).toList(); |
| 156 | 156 |
| 157 String methodName = selector.invocationMirrorMemberName; | 157 String methodName = selector.invocationMirrorMemberName; |
| 158 String internalName = namer.invocationMirrorInternalName(selector); | 158 String internalName = namer.invocationMirrorInternalName(selector); |
| 159 | 159 |
| 160 assert(backend.isInterceptedName(Compiler.NO_SUCH_METHOD)); | 160 assert(backend.isInterceptedName(Compiler.NO_SUCH_METHOD)); |
| 161 bool isIntercepted = backend.isInterceptedName(selector.name); | |
| 162 jsAst.Expression expression = | 161 jsAst.Expression expression = |
| 163 js('''this.#noSuchMethodName(#receiver, | 162 js('''this.#noSuchMethodName(this, |
| 164 #createInvocationMirror(#methodName, | 163 #createInvocationMirror(#methodName, |
| 165 #internalName, | 164 #internalName, |
| 166 #type, | 165 #type, |
| 167 #arguments, | 166 #arguments, |
| 168 #namedArguments))''', | 167 #namedArguments))''', |
| 169 {'receiver': isIntercepted ? r'$receiver' : 'this', | 168 {'noSuchMethodName': namer.noSuchMethodName, |
| 170 'noSuchMethodName': namer.noSuchMethodName, | |
| 171 'createInvocationMirror': | 169 'createInvocationMirror': |
| 172 backend.emitter.staticFunctionAccess( | 170 backend.emitter.staticFunctionAccess( |
| 173 backend.getCreateInvocationMirror()), | 171 backend.getCreateInvocationMirror()), |
| 174 'methodName': | 172 'methodName': |
| 175 js.string(compiler.enableMinification | 173 js.string(compiler.enableMinification |
| 176 ? internalName : methodName), | 174 ? internalName : methodName), |
| 177 'internalName': js.string(internalName), | 175 'internalName': js.string(internalName), |
| 178 'type': js.number(type), | 176 'type': js.number(type), |
| 179 'arguments': | 177 'arguments': |
| 180 new jsAst.ArrayInitializer(parameterNames.map(js).toList()), | 178 new jsAst.ArrayInitializer(parameterNames.map(js).toList()), |
| 181 'namedArguments': new jsAst.ArrayInitializer(argNames)}); | 179 'namedArguments': new jsAst.ArrayInitializer(argNames)}); |
| 182 | 180 |
| 183 jsAst.Expression function; | 181 jsAst.Expression function; |
| 184 if (isIntercepted) { | 182 if (backend.isInterceptedName(selector.name)) { |
| 185 function = js(r'function($receiver, #) { return # }', | 183 function = js(r'function($receiver, #) { return # }', |
| 186 [parameterNames, expression]); | 184 [parameterNames, expression]); |
| 187 } else { | 185 } else { |
| 188 function = js(r'function(#) { return # }', [parameterNames, expression]); | 186 function = js(r'function(#) { return # }', [parameterNames, expression]); |
| 189 } | 187 } |
| 190 return new StubMethod(name, function); | 188 return new StubMethod(name, function); |
| 191 } | 189 } |
| 192 } | 190 } |
| 193 | 191 |
| 194 /// Creates two JavaScript functions: `tearOffGetter` and `tearOff`. | 192 /// Creates two JavaScript functions: `tearOffGetter` and `tearOff`. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 ? function() { | 279 ? function() { |
| 282 if (cache === void 0) cache = #tearOff( | 280 if (cache === void 0) cache = #tearOff( |
| 283 this, funcs, reflectionInfo, true, [], name).prototype; | 281 this, funcs, reflectionInfo, true, [], name).prototype; |
| 284 return cache; | 282 return cache; |
| 285 } | 283 } |
| 286 : tearOffGetter(funcs, reflectionInfo, name, isIntercepted); | 284 : tearOffGetter(funcs, reflectionInfo, name, isIntercepted); |
| 287 }''', {'tearOff': tearOffAccessExpression}); | 285 }''', {'tearOff': tearOffAccessExpression}); |
| 288 | 286 |
| 289 return <jsAst.Statement>[tearOffGetter, tearOff]; | 287 return <jsAst.Statement>[tearOffGetter, tearOff]; |
| 290 } | 288 } |
| OLD | NEW |