| 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 #include "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "vm/object.h" | 7 #include "vm/object.h" |
| 8 #include "vm/report.h" | 8 #include "vm/report.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 DECLARE_FLAG(bool, warn_on_javascript_compatibility); | |
| 13 | |
| 14 DEFINE_NATIVE_ENTRY(Identical_comparison, 2) { | 12 DEFINE_NATIVE_ENTRY(Identical_comparison, 2) { |
| 15 GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0)); | 13 GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0)); |
| 16 GET_NATIVE_ARGUMENT(Instance, b, arguments->NativeArgAt(1)); | 14 GET_NATIVE_ARGUMENT(Instance, b, arguments->NativeArgAt(1)); |
| 17 const bool is_identical = a.IsIdenticalTo(b); | 15 const bool is_identical = a.IsIdenticalTo(b); |
| 18 if (FLAG_warn_on_javascript_compatibility) { | |
| 19 if (!is_identical) { | |
| 20 if (a.IsString()) { | |
| 21 if (String::Cast(a).Equals(b)) { | |
| 22 Report::JSWarningFromNative( | |
| 23 true, // Identical_comparison is static. | |
| 24 "strings that are equal are also identical"); | |
| 25 } | |
| 26 } else if (a.IsInteger()) { | |
| 27 if (b.IsDouble()) { | |
| 28 const int64_t a_value = Integer::Cast(a).AsInt64Value(); | |
| 29 const double b_value = Double::Cast(b).value(); | |
| 30 if (a_value == floor(b_value)) { | |
| 31 Report::JSWarningFromNative( | |
| 32 true, // Identical_comparison is static. | |
| 33 "integer value and integral double value that are equal " | |
| 34 "are also identical"); | |
| 35 } | |
| 36 } | |
| 37 } else if (a.IsDouble()) { | |
| 38 if (b.IsInteger()) { | |
| 39 const double a_value = Double::Cast(a).value(); | |
| 40 const int64_t b_value = Integer::Cast(b).AsInt64Value(); | |
| 41 if (floor(a_value) == b_value) { | |
| 42 Report::JSWarningFromNative( | |
| 43 true, // Identical_comparison is static. | |
| 44 "integral double value and integer value that are equal " | |
| 45 "are also identical"); | |
| 46 } | |
| 47 } | |
| 48 } | |
| 49 } | |
| 50 } | |
| 51 return Bool::Get(is_identical).raw(); | 16 return Bool::Get(is_identical).raw(); |
| 52 } | 17 } |
| 53 | 18 |
| 54 } // namespace dart | 19 } // namespace dart |
| OLD | NEW |