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" |
7 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/stack_frame.h" |
8 | 11 |
9 namespace dart { | 12 namespace dart { |
10 | 13 |
| 14 DECLARE_FLAG(bool, warn_on_javascript_compatibility); |
| 15 |
| 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 |
11 DEFINE_NATIVE_ENTRY(Identical_comparison, 2) { | 36 DEFINE_NATIVE_ENTRY(Identical_comparison, 2) { |
12 GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0)); | 37 GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0)); |
13 GET_NATIVE_ARGUMENT(Instance, b, arguments->NativeArgAt(1)); | 38 GET_NATIVE_ARGUMENT(Instance, b, arguments->NativeArgAt(1)); |
14 return Bool::Get(a.IsIdenticalTo(b)).raw(); | 39 const bool is_identical = a.IsIdenticalTo(b); |
| 40 if (FLAG_warn_on_javascript_compatibility) { |
| 41 if (!is_identical && a.IsString() && String::Cast(a).Equals(b)) { |
| 42 JSWarning("strings that are equal are also identical"); |
| 43 } |
| 44 } |
| 45 return Bool::Get(is_identical).raw(); |
15 } | 46 } |
16 | 47 |
17 } // namespace dart | 48 } // namespace dart |
OLD | NEW |