| 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 class Constant implements Hashable { | 5 class Constant implements Hashable { |
| 6 const Constant(); | 6 const Constant(); |
| 7 | 7 |
| 8 bool isNull() => false; | 8 bool isNull() => false; |
| 9 bool isBool() => false; | 9 bool isBool() => false; |
| 10 bool isTrue() => false; | 10 bool isTrue() => false; |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 "Compiler and ConstantMap disagree on number of fields."); | 349 "Compiler and ConstantMap disagree on number of fields."); |
| 350 } | 350 } |
| 351 | 351 |
| 352 ClassElement classElement = type.element; | 352 ClassElement classElement = type.element; |
| 353 buffer.add("new "); | 353 buffer.add("new "); |
| 354 buffer.add(handler.getJsConstructor(classElement)); | 354 buffer.add(handler.getJsConstructor(classElement)); |
| 355 buffer.add("("); | 355 buffer.add("("); |
| 356 // The arguments of the JavaScript constructor for any given Dart class | 356 // The arguments of the JavaScript constructor for any given Dart class |
| 357 // are in the same order as the members of the class element. | 357 // are in the same order as the members of the class element. |
| 358 int emittedArgumentCount = 0; | 358 int emittedArgumentCount = 0; |
| 359 for (Element element in classElement.members) { | 359 classElement.forEachInstanceField( |
| 360 if (element.name == LENGTH_NAME) { | 360 includeBackendMembers: true, |
| 361 includeSuperMembers: true, |
| 362 f: (ClassElement enclosing, Element field) { |
| 363 if (emittedArgumentCount != 0) buffer.add(", "); |
| 364 if (field.name == LENGTH_NAME) { |
| 361 buffer.add(keys.entries.length); | 365 buffer.add(keys.entries.length); |
| 362 } else if (element.name == JS_OBJECT_NAME) { | 366 } else if (field.name == JS_OBJECT_NAME) { |
| 363 writeJsMap(); | 367 writeJsMap(); |
| 364 } else if (element.name == KEYS_NAME) { | 368 } else if (field.name == KEYS_NAME) { |
| 365 keys.writeCanonicalizedJsCode(buffer, handler); | 369 keys.writeCanonicalizedJsCode(buffer, handler); |
| 366 } else { | 370 } else { |
| 367 // Skip methods. | 371 badFieldCountError(); |
| 368 if (element.kind == ElementKind.FIELD) badFieldCountError(); | |
| 369 continue; | |
| 370 } | 372 } |
| 371 emittedArgumentCount++; | 373 emittedArgumentCount++; |
| 372 if (emittedArgumentCount == 3) { | 374 }); |
| 373 break; // All arguments have been emitted. | |
| 374 } else { | |
| 375 buffer.add(", "); | |
| 376 } | |
| 377 } | |
| 378 if (emittedArgumentCount != 3) badFieldCountError(); | 375 if (emittedArgumentCount != 3) badFieldCountError(); |
| 379 buffer.add(")"); | 376 buffer.add(")"); |
| 380 } | 377 } |
| 381 | 378 |
| 382 bool operator ==(var other) { | 379 bool operator ==(var other) { |
| 383 if (other is !MapConstant) return false; | 380 if (other is !MapConstant) return false; |
| 384 MapConstant otherMap = other; | 381 MapConstant otherMap = other; |
| 385 if (hashCode() != otherMap.hashCode()) return false; | 382 if (hashCode() != otherMap.hashCode()) return false; |
| 386 // TODO(floitsch): verify that the generic types are the same. | 383 // TODO(floitsch): verify that the generic types are the same. |
| 387 if (keys != otherMap.keys) return false; | 384 if (keys != otherMap.keys) return false; |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 */ | 1084 */ |
| 1088 void evaluateConstructorFieldValues(List<Constant> arguments) { | 1085 void evaluateConstructorFieldValues(List<Constant> arguments) { |
| 1089 compiler.withCurrentElement(constructor, () { | 1086 compiler.withCurrentElement(constructor, () { |
| 1090 assignArgumentsToParameters(arguments); | 1087 assignArgumentsToParameters(arguments); |
| 1091 evaluateConstructorInitializers(); | 1088 evaluateConstructorInitializers(); |
| 1092 }); | 1089 }); |
| 1093 } | 1090 } |
| 1094 | 1091 |
| 1095 List<Constant> buildJsNewArguments(ClassElement classElement) { | 1092 List<Constant> buildJsNewArguments(ClassElement classElement) { |
| 1096 List<Constant> jsNewArguments = <Constant>[]; | 1093 List<Constant> jsNewArguments = <Constant>[]; |
| 1097 // TODO(floitsch): share this code with the emitter, so that we don't | 1094 classElement.forEachInstanceField( |
| 1098 // need to care about the order of fields here. | 1095 includeBackendMembers: true, |
| 1099 while (classElement != compiler.objectClass) { | 1096 includeSuperMembers: true, |
| 1100 for (Element member in classElement.members) { | 1097 f: (ClassElement enclosing, Element field) { |
| 1101 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { | 1098 Constant fieldValue = fieldValues[field]; |
| 1102 Constant fieldValue = fieldValues[member]; | 1099 if (fieldValue === null) { |
| 1103 if (fieldValue === null) { | 1100 // Use the default value. |
| 1104 // Use the default value. | 1101 fieldValue = compiler.compileVariable(field); |
| 1105 fieldValue = compiler.compileVariable(member); | |
| 1106 } | |
| 1107 jsNewArguments.add(fieldValue); | |
| 1108 } | |
| 1109 } | 1102 } |
| 1110 classElement = classElement.superclass; | 1103 jsNewArguments.add(fieldValue); |
| 1111 } | 1104 }); |
| 1112 return jsNewArguments; | 1105 return jsNewArguments; |
| 1113 } | 1106 } |
| 1114 } | 1107 } |
| OLD | NEW |