| 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/report.h" |
| 14 #include "vm/stack_frame.h" | 14 #include "vm/stack_frame.h" |
| 15 #include "vm/symbols.h" | 15 #include "vm/symbols.h" |
| 16 | 16 |
| 17 namespace dart { | 17 namespace dart { |
| 18 | 18 |
| 19 DECLARE_FLAG(bool, trace_type_checks); | 19 DECLARE_FLAG(bool, trace_type_checks); |
| 20 DECLARE_FLAG(bool, warn_on_javascript_compatibility); | |
| 21 | 20 |
| 22 // Helper function in stacktrace.cc. | 21 // Helper function in stacktrace.cc. |
| 23 void _printCurrentStacktrace(); | 22 void _printCurrentStacktrace(); |
| 24 | 23 |
| 25 DEFINE_NATIVE_ENTRY(DartCore_fatal, 1) { | 24 DEFINE_NATIVE_ENTRY(DartCore_fatal, 1) { |
| 26 // The core library code entered an unrecoverable state. | 25 // The core library code entered an unrecoverable state. |
| 27 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 26 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
| 28 const char* msg = instance.ToCString(); | 27 const char* msg = instance.ToCString(); |
| 29 OS::PrintErr("Fatal error in dart:core\n"); | 28 OS::PrintErr("Fatal error in dart:core\n"); |
| 30 _printCurrentStacktrace(); | 29 _printCurrentStacktrace(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 113 |
| 115 | 114 |
| 116 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { | 115 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { |
| 117 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 116 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
| 118 // Special handling for following types outside this native. | 117 // Special handling for following types outside this native. |
| 119 ASSERT(!instance.IsString() && !instance.IsInteger() && !instance.IsDouble()); | 118 ASSERT(!instance.IsString() && !instance.IsInteger() && !instance.IsDouble()); |
| 120 return instance.GetType(); | 119 return instance.GetType(); |
| 121 } | 120 } |
| 122 | 121 |
| 123 | 122 |
| 124 static void WarnOnJSIntegralNumTypeTest( | |
| 125 const Instance& instance, | |
| 126 const TypeArguments& instantiator_type_arguments, | |
| 127 const AbstractType& type) { | |
| 128 const bool instance_is_int = instance.IsInteger(); | |
| 129 const bool instance_is_double = instance.IsDouble(); | |
| 130 if (!(instance_is_int || instance_is_double)) { | |
| 131 return; | |
| 132 } | |
| 133 AbstractType& instantiated_type = AbstractType::Handle(type.raw()); | |
| 134 if (!type.IsInstantiated()) { | |
| 135 instantiated_type = type.InstantiateFrom(instantiator_type_arguments, NULL); | |
| 136 } | |
| 137 if (instance_is_double) { | |
| 138 if (instantiated_type.IsIntType()) { | |
| 139 const double value = Double::Cast(instance).value(); | |
| 140 if (floor(value) == value) { | |
| 141 Report::JSWarningFromNative( | |
| 142 false, // Object_instanceOf and Object_as are not static calls. | |
| 143 "integral value of type 'double' is also considered to be " | |
| 144 "of type 'int'"); | |
| 145 } | |
| 146 } | |
| 147 } else { | |
| 148 ASSERT(instance_is_int); | |
| 149 if (instantiated_type.IsDoubleType()) { | |
| 150 Report::JSWarningFromNative( | |
| 151 false, // Object_instanceOf and Object_as are not static calls. | |
| 152 "integer value is also considered to be of type 'double'"); | |
| 153 } | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 | |
| 158 DEFINE_NATIVE_ENTRY(Object_instanceOf, 4) { | 123 DEFINE_NATIVE_ENTRY(Object_instanceOf, 4) { |
| 159 const Instance& instance = | 124 const Instance& instance = |
| 160 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); | 125 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); |
| 161 const TypeArguments& instantiator_type_arguments = | 126 const TypeArguments& instantiator_type_arguments = |
| 162 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); | 127 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); |
| 163 const AbstractType& type = | 128 const AbstractType& type = |
| 164 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); | 129 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); |
| 165 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(3)); | 130 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(3)); |
| 166 ASSERT(type.IsFinalized()); | 131 ASSERT(type.IsFinalized()); |
| 167 ASSERT(!type.IsMalformed()); | 132 ASSERT(!type.IsMalformed()); |
| 168 ASSERT(!type.IsMalbounded()); | 133 ASSERT(!type.IsMalbounded()); |
| 169 | |
| 170 // Check for javascript compatibility. | |
| 171 if (FLAG_warn_on_javascript_compatibility) { | |
| 172 WarnOnJSIntegralNumTypeTest(instance, instantiator_type_arguments, type); | |
| 173 } | |
| 174 | |
| 175 Error& bound_error = Error::Handle(zone, Error::null()); | 134 Error& bound_error = Error::Handle(zone, Error::null()); |
| 176 const bool is_instance_of = instance.IsInstanceOf(type, | 135 const bool is_instance_of = instance.IsInstanceOf(type, |
| 177 instantiator_type_arguments, | 136 instantiator_type_arguments, |
| 178 &bound_error); | 137 &bound_error); |
| 179 if (FLAG_trace_type_checks) { | 138 if (FLAG_trace_type_checks) { |
| 180 const char* result_str = is_instance_of ? "true" : "false"; | 139 const char* result_str = is_instance_of ? "true" : "false"; |
| 181 OS::Print("Native Object.instanceOf: result %s\n", result_str); | 140 OS::Print("Native Object.instanceOf: result %s\n", result_str); |
| 182 const AbstractType& instance_type = | 141 const AbstractType& instance_type = |
| 183 AbstractType::Handle(instance.GetType()); | 142 AbstractType::Handle(instance.GetType()); |
| 184 OS::Print(" instance type: %s\n", | 143 OS::Print(" instance type: %s\n", |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 TypeArguments::CheckedHandle(arguments->NativeArgAt(1)); | 230 TypeArguments::CheckedHandle(arguments->NativeArgAt(1)); |
| 272 const AbstractType& type = | 231 const AbstractType& type = |
| 273 AbstractType::CheckedHandle(arguments->NativeArgAt(2)); | 232 AbstractType::CheckedHandle(arguments->NativeArgAt(2)); |
| 274 ASSERT(type.IsFinalized()); | 233 ASSERT(type.IsFinalized()); |
| 275 ASSERT(!type.IsMalformed()); | 234 ASSERT(!type.IsMalformed()); |
| 276 ASSERT(!type.IsMalbounded()); | 235 ASSERT(!type.IsMalbounded()); |
| 277 Error& bound_error = Error::Handle(); | 236 Error& bound_error = Error::Handle(); |
| 278 if (instance.IsNull()) { | 237 if (instance.IsNull()) { |
| 279 return instance.raw(); | 238 return instance.raw(); |
| 280 } | 239 } |
| 281 | |
| 282 // Check for javascript compatibility. | |
| 283 if (FLAG_warn_on_javascript_compatibility) { | |
| 284 WarnOnJSIntegralNumTypeTest(instance, instantiator_type_arguments, type); | |
| 285 } | |
| 286 | |
| 287 const bool is_instance_of = instance.IsInstanceOf(type, | 240 const bool is_instance_of = instance.IsInstanceOf(type, |
| 288 instantiator_type_arguments, | 241 instantiator_type_arguments, |
| 289 &bound_error); | 242 &bound_error); |
| 290 if (FLAG_trace_type_checks) { | 243 if (FLAG_trace_type_checks) { |
| 291 const char* result_str = is_instance_of ? "true" : "false"; | 244 const char* result_str = is_instance_of ? "true" : "false"; |
| 292 OS::Print("Object.as: result %s\n", result_str); | 245 OS::Print("Object.as: result %s\n", result_str); |
| 293 const AbstractType& instance_type = | 246 const AbstractType& instance_type = |
| 294 AbstractType::Handle(instance.GetType()); | 247 AbstractType::Handle(instance.GetType()); |
| 295 OS::Print(" instance type: %s\n", | 248 OS::Print(" instance type: %s\n", |
| 296 String::Handle(instance_type.Name()).ToCString()); | 249 String::Handle(instance_type.Name()).ToCString()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 336 |
| 384 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { | 337 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { |
| 385 #if defined(ARCH_IS_64_BIT) | 338 #if defined(ARCH_IS_64_BIT) |
| 386 return Bool::True().raw(); | 339 return Bool::True().raw(); |
| 387 #else | 340 #else |
| 388 return Bool::False().raw(); | 341 return Bool::False().raw(); |
| 389 #endif // defined(ARCH_IS_64_BIT) | 342 #endif // defined(ARCH_IS_64_BIT) |
| 390 } | 343 } |
| 391 | 344 |
| 392 } // namespace dart | 345 } // namespace dart |
| OLD | NEW |