Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/code_patcher.h" | 8 #include "vm/code_patcher.h" |
| 9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
| 10 #include "vm/heap.h" | 10 #include "vm/heap.h" |
| 11 #include "vm/native_entry.h" | 11 #include "vm/native_entry.h" |
| 12 #include "vm/object.h" | 12 #include "vm/object.h" |
| 13 #include "vm/report.h" | |
| 13 #include "vm/stack_frame.h" | 14 #include "vm/stack_frame.h" |
| 14 #include "vm/symbols.h" | 15 #include "vm/symbols.h" |
| 15 | 16 |
| 16 namespace dart { | 17 namespace dart { |
| 17 | 18 |
| 18 DECLARE_FLAG(bool, enable_type_checks); | 19 DECLARE_FLAG(bool, enable_type_checks); |
| 19 DECLARE_FLAG(bool, trace_type_checks); | 20 DECLARE_FLAG(bool, trace_type_checks); |
| 20 DECLARE_FLAG(bool, warn_on_javascript_compatibility); | 21 DECLARE_FLAG(bool, warn_on_javascript_compatibility); |
| 21 | 22 |
| 22 | 23 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 | 105 |
| 105 | 106 |
| 106 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { | 107 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { |
| 107 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 108 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
| 108 // Special handling for following types outside this native. | 109 // Special handling for following types outside this native. |
| 109 ASSERT(!instance.IsString() && !instance.IsInteger() && !instance.IsDouble()); | 110 ASSERT(!instance.IsString() && !instance.IsInteger() && !instance.IsDouble()); |
| 110 return instance.GetType(); | 111 return instance.GetType(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 | 114 |
| 114 static void JSWarning(const char* msg) { | |
| 115 DartFrameIterator iterator; | |
| 116 iterator.NextFrame(); // Skip native call. | |
| 117 StackFrame* caller_frame = iterator.NextFrame(); | |
| 118 ASSERT(caller_frame != NULL); | |
| 119 const Code& caller_code = Code::Handle(caller_frame->LookupDartCode()); | |
| 120 ASSERT(!caller_code.IsNull()); | |
| 121 const uword caller_pc = caller_frame->pc(); | |
| 122 // Assume an instance call. | |
| 123 ICData& ic_data = ICData::Handle(); | |
| 124 CodePatcher::GetInstanceCallAt(caller_pc, caller_code, &ic_data); | |
| 125 ASSERT(!ic_data.IsNull()); | |
| 126 // Report warning only if not already reported at this location. | |
| 127 if (!ic_data.IssuedJSWarning()) { | |
| 128 ic_data.SetIssuedJSWarning(); | |
| 129 Exceptions::JSWarning(caller_frame, "%s", msg); | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 | |
| 134 static void WarnOnJSIntegralNumTypeTest( | 115 static void WarnOnJSIntegralNumTypeTest( |
| 135 const Instance& instance, | 116 const Instance& instance, |
| 136 const TypeArguments& instantiator_type_arguments, | 117 const TypeArguments& instantiator_type_arguments, |
| 137 const AbstractType& type) { | 118 const AbstractType& type) { |
| 138 const bool instance_is_int = instance.IsInteger(); | 119 const bool instance_is_int = instance.IsInteger(); |
| 139 const bool instance_is_double = instance.IsDouble(); | 120 const bool instance_is_double = instance.IsDouble(); |
| 121 const bool is_static_native = false; // Object_instanceOf and Object_as are | |
| 122 // not static native calls. | |
| 140 if (!(instance_is_int || instance_is_double)) { | 123 if (!(instance_is_int || instance_is_double)) { |
| 141 return; | 124 return; |
| 142 } | 125 } |
| 143 AbstractType& instantiated_type = AbstractType::Handle(type.raw()); | 126 AbstractType& instantiated_type = AbstractType::Handle(type.raw()); |
| 144 if (!type.IsInstantiated()) { | 127 if (!type.IsInstantiated()) { |
| 145 instantiated_type = type.InstantiateFrom(instantiator_type_arguments, NULL); | 128 instantiated_type = type.InstantiateFrom(instantiator_type_arguments, NULL); |
| 146 } | 129 } |
| 147 if (instance_is_double) { | 130 if (instance_is_double) { |
| 148 if (instantiated_type.IsIntType()) { | 131 if (instantiated_type.IsIntType()) { |
| 149 const double value = Double::Cast(instance).value(); | 132 const double value = Double::Cast(instance).value(); |
| 150 if (floor(value) == value) { | 133 if (floor(value) == value) { |
| 151 JSWarning("integral value of type 'double' is also considered to be " | 134 Report::JSWarningFromNative(is_static_native, |
|
hausner
2014/06/18 21:48:53
As discussed offline, I prefer passing false as a
regis
2014/06/18 22:13:28
Done.
| |
| 152 "of type 'int'"); | 135 "integral value of type 'double' is also considered to be " |
| 136 "of type 'int'"); | |
| 153 } | 137 } |
| 154 } | 138 } |
| 155 } else { | 139 } else { |
| 156 ASSERT(instance_is_int); | 140 ASSERT(instance_is_int); |
| 157 if (instantiated_type.IsDoubleType()) { | 141 if (instantiated_type.IsDoubleType()) { |
| 158 JSWarning("integer value is also considered to be of type 'double'"); | 142 Report::JSWarningFromNative(is_static_native, |
| 143 "integer value is also considered to be of type 'double'"); | |
| 159 } | 144 } |
| 160 } | 145 } |
| 161 } | 146 } |
| 162 | 147 |
| 163 | 148 |
| 164 DEFINE_NATIVE_ENTRY(Object_instanceOf, 5) { | 149 DEFINE_NATIVE_ENTRY(Object_instanceOf, 5) { |
| 165 const Instance& instance = | 150 const Instance& instance = |
| 166 Instance::CheckedHandle(isolate, arguments->NativeArgAt(0)); | 151 Instance::CheckedHandle(isolate, arguments->NativeArgAt(0)); |
| 167 // Instantiator at position 1 is not used. It is passed along so that the call | 152 // Instantiator at position 1 is not used. It is passed along so that the call |
| 168 // can be easily converted to an optimized implementation. Instantiator is | 153 // can be easily converted to an optimized implementation. Instantiator is |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 | 290 |
| 306 | 291 |
| 307 DEFINE_NATIVE_ENTRY(LibraryPrefix_load, 1) { | 292 DEFINE_NATIVE_ENTRY(LibraryPrefix_load, 1) { |
| 308 const LibraryPrefix& prefix = | 293 const LibraryPrefix& prefix = |
| 309 LibraryPrefix::CheckedHandle(arguments->NativeArgAt(0)); | 294 LibraryPrefix::CheckedHandle(arguments->NativeArgAt(0)); |
| 310 bool hasCompleted = prefix.LoadLibrary(); | 295 bool hasCompleted = prefix.LoadLibrary(); |
| 311 return Bool::Get(hasCompleted).raw(); | 296 return Bool::Get(hasCompleted).raw(); |
| 312 } | 297 } |
| 313 | 298 |
| 314 } // namespace dart | 299 } // namespace dart |
| OLD | NEW |