| 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 | 7 import '../compiler.dart' show |
| 8 Compiler; | 8 Compiler; |
| 9 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
| 10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 return new ListConstantValue(type, values); | 267 return new ListConstantValue(type, values); |
| 268 } | 268 } |
| 269 | 269 |
| 270 @override | 270 @override |
| 271 ConstantValue createType(Compiler compiler, DartType type) { | 271 ConstantValue createType(Compiler compiler, DartType type) { |
| 272 return new TypeConstantValue( | 272 return new TypeConstantValue( |
| 273 type, | 273 type, |
| 274 compiler.backend.typeImplementation.computeType(compiler.resolution)); | 274 compiler.backend.typeImplementation.computeType(compiler.resolution)); |
| 275 } | 275 } |
| 276 | 276 |
| 277 // Integer checks don't verify that the number is not -0.0. | 277 // Integer checks report true for -0.0, INFINITY, and -INFINITY. At |
| 278 bool isInt(ConstantValue constant) => constant.isInt || constant.isMinusZero; | 278 // runtime an 'X is int' check is implemented as: |
| 279 // |
| 280 // typeof(X) === "number" && Math.floor(X) === X |
| 281 // |
| 282 // We consistently match that runtime semantics at compile time as well. |
| 283 bool isInt(ConstantValue constant) { |
| 284 return constant.isInt || constant.isMinusZero || |
| 285 constant.isPositiveInfinity || |
| 286 constant.isNegativeInfinity; |
| 287 } |
| 279 bool isDouble(ConstantValue constant) | 288 bool isDouble(ConstantValue constant) |
| 280 => constant.isDouble && !constant.isMinusZero; | 289 => constant.isDouble && !constant.isMinusZero; |
| 281 bool isString(ConstantValue constant) => constant.isString; | 290 bool isString(ConstantValue constant) => constant.isString; |
| 282 bool isBool(ConstantValue constant) => constant.isBool; | 291 bool isBool(ConstantValue constant) => constant.isBool; |
| 283 bool isNull(ConstantValue constant) => constant.isNull; | 292 bool isNull(ConstantValue constant) => constant.isNull; |
| 284 | 293 |
| 285 bool isSubtype(DartTypes types, DartType s, DartType t) { | 294 bool isSubtype(DartTypes types, DartType s, DartType t) { |
| 286 // At runtime, an integer is both an integer and a double: the | 295 // At runtime, an integer is both an integer and a double: the |
| 287 // integer type check is Math.floor, which will return true only | 296 // integer type check is Math.floor, which will return true only |
| 288 // for real integers, and our double type check is 'typeof number' | 297 // for real integers, and our double type check is 'typeof number' |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 result.add(keyList); | 390 result.add(keyList); |
| 382 } else { | 391 } else { |
| 383 // Add the keys individually to avoid generating an unused list constant | 392 // Add the keys individually to avoid generating an unused list constant |
| 384 // for the keys. | 393 // for the keys. |
| 385 result.addAll(keys); | 394 result.addAll(keys); |
| 386 } | 395 } |
| 387 result.addAll(values); | 396 result.addAll(values); |
| 388 return result; | 397 return result; |
| 389 } | 398 } |
| 390 } | 399 } |
| OLD | NEW |