| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // Arg4: name of instance being assigned to. | 187 // Arg4: name of instance being assigned to. |
| 188 // Return value: instance if assignable, otherwise throw a TypeError. | 188 // Return value: instance if assignable, otherwise throw a TypeError. |
| 189 DEFINE_RUNTIME_ENTRY(TypeCheck, 5) { | 189 DEFINE_RUNTIME_ENTRY(TypeCheck, 5) { |
| 190 ASSERT(arguments.Count() == kTypeCheckRuntimeEntry.argument_count()); | 190 ASSERT(arguments.Count() == kTypeCheckRuntimeEntry.argument_count()); |
| 191 intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value(); | 191 intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value(); |
| 192 const Instance& src_instance = Instance::CheckedHandle(arguments.At(1)); | 192 const Instance& src_instance = Instance::CheckedHandle(arguments.At(1)); |
| 193 const Type& dst_type = Type::CheckedHandle(arguments.At(2)); | 193 const Type& dst_type = Type::CheckedHandle(arguments.At(2)); |
| 194 const TypeArguments& dst_type_instantiator = | 194 const TypeArguments& dst_type_instantiator = |
| 195 TypeArguments::CheckedHandle(arguments.At(3)); | 195 TypeArguments::CheckedHandle(arguments.At(3)); |
| 196 const String& dst_name = String::CheckedHandle(arguments.At(4)); | 196 const String& dst_name = String::CheckedHandle(arguments.At(4)); |
| 197 ASSERT(!dst_type.IsVarType()); // No need to check assignment to 'var type'. | 197 ASSERT(!dst_type.IsDynamicType()); // No need to check assignment. |
| 198 ASSERT(!src_instance.IsNull()); // Already checked in inlined code. | 198 ASSERT(!src_instance.IsNull()); // Already checked in inlined code. |
| 199 | 199 |
| 200 if (!src_instance.IsAssignableTo(dst_type, dst_type_instantiator)) { | 200 if (!src_instance.IsAssignableTo(dst_type, dst_type_instantiator)) { |
| 201 const Type& src_type = Type::Handle(src_instance.GetType()); | 201 const Type& src_type = Type::Handle(src_instance.GetType()); |
| 202 const String& src_type_name = String::Handle(src_type.Name()); | 202 const String& src_type_name = String::Handle(src_type.Name()); |
| 203 String& dst_type_name = String::Handle(); | 203 String& dst_type_name = String::Handle(); |
| 204 if (!dst_type.IsInstantiated()) { | 204 if (!dst_type.IsInstantiated()) { |
| 205 // Instantiate dst_type before reporting the error. | 205 // Instantiate dst_type before reporting the error. |
| 206 const Type& instantiated_dst_type = Type::Handle( | 206 const Type& instantiated_dst_type = Type::Handle( |
| 207 dst_type.InstantiateFrom(dst_type_instantiator, 0)); | 207 dst_type.InstantiateFrom(dst_type_instantiator, 0)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 // Return value: null if assignable, otherwise allocate and throw a TypeError. | 251 // Return value: null if assignable, otherwise allocate and throw a TypeError. |
| 252 DEFINE_RUNTIME_ENTRY(RestArgumentTypeCheck, 5) { | 252 DEFINE_RUNTIME_ENTRY(RestArgumentTypeCheck, 5) { |
| 253 ASSERT(arguments.Count() == | 253 ASSERT(arguments.Count() == |
| 254 kRestArgumentTypeCheckRuntimeEntry.argument_count()); | 254 kRestArgumentTypeCheckRuntimeEntry.argument_count()); |
| 255 intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value(); | 255 intptr_t location = Smi::CheckedHandle(arguments.At(0)).Value(); |
| 256 const Array& rest_array = Array::CheckedHandle(arguments.At(1)); | 256 const Array& rest_array = Array::CheckedHandle(arguments.At(1)); |
| 257 const Type& element_type = Type::CheckedHandle(arguments.At(2)); | 257 const Type& element_type = Type::CheckedHandle(arguments.At(2)); |
| 258 const TypeArguments& element_type_instantiator = | 258 const TypeArguments& element_type_instantiator = |
| 259 TypeArguments::CheckedHandle(arguments.At(3)); | 259 TypeArguments::CheckedHandle(arguments.At(3)); |
| 260 const String& rest_name = String::CheckedHandle(arguments.At(4)); | 260 const String& rest_name = String::CheckedHandle(arguments.At(4)); |
| 261 ASSERT(!element_type.IsVarType()); // No need to check assignment. | 261 ASSERT(!element_type.IsDynamicType()); // No need to check assignment. |
| 262 ASSERT(!rest_array.IsNull()); | 262 ASSERT(!rest_array.IsNull()); |
| 263 | 263 |
| 264 Instance& elem = Instance::Handle(); | 264 Instance& elem = Instance::Handle(); |
| 265 for (intptr_t i = 0; i < rest_array.Length(); i++) { | 265 for (intptr_t i = 0; i < rest_array.Length(); i++) { |
| 266 elem ^= rest_array.At(i); | 266 elem ^= rest_array.At(i); |
| 267 if (!elem.IsNull() && | 267 if (!elem.IsNull() && |
| 268 !elem.IsAssignableTo(element_type, element_type_instantiator)) { | 268 !elem.IsAssignableTo(element_type, element_type_instantiator)) { |
| 269 // Allocate and throw a new instance of TypeError. | 269 // Allocate and throw a new instance of TypeError. |
| 270 char buf[256]; | 270 char buf[256]; |
| 271 OS::SNPrint(buf, sizeof(buf), "%s[%d]", | 271 OS::SNPrint(buf, sizeof(buf), "%s[%d]", |
| (...skipping 10 matching lines...) Expand all Loading... |
| 282 dst_type_name = element_type.Name(); | 282 dst_type_name = element_type.Name(); |
| 283 } | 283 } |
| 284 const String& dst_name = String::Handle(String::New(buf)); | 284 const String& dst_name = String::Handle(String::New(buf)); |
| 285 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); | 285 ThrowTypeError(location, src_type_name, dst_type_name, dst_name); |
| 286 UNREACHABLE(); | 286 UNREACHABLE(); |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 } | 289 } |
| 290 | 290 |
| 291 } // namespace dart | 291 } // namespace dart |
| OLD | NEW |