| 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 library dart2js.constant_system.js; | 5 library dart2js.constant_system.js; |
| 6 | 6 |
| 7 import '../compiler.dart' show Compiler; | 7 import '../compiler.dart' show Compiler; |
| 8 import '../constant_system_dart.dart'; | 8 import '../constant_system_dart.dart'; |
| 9 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
| 10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 NullConstantValue createNull() => new NullConstantValue(); | 313 NullConstantValue createNull() => new NullConstantValue(); |
| 314 | 314 |
| 315 @override | 315 @override |
| 316 ListConstantValue createList( | 316 ListConstantValue createList( |
| 317 ResolutionInterfaceType type, List<ConstantValue> values) { | 317 ResolutionInterfaceType type, List<ConstantValue> values) { |
| 318 return new ListConstantValue(type, values); | 318 return new ListConstantValue(type, values); |
| 319 } | 319 } |
| 320 | 320 |
| 321 @override | 321 @override |
| 322 ConstantValue createType(Compiler compiler, ResolutionDartType type) { | 322 ConstantValue createType(Compiler compiler, ResolutionDartType type) { |
| 323 return new TypeConstantValue( | 323 ResolutionInterfaceType instanceType = compiler |
| 324 type, | 324 .backend.backendClasses.typeImplementation |
| 325 compiler.backend.backendClasses.typeImplementation | 325 .computeType(compiler.resolution); |
| 326 .computeType(compiler.resolution)); | 326 return new TypeConstantValue(type, instanceType); |
| 327 } | 327 } |
| 328 | 328 |
| 329 // Integer checks report true for -0.0, INFINITY, and -INFINITY. At | 329 // Integer checks report true for -0.0, INFINITY, and -INFINITY. At |
| 330 // runtime an 'X is int' check is implemented as: | 330 // runtime an 'X is int' check is implemented as: |
| 331 // | 331 // |
| 332 // typeof(X) === "number" && Math.floor(X) === X | 332 // typeof(X) === "number" && Math.floor(X) === X |
| 333 // | 333 // |
| 334 // We consistently match that runtime semantics at compile time as well. | 334 // We consistently match that runtime semantics at compile time as well. |
| 335 bool isInt(ConstantValue constant) { | 335 bool isInt(ConstantValue constant) { |
| 336 return constant.isInt || | 336 return constant.isInt || |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 } | 375 } |
| 376 } else { | 376 } else { |
| 377 onlyStringKeys = false; | 377 onlyStringKeys = false; |
| 378 // Don't handle __proto__ values specially in the general map case. | 378 // Don't handle __proto__ values specially in the general map case. |
| 379 protoValue = null; | 379 protoValue = null; |
| 380 break; | 380 break; |
| 381 } | 381 } |
| 382 } | 382 } |
| 383 | 383 |
| 384 bool hasProtoKey = (protoValue != null); | 384 bool hasProtoKey = (protoValue != null); |
| 385 ResolutionDartType keysType; | 385 ResolutionInterfaceType keysType; |
| 386 if (sourceType.treatAsRaw) { | 386 if (sourceType.treatAsRaw) { |
| 387 keysType = commonElements.listType(); | 387 keysType = commonElements.listType(); |
| 388 } else { | 388 } else { |
| 389 keysType = commonElements.listType(sourceType.typeArguments.first); | 389 keysType = commonElements.listType(sourceType.typeArguments.first); |
| 390 } | 390 } |
| 391 ListConstantValue keysList = new ListConstantValue(keysType, keys); | 391 ListConstantValue keysList = new ListConstantValue(keysType, keys); |
| 392 ClassElement classElement = onlyStringKeys | 392 ClassElement classElement = onlyStringKeys |
| 393 ? (hasProtoKey | 393 ? (hasProtoKey |
| 394 ? backend.helpers.constantProtoMapClass | 394 ? backend.helpers.constantProtoMapClass |
| 395 : backend.helpers.constantStringMapClass) | 395 : backend.helpers.constantStringMapClass) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 result.add(keyList); | 458 result.add(keyList); |
| 459 } else { | 459 } else { |
| 460 // Add the keys individually to avoid generating an unused list constant | 460 // Add the keys individually to avoid generating an unused list constant |
| 461 // for the keys. | 461 // for the keys. |
| 462 result.addAll(keys); | 462 result.addAll(keys); |
| 463 } | 463 } |
| 464 result.addAll(values); | 464 result.addAll(values); |
| 465 return result; | 465 return result; |
| 466 } | 466 } |
| 467 } | 467 } |
| OLD | NEW |