| 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/code_patcher.h" | |
| 8 #include "vm/exceptions.h" | |
| 9 #include "vm/object.h" | 7 #include "vm/object.h" |
| 10 #include "vm/stack_frame.h" | 8 #include "vm/report.h" |
| 11 | 9 |
| 12 namespace dart { | 10 namespace dart { |
| 13 | 11 |
| 14 DECLARE_FLAG(bool, warn_on_javascript_compatibility); | 12 DECLARE_FLAG(bool, warn_on_javascript_compatibility); |
| 15 | 13 |
| 16 static void JSWarning(const char* msg) { | |
| 17 DartFrameIterator iterator; | |
| 18 iterator.NextFrame(); // Skip native call. | |
| 19 StackFrame* caller_frame = iterator.NextFrame(); | |
| 20 ASSERT(caller_frame != NULL); | |
| 21 const Code& caller_code = Code::Handle(caller_frame->LookupDartCode()); | |
| 22 ASSERT(!caller_code.IsNull()); | |
| 23 const uword caller_pc = caller_frame->pc(); | |
| 24 // Assume an unoptimized static call. Optimization was prevented. | |
| 25 ICData& ic_data = ICData::Handle(); | |
| 26 CodePatcher::GetUnoptimizedStaticCallAt(caller_pc, caller_code, &ic_data); | |
| 27 ASSERT(!ic_data.IsNull()); | |
| 28 // Report warning only if not already reported at this location. | |
| 29 if (!ic_data.IssuedJSWarning()) { | |
| 30 ic_data.SetIssuedJSWarning(); | |
| 31 Exceptions::JSWarning(caller_frame, "%s", msg); | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 | |
| 36 DEFINE_NATIVE_ENTRY(Identical_comparison, 2) { | 14 DEFINE_NATIVE_ENTRY(Identical_comparison, 2) { |
| 37 GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0)); | 15 GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0)); |
| 38 GET_NATIVE_ARGUMENT(Instance, b, arguments->NativeArgAt(1)); | 16 GET_NATIVE_ARGUMENT(Instance, b, arguments->NativeArgAt(1)); |
| 39 const bool is_identical = a.IsIdenticalTo(b); | 17 const bool is_identical = a.IsIdenticalTo(b); |
| 40 if (FLAG_warn_on_javascript_compatibility) { | 18 if (FLAG_warn_on_javascript_compatibility) { |
| 41 if (!is_identical) { | 19 if (!is_identical) { |
| 42 if (a.IsString()) { | 20 if (a.IsString()) { |
| 43 if (String::Cast(a).Equals(b)) { | 21 if (String::Cast(a).Equals(b)) { |
| 44 JSWarning("strings that are equal are also identical"); | 22 Report::JSWarningFromNative( |
| 23 true, // Identical_comparison is static. |
| 24 "strings that are equal are also identical"); |
| 45 } | 25 } |
| 46 } else if (a.IsInteger()) { | 26 } else if (a.IsInteger()) { |
| 47 if (b.IsDouble()) { | 27 if (b.IsDouble()) { |
| 48 const int64_t a_value = Integer::Cast(a).AsInt64Value(); | 28 const int64_t a_value = Integer::Cast(a).AsInt64Value(); |
| 49 const double b_value = Double::Cast(b).value(); | 29 const double b_value = Double::Cast(b).value(); |
| 50 if (a_value == floor(b_value)) { | 30 if (a_value == floor(b_value)) { |
| 51 JSWarning("integer value and integral double value that are equal " | 31 Report::JSWarningFromNative( |
| 52 "are also identical"); | 32 true, // Identical_comparison is static. |
| 33 "integer value and integral double value that are equal " |
| 34 "are also identical"); |
| 53 } | 35 } |
| 54 } | 36 } |
| 55 } else if (a.IsDouble()) { | 37 } else if (a.IsDouble()) { |
| 56 if (b.IsInteger()) { | 38 if (b.IsInteger()) { |
| 57 const double a_value = Double::Cast(a).value(); | 39 const double a_value = Double::Cast(a).value(); |
| 58 const int64_t b_value = Integer::Cast(b).AsInt64Value(); | 40 const int64_t b_value = Integer::Cast(b).AsInt64Value(); |
| 59 if (floor(a_value) == b_value) { | 41 if (floor(a_value) == b_value) { |
| 60 JSWarning("integral double value and integer value that are equal " | 42 Report::JSWarningFromNative( |
| 61 "are also identical"); | 43 true, // Identical_comparison is static. |
| 44 "integral double value and integer value that are equal " |
| 45 "are also identical"); |
| 62 } | 46 } |
| 63 } | 47 } |
| 64 } | 48 } |
| 65 } | 49 } |
| 66 } | 50 } |
| 67 return Bool::Get(is_identical).raw(); | 51 return Bool::Get(is_identical).raw(); |
| 68 } | 52 } |
| 69 | 53 |
| 70 } // namespace dart | 54 } // namespace dart |
| OLD | NEW |