| 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" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } else { | 209 } else { |
| 210 dst_type_name = dst_type.Name(); | 210 dst_type_name = dst_type.Name(); |
| 211 } | 211 } |
| 212 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); | 212 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); |
| 213 UNREACHABLE(); | 213 UNREACHABLE(); |
| 214 } | 214 } |
| 215 arguments.SetReturn(src_instance); | 215 arguments.SetReturn(src_instance); |
| 216 } | 216 } |
| 217 | 217 |
| 218 | 218 |
| 219 // Check that the type of the given object is allowed in conditional context. | 219 // Report that the type of the given object is not bool in conditional context. |
| 220 // Arg0: index of the token of the assignment (source location). | 220 // Arg0: index of the token of the assignment (source location). |
| 221 // Arg1: object being checked. | 221 // Arg1: bad object. |
| 222 // Return value: checked value, otherwise allocate and throw a TypeError. | 222 // Return value: none, throws a TypeError. |
| 223 DEFINE_RUNTIME_ENTRY(ConditionTypeCheck, 2) { | 223 DEFINE_RUNTIME_ENTRY(ConditionTypeError, 2) { |
| 224 ASSERT(arguments.Count() == | 224 ASSERT(arguments.Count() == |
| 225 kConditionTypeCheckRuntimeEntry.argument_count()); | 225 kConditionTypeErrorRuntimeEntry.argument_count()); |
| 226 intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value(); | 226 intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value(); |
| 227 const Instance& src_instance = Instance::CheckedHandle(arguments.At(1)); | 227 const Instance& src_instance = Instance::CheckedHandle(arguments.At(1)); |
| 228 | 228 ASSERT(src_instance.IsNull() || !src_instance.IsBool()); |
| 229 const char* msg = "boolean expression"; | 229 const char* msg = "boolean expression"; |
| 230 if (src_instance.IsNull() || !src_instance.IsBool()) { | 230 const Type& bool_interface = Type::Handle(Type::BoolInterface()); |
| 231 const Type& bool_interface = Type::Handle(Type::BoolInterface()); | 231 const Type& src_type = Type::Handle(src_instance.GetType()); |
| 232 const Type& src_type = Type::Handle(src_instance.GetType()); | 232 const String& src_type_name = String::Handle(src_type.Name()); |
| 233 const String& src_type_name = String::Handle(src_type.Name()); | 233 const String& bool_type_name = String::Handle(bool_interface.Name()); |
| 234 const String& bool_type_name = String::Handle(bool_interface.Name()); | 234 ThrowTypeError(location, src_type_name, bool_type_name, |
| 235 ThrowTypeError(location, src_type_name, bool_type_name, | 235 String::Handle(String::NewSymbol(msg))); |
| 236 String::Handle(String::NewSymbol(msg))); | 236 UNREACHABLE(); |
| 237 UNREACHABLE(); | |
| 238 } | |
| 239 | |
| 240 arguments.SetReturn(src_instance); | |
| 241 } | 237 } |
| 242 | 238 |
| 243 | 239 |
| 244 // Check that the type of each element of the given array is assignable to the | 240 // Check that the type of each element of the given array is assignable to the |
| 245 // given type. | 241 // given type. |
| 246 // Arg0: index of the token of the rest argument declaration (source location). | 242 // Arg0: index of the token of the rest argument declaration (source location). |
| 247 // Arg1: rest argument array. | 243 // Arg1: rest argument array. |
| 248 // Arg2: element declaration type. | 244 // Arg2: element declaration type. |
| 249 // Arg3: type arguments of the instantiator of the element declaration type. | 245 // Arg3: type arguments of the instantiator of the element declaration type. |
| 250 // Arg4: name of object being assigned to, i.e. name of rest argument. | 246 // Arg4: name of object being assigned to, i.e. name of rest argument. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 dst_type_name = element_type.Name(); | 278 dst_type_name = element_type.Name(); |
| 283 } | 279 } |
| 284 const String& dst_name = String::Handle(String::New(buf)); | 280 const String& dst_name = String::Handle(String::New(buf)); |
| 285 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); | 281 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); |
| 286 UNREACHABLE(); | 282 UNREACHABLE(); |
| 287 } | 283 } |
| 288 } | 284 } |
| 289 } | 285 } |
| 290 | 286 |
| 291 } // namespace dart | 287 } // namespace dart |
| OLD | NEW |