| 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 25 matching lines...) Expand all Loading... |
| 36 assert(selector.namedArgumentCount == 0); | 36 assert(selector.namedArgumentCount == 0); |
| 37 return; | 37 return; |
| 38 } | 38 } |
| 39 if (parameters.optionalParametersAreNamed | 39 if (parameters.optionalParametersAreNamed |
| 40 && selector.namedArgumentCount == parameters.optionalParameterCount) { | 40 && selector.namedArgumentCount == parameters.optionalParameterCount) { |
| 41 // If the selector has the same number of named arguments as the element, | 41 // If the selector has the same number of named arguments as the element, |
| 42 // we don't need to add a stub. The call site will hit the method | 42 // we don't need to add a stub. The call site will hit the method |
| 43 // directly. | 43 // directly. |
| 44 return; | 44 return; |
| 45 } | 45 } |
| 46 ConstantHandler handler = compiler.constantHandler; | 46 JavaScriptConstantCompiler handler = backend.constants; |
| 47 List<String> names = selector.getOrderedNamedArguments(); | 47 List<String> names = selector.getOrderedNamedArguments(); |
| 48 | 48 |
| 49 String invocationName = namer.invocationName(selector); | 49 String invocationName = namer.invocationName(selector); |
| 50 if (alreadyGenerated.contains(invocationName)) return; | 50 if (alreadyGenerated.contains(invocationName)) return; |
| 51 alreadyGenerated.add(invocationName); | 51 alreadyGenerated.add(invocationName); |
| 52 | 52 |
| 53 bool isInterceptedMethod = backend.isInterceptedMethod(member); | 53 bool isInterceptedMethod = backend.isInterceptedMethod(member); |
| 54 | 54 |
| 55 // If the method is intercepted, we need to also pass the actual receiver. | 55 // If the method is intercepted, we need to also pass the actual receiver. |
| 56 int extraArgumentCount = isInterceptedMethod ? 1 : 0; | 56 int extraArgumentCount = isInterceptedMethod ? 1 : 0; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } else { | 92 } else { |
| 93 int index = names.indexOf(element.name); | 93 int index = names.indexOf(element.name); |
| 94 if (index != -1) { | 94 if (index != -1) { |
| 95 indexOfLastOptionalArgumentInParameters = count; | 95 indexOfLastOptionalArgumentInParameters = count; |
| 96 // The order of the named arguments is not the same as the | 96 // The order of the named arguments is not the same as the |
| 97 // one in the real method (which is in Dart source order). | 97 // one in the real method (which is in Dart source order). |
| 98 argumentsBuffer[count] = js(jsName); | 98 argumentsBuffer[count] = js(jsName); |
| 99 parametersBuffer[optionalParameterStart + index] = | 99 parametersBuffer[optionalParameterStart + index] = |
| 100 new jsAst.Parameter(jsName); | 100 new jsAst.Parameter(jsName); |
| 101 } else { | 101 } else { |
| 102 Constant value = handler.initialVariableValues[element]; | 102 Constant value = handler.getConstantForVariable(element); |
| 103 if (value == null) { | 103 if (value == null) { |
| 104 argumentsBuffer[count] = task.constantReference(new NullConstant()); | 104 argumentsBuffer[count] = task.constantReference(new NullConstant()); |
| 105 } else { | 105 } else { |
| 106 if (!value.isNull) { | 106 if (!value.isNull) { |
| 107 // If the value is the null constant, we should not pass it | 107 // If the value is the null constant, we should not pass it |
| 108 // down to the native method. | 108 // down to the native method. |
| 109 indexOfLastOptionalArgumentInParameters = count; | 109 indexOfLastOptionalArgumentInParameters = count; |
| 110 } | 110 } |
| 111 argumentsBuffer[count] = task.constantReference(value); | 111 argumentsBuffer[count] = task.constantReference(value); |
| 112 } | 112 } |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 ..add(optionalParameterCount) | 498 ..add(optionalParameterCount) |
| 499 ..add(memberTypeExpression) | 499 ..add(memberTypeExpression) |
| 500 ..addAll(task.metadataEmitter.reifyDefaultArguments(member)); | 500 ..addAll(task.metadataEmitter.reifyDefaultArguments(member)); |
| 501 | 501 |
| 502 if (canBeReflected || canBeApplied) { | 502 if (canBeReflected || canBeApplied) { |
| 503 parameters.forEachParameter((Element parameter) { | 503 parameters.forEachParameter((Element parameter) { |
| 504 expressions.add(task.metadataEmitter.reifyName(parameter.name)); | 504 expressions.add(task.metadataEmitter.reifyName(parameter.name)); |
| 505 if (backend.mustRetainMetadata) { | 505 if (backend.mustRetainMetadata) { |
| 506 List<MetadataAnnotation> annotations = parameter.metadata.toList(); | 506 List<MetadataAnnotation> annotations = parameter.metadata.toList(); |
| 507 Iterable<int> metadataIndices = | 507 Iterable<int> metadataIndices = |
| 508 annotations.map((MetadataAnnotation a) { | 508 annotations.map((MetadataAnnotation annotation) { |
| 509 compiler.constantHandler.addCompileTimeConstantForEmission(a.value); | 509 Constant constant = |
| 510 return task.metadataEmitter.reifyMetadata(a); | 510 backend.constants.getConstantForMetadata(annotation); |
| 511 backend.constants.addCompileTimeConstantForEmission(constant); |
| 512 return task.metadataEmitter.reifyMetadata(annotation); |
| 511 }); | 513 }); |
| 512 expressions.add(metadataIndices.isNotEmpty ? metadataIndices.toList() | 514 expressions.add(metadataIndices.isNotEmpty ? metadataIndices.toList() |
| 513 : js('[]')); | 515 : js('[]')); |
| 514 } | 516 } |
| 515 }); | 517 }); |
| 516 } | 518 } |
| 517 if (canBeReflected) { | 519 if (canBeReflected) { |
| 518 jsAst.LiteralString reflectionName; | 520 jsAst.LiteralString reflectionName; |
| 519 if (member.isConstructor()) { | 521 if (member.isConstructor()) { |
| 520 String reflectionNameString = task.getReflectionName(member, name); | 522 String reflectionNameString = task.getReflectionName(member, name); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 531 expressions.add(js.string(member.name)); | 533 expressions.add(js.string(member.name)); |
| 532 } | 534 } |
| 533 | 535 |
| 534 builder.addProperty(name, js.toExpression(expressions)); | 536 builder.addProperty(name, js.toExpression(expressions)); |
| 535 } | 537 } |
| 536 | 538 |
| 537 void addMemberField(VariableElement member, ClassBuilder builder) { | 539 void addMemberField(VariableElement member, ClassBuilder builder) { |
| 538 // For now, do nothing. | 540 // For now, do nothing. |
| 539 } | 541 } |
| 540 } | 542 } |
| OLD | NEW |