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" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 } | 148 } |
149 if (!is_instance_of && !bound_error.IsNull()) { | 149 if (!is_instance_of && !bound_error.IsNull()) { |
150 // Throw a dynamic type error only if the instanceof test fails. | 150 // Throw a dynamic type error only if the instanceof test fails. |
151 DartFrameIterator iterator; | 151 DartFrameIterator iterator; |
152 StackFrame* caller_frame = iterator.NextFrame(); | 152 StackFrame* caller_frame = iterator.NextFrame(); |
153 ASSERT(caller_frame != NULL); | 153 ASSERT(caller_frame != NULL); |
154 const TokenPosition location = caller_frame->GetTokenPos(); | 154 const TokenPosition location = caller_frame->GetTokenPos(); |
155 String& bound_error_message = String::Handle( | 155 String& bound_error_message = String::Handle( |
156 zone, String::New(bound_error.ToErrorCString())); | 156 zone, String::New(bound_error.ToErrorCString())); |
157 Exceptions::CreateAndThrowTypeError( | 157 Exceptions::CreateAndThrowTypeError( |
158 location, Symbols::Empty(), Symbols::Empty(), | 158 location, AbstractType::Handle(), AbstractType::Handle(), |
srdjan
2016/03/09 22:38:22
AbstractType::Handle(zone) x 2
regis
2016/03/09 23:15:40
Done here and above.
| |
159 Symbols::Empty(), bound_error_message); | 159 Symbols::Empty(), bound_error_message); |
160 UNREACHABLE(); | 160 UNREACHABLE(); |
161 } | 161 } |
162 return Bool::Get(negate.value() ? !is_instance_of : is_instance_of).raw(); | 162 return Bool::Get(negate.value() ? !is_instance_of : is_instance_of).raw(); |
163 } | 163 } |
164 | 164 |
165 | 165 |
166 DEFINE_NATIVE_ENTRY(Object_instanceOfNum, 2) { | 166 DEFINE_NATIVE_ENTRY(Object_instanceOfNum, 2) { |
167 const Instance& instance = | 167 const Instance& instance = |
168 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); | 168 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 is_instance_of = !is_instance_of; | 220 is_instance_of = !is_instance_of; |
221 } | 221 } |
222 return Bool::Get(is_instance_of).raw(); | 222 return Bool::Get(is_instance_of).raw(); |
223 } | 223 } |
224 | 224 |
225 | 225 |
226 DEFINE_NATIVE_ENTRY(Object_as, 3) { | 226 DEFINE_NATIVE_ENTRY(Object_as, 3) { |
227 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 227 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
228 const TypeArguments& instantiator_type_arguments = | 228 const TypeArguments& instantiator_type_arguments = |
229 TypeArguments::CheckedHandle(arguments->NativeArgAt(1)); | 229 TypeArguments::CheckedHandle(arguments->NativeArgAt(1)); |
230 const AbstractType& type = | 230 AbstractType& type = AbstractType::CheckedHandle(arguments->NativeArgAt(2)); |
231 AbstractType::CheckedHandle(arguments->NativeArgAt(2)); | |
232 ASSERT(type.IsFinalized()); | 231 ASSERT(type.IsFinalized()); |
233 ASSERT(!type.IsMalformed()); | 232 ASSERT(!type.IsMalformed()); |
234 ASSERT(!type.IsMalbounded()); | 233 ASSERT(!type.IsMalbounded()); |
235 Error& bound_error = Error::Handle(); | 234 Error& bound_error = Error::Handle(); |
236 if (instance.IsNull()) { | 235 if (instance.IsNull()) { |
237 return instance.raw(); | 236 return instance.raw(); |
238 } | 237 } |
239 const bool is_instance_of = instance.IsInstanceOf(type, | 238 const bool is_instance_of = instance.IsInstanceOf(type, |
240 instantiator_type_arguments, | 239 instantiator_type_arguments, |
241 &bound_error); | 240 &bound_error); |
242 if (FLAG_trace_type_checks) { | 241 if (FLAG_trace_type_checks) { |
243 const char* result_str = is_instance_of ? "true" : "false"; | 242 const char* result_str = is_instance_of ? "true" : "false"; |
244 OS::Print("Object.as: result %s\n", result_str); | 243 OS::Print("Object.as: result %s\n", result_str); |
245 const AbstractType& instance_type = | 244 const AbstractType& instance_type = |
246 AbstractType::Handle(instance.GetType()); | 245 AbstractType::Handle(instance.GetType()); |
247 OS::Print(" instance type: %s\n", | 246 OS::Print(" instance type: %s\n", |
248 String::Handle(instance_type.Name()).ToCString()); | 247 String::Handle(instance_type.Name()).ToCString()); |
249 OS::Print(" cast type: %s\n", String::Handle(type.Name()).ToCString()); | 248 OS::Print(" cast type: %s\n", String::Handle(type.Name()).ToCString()); |
250 if (!bound_error.IsNull()) { | 249 if (!bound_error.IsNull()) { |
251 OS::Print(" bound error: %s\n", bound_error.ToErrorCString()); | 250 OS::Print(" bound error: %s\n", bound_error.ToErrorCString()); |
252 } | 251 } |
253 } | 252 } |
254 if (!is_instance_of) { | 253 if (!is_instance_of) { |
255 DartFrameIterator iterator; | 254 DartFrameIterator iterator; |
256 StackFrame* caller_frame = iterator.NextFrame(); | 255 StackFrame* caller_frame = iterator.NextFrame(); |
257 ASSERT(caller_frame != NULL); | 256 ASSERT(caller_frame != NULL); |
258 const TokenPosition location = caller_frame->GetTokenPos(); | 257 const TokenPosition location = caller_frame->GetTokenPos(); |
259 const AbstractType& instance_type = | 258 const AbstractType& instance_type = |
260 AbstractType::Handle(instance.GetType()); | 259 AbstractType::Handle(instance.GetType()); |
261 const String& instance_type_name = | |
262 String::Handle(instance_type.UserVisibleName()); | |
263 String& type_name = String::Handle(); | |
264 if (!type.IsInstantiated()) { | 260 if (!type.IsInstantiated()) { |
265 // Instantiate type before reporting the error. | 261 // Instantiate type before reporting the error. |
266 const AbstractType& instantiated_type = AbstractType::Handle( | 262 type = type.InstantiateFrom(instantiator_type_arguments, NULL, |
267 type.InstantiateFrom(instantiator_type_arguments, NULL, | 263 NULL, NULL, Heap::kNew); |
268 NULL, NULL, Heap::kNew)); | 264 // Note that the instantiated type may be malformed. |
269 // Note that instantiated_type may be malformed. | |
270 type_name = instantiated_type.UserVisibleName(); | |
271 } else { | |
272 type_name = type.UserVisibleName(); | |
273 } | 265 } |
274 String& bound_error_message = String::Handle(); | |
275 if (bound_error.IsNull()) { | 266 if (bound_error.IsNull()) { |
276 const String& dst_name = String::ZoneHandle( | |
277 Symbols::New(Exceptions::kCastErrorDstName)); | |
278 | |
279 Exceptions::CreateAndThrowTypeError( | 267 Exceptions::CreateAndThrowTypeError( |
280 location, instance_type_name, type_name, | 268 location, instance_type, type, |
281 dst_name, Object::null_string()); | 269 Symbols::InTypeCast(), Object::null_string()); |
282 } else { | 270 } else { |
283 ASSERT(isolate->type_checks()); | 271 ASSERT(isolate->type_checks()); |
284 bound_error_message = String::New(bound_error.ToErrorCString()); | 272 const String& bound_error_message = |
273 String::Handle(String::New(bound_error.ToErrorCString())); | |
srdjan
2016/03/09 22:38:22
zone,
regis
2016/03/09 23:15:40
Done.
| |
285 Exceptions::CreateAndThrowTypeError( | 274 Exceptions::CreateAndThrowTypeError( |
286 location, instance_type_name, Symbols::Empty(), | 275 location, instance_type, AbstractType::Handle(), |
srdjan
2016/03/09 22:38:22
zone
regis
2016/03/09 23:15:40
Done.
| |
287 Symbols::Empty(), bound_error_message); | 276 Symbols::Empty(), bound_error_message); |
288 } | 277 } |
289 UNREACHABLE(); | 278 UNREACHABLE(); |
290 } | 279 } |
291 return instance.raw(); | 280 return instance.raw(); |
292 } | 281 } |
293 | 282 |
294 | 283 |
295 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) { | 284 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) { |
296 const AbstractType& type = | 285 const AbstractType& type = |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 | 325 |
337 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { | 326 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { |
338 #if defined(ARCH_IS_64_BIT) | 327 #if defined(ARCH_IS_64_BIT) |
339 return Bool::True().raw(); | 328 return Bool::True().raw(); |
340 #else | 329 #else |
341 return Bool::False().raw(); | 330 return Bool::False().raw(); |
342 #endif // defined(ARCH_IS_64_BIT) | 331 #endif // defined(ARCH_IS_64_BIT) |
343 } | 332 } |
344 | 333 |
345 } // namespace dart | 334 } // namespace dart |
OLD | NEW |