Add javascript compatibility warnings for integer values and integral double

values that are not identical, but equal.

R=srdjan@google.com

Review URL: https://codereview.chromium.org//317793003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@37017 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
regis@google.com 2014-06-04 23:14:03 +00:00
parent 9bd9f2a479
commit eef5589182
3 changed files with 89 additions and 39 deletions

View file

@ -38,8 +38,30 @@ DEFINE_NATIVE_ENTRY(Identical_comparison, 2) {
GET_NATIVE_ARGUMENT(Instance, b, arguments->NativeArgAt(1));
const bool is_identical = a.IsIdenticalTo(b);
if (FLAG_warn_on_javascript_compatibility) {
if (!is_identical && a.IsString() && String::Cast(a).Equals(b)) {
JSWarning("strings that are equal are also identical");
if (!is_identical) {
if (a.IsString()) {
if (String::Cast(a).Equals(b)) {
JSWarning("strings that are equal are also identical");
}
} else if (a.IsInteger()) {
if (b.IsDouble()) {
const int64_t a_value = Integer::Cast(a).AsInt64Value();
const double b_value = Double::Cast(b).value();
if (a_value == floor(b_value)) {
JSWarning("integer value and integral double value that are equal "
"are also identical");
}
}
} else if (a.IsDouble()) {
if (b.IsInteger()) {
const double a_value = Double::Cast(a).value();
const int64_t b_value = Integer::Cast(b).AsInt64Value();
if (floor(a_value) == b_value) {
JSWarning("integral double value and integer value that are equal "
"are also identical");
}
}
}
}
}
return Bool::Get(is_identical).raw();

View file

@ -7,7 +7,7 @@
import "package:expect/expect.dart";
f(x, y) {
// Unoptimized code.
// Unoptimized and optimized code.
1 is double; /// 00: compile-time error
if (1 is double) { x++; } /// 01: compile-time error
try { 1 as double; } on CastError catch (e) { } /// 02: compile-time error
@ -40,35 +40,41 @@ f(x, y) {
b = b.substring(1);
if (identical(a, b)) { } /// 28: ok
if (identical(x, y)) { } /// 29: ok
if (identical(y, x)) { } /// 30: ok
if (x > 10) {
// Optimized code.
x is double; /// 30: ok
if (x is double) { } /// 31: ok
try { x as double; } on CastError catch (e) { } /// 32: ok
try { var z = x as double; } on CastError catch (e) { } /// 33: ok
y is int; /// 34: ok
if (y is int) { } /// 35: ok
try { y as int; } on CastError catch (e) { } /// 36: ok
try { var z = y as int; } on CastError catch (e) { } /// 37: ok
x is double; /// 40: ok
if (x is double) { } /// 41: ok
try { x as double; } on CastError catch (e) { } /// 42: ok
try { var z = x as double; } on CastError catch (e) { } /// 43: ok
y is int; /// 44: ok
if (y is int) { } /// 45: ok
try { y as int; } on CastError catch (e) { } /// 46: ok
try { var z = y as int; } on CastError catch (e) { } /// 47: ok
"${1.0}"; /// 40: compile-time error
var z = "${1.0}"; /// 41: compile-time error
(1.0).toString(); /// 42: ok
var z = (1.0).toString(); /// 43: ok
"$y"; /// 44: ok
var z = "$y"; /// 45: ok
y.toString(); /// 46: ok
var z = y.toString(); /// 47: ok
"${1.0}"; /// 50: compile-time error
var z = "${1.0}"; /// 51: compile-time error
(1.0).toString(); /// 52: ok
var z = (1.0).toString(); /// 53: ok
"$y"; /// 54: ok
var z = "$y"; /// 55: ok
y.toString(); /// 56: ok
var z = y.toString(); /// 57: ok
var a = "yz";
var b = "xyz";
b = b.substring(1);
if (identical(a, b)) { } /// 48: ok
if (identical(a, b)) { } /// 58: ok
if (identical(x, y)) { } /// 59: ok
if (identical(y, x)) { } /// 60: ok
}
}
k(x, y) {
// Unoptimized code.
// Unoptimized and optimized code.
1.5 is double;
if (1.5 is double) { x++; }
try { 1.5 as double; } on CastError catch (e) { }
@ -105,6 +111,14 @@ k(x, y) {
y.toString();
z = y.toString();
var a = "xyz";
var b = "xyz";
b = b.substring(1);
if (identical(a, b)) { }
if (identical(x, y)) { }
if (identical(y, x)) { }
if (x > 10) {
// Optimized code.
x is double;
@ -124,6 +138,14 @@ k(x, y) {
z = "$y";
y.toString();
z = y.toString();
var a = "xyz";
var b = "xyz";
b = b.substring(1);
if (identical(a, b)) { }
if (identical(x, y)) { }
if (identical(y, x)) { }
}
}

View file

@ -7,7 +7,7 @@
import "package:expect/expect.dart";
f(x, y) {
// Unoptimized code.
// Unoptimized and optimized code.
1 is double; /// 00: ok
if (1 is double) { x++; } /// 01: ok
try { 1 as double; } on CastError catch (e) { } /// 02: ok
@ -40,30 +40,36 @@ f(x, y) {
b = b.substring(1);
if (identical(a, b)) { } /// 28: ok
if (identical(x, y)) { } /// 29: ok
if (identical(y, x)) { } /// 30: ok
if (x > 10) {
// Optimized code.
x is double; /// 30: ok
if (x is double) { } /// 31: ok
try { x as double; } on CastError catch (e) { } /// 32: ok
try { var z = x as double; } on CastError catch (e) { } /// 33: ok
y is int; /// 34: ok
if (y is int) { } /// 35: ok
try { y as int; } on CastError catch (e) { } /// 36: ok
try { var z = y as int; } on CastError catch (e) { } /// 37: ok
x is double; /// 40: ok
if (x is double) { } /// 41: ok
try { x as double; } on CastError catch (e) { } /// 42: ok
try { var z = x as double; } on CastError catch (e) { } /// 43: ok
y is int; /// 44: ok
if (y is int) { } /// 45: ok
try { y as int; } on CastError catch (e) { } /// 46: ok
try { var z = y as int; } on CastError catch (e) { } /// 47: ok
"${1.0}"; /// 40: ok
var z = "${1.0}"; /// 41: ok
(1.0).toString(); /// 42: ok
var z = (1.0).toString(); /// 43: ok
"$y"; /// 44: ok
var z = "$y"; /// 45: ok
y.toString(); /// 46: ok
var z = y.toString(); /// 47: ok
"${1.0}"; /// 50: ok
var z = "${1.0}"; /// 51: ok
(1.0).toString(); /// 52: ok
var z = (1.0).toString(); /// 53: ok
"$y"; /// 54: ok
var z = "$y"; /// 55: ok
y.toString(); /// 56: ok
var z = y.toString(); /// 57: ok
var a = "yz";
var b = "xyz";
b = b.substring(1);
if (identical(a, b)) { } /// 48: ok
if (identical(a, b)) { } /// 58: ok
if (identical(x, y)) { } /// 59: ok
if (identical(y, x)) { } /// 60: ok
}
}