| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A function element that represents a closure call. The signature is copied | 8 * A function element that represents a closure call. The signature is copied |
| 9 * from the given element. | 9 * from the given element. |
| 10 */ | 10 */ |
| (...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1536 String receiver = backend.isInterceptorClass(member.getEnclosingClass()) | 1536 String receiver = backend.isInterceptorClass(member.getEnclosingClass()) |
| 1537 ? 'receiver' : 'this'; | 1537 ? 'receiver' : 'this'; |
| 1538 List<String> args = backend.isInterceptedMethod(member) | 1538 List<String> args = backend.isInterceptedMethod(member) |
| 1539 ? ['receiver', 'v'] | 1539 ? ['receiver', 'v'] |
| 1540 : ['v']; | 1540 : ['v']; |
| 1541 builder.addProperty(setterName, | 1541 builder.addProperty(setterName, |
| 1542 js.fun(args, js('$receiver.$fieldName = v'))); | 1542 js.fun(args, js('$receiver.$fieldName = v'))); |
| 1543 } | 1543 } |
| 1544 | 1544 |
| 1545 bool canGenerateCheckedSetter(Element member) { | 1545 bool canGenerateCheckedSetter(Element member) { |
| 1546 DartType type = member.computeType(compiler); | 1546 DartType type = member.computeType(compiler).unalias(compiler); |
| 1547 if (type.element.isTypeVariable() | 1547 if (type.element.isTypeVariable() || |
| 1548 || type.element == compiler.dynamicClass | 1548 (type is FunctionType && type.containsTypeVariables) || |
| 1549 || type.element == compiler.objectClass) { | 1549 type.element == compiler.dynamicClass || |
| 1550 type.element == compiler.objectClass) { |
| 1550 // TODO(ngeoffray): Support type checks on type parameters. | 1551 // TODO(ngeoffray): Support type checks on type parameters. |
| 1551 return false; | 1552 return false; |
| 1552 } | 1553 } |
| 1553 return true; | 1554 return true; |
| 1554 } | 1555 } |
| 1555 | 1556 |
| 1556 void generateCheckedSetter(Element member, | 1557 void generateCheckedSetter(Element member, |
| 1557 String fieldName, | 1558 String fieldName, |
| 1558 String accessorName, | 1559 String accessorName, |
| 1559 ClassBuilder builder) { | 1560 ClassBuilder builder) { |
| 1560 assert(canGenerateCheckedSetter(member)); | 1561 assert(canGenerateCheckedSetter(member)); |
| 1561 DartType type = member.computeType(compiler); | 1562 DartType type = member.computeType(compiler); |
| 1562 // TODO(ahe): Generate a dynamic type error here. | 1563 // TODO(ahe): Generate a dynamic type error here. |
| 1563 if (type.element.isErroneous()) return; | 1564 if (type.element.isErroneous()) return; |
| 1564 type = type.unalias(compiler); | 1565 type = type.unalias(compiler); |
| 1566 // TODO(11273): Support complex subtype checks. |
| 1567 type = type.asRaw(); |
| 1565 CheckedModeHelper helper = | 1568 CheckedModeHelper helper = |
| 1566 backend.getCheckedModeHelper(type, typeCast: false); | 1569 backend.getCheckedModeHelper(type, typeCast: false); |
| 1567 FunctionElement helperElement = helper.getElement(compiler); | 1570 FunctionElement helperElement = helper.getElement(compiler); |
| 1568 String helperName = namer.isolateAccess(helperElement); | 1571 String helperName = namer.isolateAccess(helperElement); |
| 1569 List<jsAst.Expression> arguments = <jsAst.Expression>[js('v')]; | 1572 List<jsAst.Expression> arguments = <jsAst.Expression>[js('v')]; |
| 1570 if (helperElement.computeSignature(compiler).parameterCount != 1) { | 1573 if (helperElement.computeSignature(compiler).parameterCount != 1) { |
| 1571 arguments.add(js.string(namer.operatorIsType(type))); | 1574 arguments.add(js.string(namer.operatorIsType(type))); |
| 1572 } | 1575 } |
| 1573 | 1576 |
| 1574 String setterName = namer.setterNameFromAccessorName(accessorName); | 1577 String setterName = namer.setterNameFromAccessorName(accessorName); |
| (...skipping 2126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3701 | 3704 |
| 3702 const String HOOKS_API_USAGE = """ | 3705 const String HOOKS_API_USAGE = """ |
| 3703 // The code supports the following hooks: | 3706 // The code supports the following hooks: |
| 3704 // dartPrint(message) - if this function is defined it is called | 3707 // dartPrint(message) - if this function is defined it is called |
| 3705 // instead of the Dart [print] method. | 3708 // instead of the Dart [print] method. |
| 3706 // dartMainRunner(main) - if this function is defined, the Dart [main] | 3709 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 3707 // method will not be invoked directly. | 3710 // method will not be invoked directly. |
| 3708 // Instead, a closure that will invoke [main] is | 3711 // Instead, a closure that will invoke [main] is |
| 3709 // passed to [dartMainRunner]. | 3712 // passed to [dartMainRunner]. |
| 3710 """; | 3713 """; |
| OLD | NEW |