| 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 "lib/error.h" | 5 #include "lib/error.h" |
| 6 | 6 |
| 7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.h" |
| 8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 #include "vm/runtime_entry.h" | 10 #include "vm/runtime_entry.h" |
| 11 #include "vm/stack_frame.h" | 11 #include "vm/stack_frame.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 DEFINE_FLAG(bool, trace_type_checks, false, "Trace runtime type checks."); |
| 15 DECLARE_FLAG(bool, print_stack_trace_at_throw); | 16 DECLARE_FLAG(bool, print_stack_trace_at_throw); |
| 16 | 17 |
| 17 | 18 |
| 18 // Static helpers for allocating, initializing, and throwing an error instance. | 19 // Static helpers for allocating, initializing, and throwing an error instance. |
| 19 | 20 |
| 20 // Return the script of the Dart function that called the native entry or the | 21 // Return the script of the Dart function that called the native entry or the |
| 21 // runtime entry. The frame iterator points to the callee. | 22 // runtime entry. The frame iterator points to the callee. |
| 22 static RawScript* GetCallerScript(DartFrameIterator* iterator) { | 23 static RawScript* GetCallerScript(DartFrameIterator* iterator) { |
| 23 DartFrame* caller_frame = iterator->NextFrame(); | 24 DartFrame* caller_frame = iterator->NextFrame(); |
| 24 ASSERT(caller_frame != NULL); | 25 ASSERT(caller_frame != NULL); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // Instantiate dst_type before reporting the error. | 207 // Instantiate dst_type before reporting the error. |
| 207 const Type& instantiated_dst_type = Type::Handle( | 208 const Type& instantiated_dst_type = Type::Handle( |
| 208 dst_type.InstantiateFrom(dst_type_instantiator, 0)); | 209 dst_type.InstantiateFrom(dst_type_instantiator, 0)); |
| 209 dst_type_name = instantiated_dst_type.Name(); | 210 dst_type_name = instantiated_dst_type.Name(); |
| 210 } else { | 211 } else { |
| 211 dst_type_name = dst_type.Name(); | 212 dst_type_name = dst_type.Name(); |
| 212 } | 213 } |
| 213 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); | 214 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); |
| 214 UNREACHABLE(); | 215 UNREACHABLE(); |
| 215 } | 216 } |
| 217 |
| 218 if (FLAG_trace_type_checks) { |
| 219 Class& cls = Class::Handle(src_instance.clazz()); |
| 220 // TODO(regis): Remove once all classes finalized. |
| 221 if (cls.is_finalized()) { |
| 222 OS::Print("TypeCheck '%s' vs '%s'\n", |
| 223 String::Handle(Type::Handle(src_instance.GetType()).Name()). |
| 224 ToCString(), |
| 225 String::Handle(dst_type.Name()).ToCString()); |
| 226 } |
| 227 } |
| 216 arguments.SetReturn(src_instance); | 228 arguments.SetReturn(src_instance); |
| 217 } | 229 } |
| 218 | 230 |
| 219 | 231 |
| 220 // Report that the type of the given object is not bool in conditional context. | 232 // Report that the type of the given object is not bool in conditional context. |
| 221 // Arg0: index of the token of the assignment (source location). | 233 // Arg0: index of the token of the assignment (source location). |
| 222 // Arg1: bad object. | 234 // Arg1: bad object. |
| 223 // Return value: none, throws a TypeError. | 235 // Return value: none, throws a TypeError. |
| 224 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 2) { | 236 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 2) { |
| 225 ASSERT(arguments.Count() == | 237 ASSERT(arguments.Count() == |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 dst_type_name = element_type.Name(); | 291 dst_type_name = element_type.Name(); |
| 280 } | 292 } |
| 281 const String& dst_name = String::Handle(String::New(buf)); | 293 const String& dst_name = String::Handle(String::New(buf)); |
| 282 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); | 294 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); |
| 283 UNREACHABLE(); | 295 UNREACHABLE(); |
| 284 } | 296 } |
| 285 } | 297 } |
| 286 } | 298 } |
| 287 | 299 |
| 288 } // namespace dart | 300 } // namespace dart |
| OLD | NEW |