| 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 /// This class should morph into something that makes it easy to build | 7 /// This class should morph into something that makes it easy to build |
| 8 /// JavaScript representations of libraries, class-sides, and instance-sides. | 8 /// JavaScript representations of libraries, class-sides, and instance-sides. |
| 9 /// Initially, it is just a placeholder for code that is moved from | 9 /// Initially, it is just a placeholder for code that is moved from |
| 10 /// [CodeEmitterTask]. | 10 /// [CodeEmitterTask]. |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 RuntimeTypes rti = backend.rti; | 315 RuntimeTypes rti = backend.rti; |
| 316 // [:() => null:] is dummy encoding of [this] which is never needed for | 316 // [:() => null:] is dummy encoding of [this] which is never needed for |
| 317 // the encoding of the type of the static [method]. | 317 // the encoding of the type of the static [method]. |
| 318 jsAst.Expression encoding = | 318 jsAst.Expression encoding = |
| 319 rti.getSignatureEncoding(methodType, js('null')); | 319 rti.getSignatureEncoding(methodType, js('null')); |
| 320 String operatorSignature = namer.operatorSignature(); | 320 String operatorSignature = namer.operatorSignature(); |
| 321 // TODO(johnniwinther): Make MiniJsParser support function expressions. | 321 // TODO(johnniwinther): Make MiniJsParser support function expressions. |
| 322 closureBuilder.addProperty(operatorSignature, encoding); | 322 closureBuilder.addProperty(operatorSignature, encoding); |
| 323 } | 323 } |
| 324 | 324 |
| 325 void emitIsFunctionTypeTest(FunctionType functionType) { | |
| 326 String operator = namer.operatorIsType(functionType); | |
| 327 closureBuilder.addProperty(operator, js('true')); | |
| 328 } | |
| 329 | |
| 330 FunctionType methodType = element.computeType(compiler); | 325 FunctionType methodType = element.computeType(compiler); |
| 331 Map<FunctionType, bool> functionTypeChecks = | 326 Map<FunctionType, bool> functionTypeChecks = |
| 332 task.typeTestEmitter.getFunctionTypeChecksOn(methodType); | 327 task.typeTestEmitter.getFunctionTypeChecksOn(methodType); |
| 333 task.typeTestEmitter.generateFunctionTypeTests( | 328 task.typeTestEmitter.generateFunctionTypeTests( |
| 334 element, methodType, functionTypeChecks, | 329 element, methodType, functionTypeChecks, |
| 335 emitFunctionTypeSignature, emitIsFunctionTypeTest); | 330 emitFunctionTypeSignature); |
| 336 | 331 |
| 337 closureClassElement = | 332 closureClassElement = |
| 338 addClosureIfNew(closureBuilder, closureClassElement, fieldNames); | 333 addClosureIfNew(closureBuilder, closureClassElement, fieldNames); |
| 339 staticGetters[element] = closureClassElement; | 334 staticGetters[element] = closureClassElement; |
| 340 | 335 |
| 341 } | 336 } |
| 342 } | 337 } |
| 343 | 338 |
| 344 ClassElement addClosureIfNew(ClassBuilder builder, | 339 ClassElement addClosureIfNew(ClassBuilder builder, |
| 345 ClassElement closure, | 340 ClassElement closure, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 444 |
| 450 addParameterStubs(callElement, boundClosureBuilder.addProperty); | 445 addParameterStubs(callElement, boundClosureBuilder.addProperty); |
| 451 | 446 |
| 452 void emitFunctionTypeSignature(Element method, FunctionType methodType) { | 447 void emitFunctionTypeSignature(Element method, FunctionType methodType) { |
| 453 jsAst.Expression encoding = backend.rti.getSignatureEncoding( | 448 jsAst.Expression encoding = backend.rti.getSignatureEncoding( |
| 454 methodType, js('this')[fieldNames[0]]); | 449 methodType, js('this')[fieldNames[0]]); |
| 455 String operatorSignature = namer.operatorSignature(); | 450 String operatorSignature = namer.operatorSignature(); |
| 456 boundClosureBuilder.addProperty(operatorSignature, encoding); | 451 boundClosureBuilder.addProperty(operatorSignature, encoding); |
| 457 } | 452 } |
| 458 | 453 |
| 459 void emitIsFunctionTypeTest(FunctionType functionType) { | |
| 460 String operator = namer.operatorIsType(functionType); | |
| 461 boundClosureBuilder.addProperty(operator, | |
| 462 new jsAst.LiteralBool(true)); | |
| 463 } | |
| 464 | |
| 465 DartType memberType = member.computeType(compiler); | 454 DartType memberType = member.computeType(compiler); |
| 466 Map<FunctionType, bool> functionTypeChecks = | 455 Map<FunctionType, bool> functionTypeChecks = |
| 467 task.typeTestEmitter.getFunctionTypeChecksOn(memberType); | 456 task.typeTestEmitter.getFunctionTypeChecksOn(memberType); |
| 468 | 457 |
| 469 task.typeTestEmitter.generateFunctionTypeTests( | 458 task.typeTestEmitter.generateFunctionTypeTests( |
| 470 member, memberType, functionTypeChecks, | 459 member, memberType, functionTypeChecks, |
| 471 emitFunctionTypeSignature, emitIsFunctionTypeTest); | 460 emitFunctionTypeSignature); |
| 472 | 461 |
| 473 closureClassElement = | 462 closureClassElement = |
| 474 addClosureIfNew(boundClosureBuilder, closureClassElement, fieldNames); | 463 addClosureIfNew(boundClosureBuilder, closureClassElement, fieldNames); |
| 475 | 464 |
| 476 String closureClass = namer.isolateAccess(closureClassElement); | 465 String closureClass = namer.isolateAccess(closureClassElement); |
| 477 | 466 |
| 478 // And finally the getter. | 467 // And finally the getter. |
| 479 String getterName = namer.getterName(member); | 468 String getterName = namer.getterName(member); |
| 480 String targetName = namer.instanceMethodName(member); | 469 String targetName = namer.instanceMethodName(member); |
| 481 | 470 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 if (!parameters.optionalParameters.isEmpty) { | 618 if (!parameters.optionalParameters.isEmpty) { |
| 630 addParameterStubs(member, builder.addProperty); | 619 addParameterStubs(member, builder.addProperty); |
| 631 } | 620 } |
| 632 } | 621 } |
| 633 } | 622 } |
| 634 | 623 |
| 635 void addMemberField(VariableElement member, ClassBuilder builder) { | 624 void addMemberField(VariableElement member, ClassBuilder builder) { |
| 636 // For now, do nothing. | 625 // For now, do nothing. |
| 637 } | 626 } |
| 638 } | 627 } |
| OLD | NEW |