| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 return String::New(c_str); | 66 return String::New(c_str); |
| 67 } | 67 } |
| 68 | 68 |
| 69 | 69 |
| 70 DEFINE_NATIVE_ENTRY(Object_noSuchMethod, 6) { | 70 DEFINE_NATIVE_ENTRY(Object_noSuchMethod, 6) { |
| 71 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 71 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
| 72 GET_NON_NULL_NATIVE_ARGUMENT(Bool, is_method, arguments->NativeArgAt(1)); | 72 GET_NON_NULL_NATIVE_ARGUMENT(Bool, is_method, arguments->NativeArgAt(1)); |
| 73 GET_NON_NULL_NATIVE_ARGUMENT(String, member_name, arguments->NativeArgAt(2)); | 73 GET_NON_NULL_NATIVE_ARGUMENT(String, member_name, arguments->NativeArgAt(2)); |
| 74 GET_NON_NULL_NATIVE_ARGUMENT(Smi, invocation_type, arguments->NativeArgAt(3)); | 74 GET_NON_NULL_NATIVE_ARGUMENT(Smi, invocation_type, arguments->NativeArgAt(3)); |
| 75 GET_NON_NULL_NATIVE_ARGUMENT(Instance, func_args, arguments->NativeArgAt(4)); | 75 GET_NON_NULL_NATIVE_ARGUMENT(Instance, func_args, arguments->NativeArgAt(4)); |
| 76 GET_NON_NULL_NATIVE_ARGUMENT( | 76 GET_NON_NULL_NATIVE_ARGUMENT(Instance, func_named_args, |
| 77 Instance, func_named_args, arguments->NativeArgAt(5)); | 77 arguments->NativeArgAt(5)); |
| 78 const Array& dart_arguments = Array::Handle(Array::New(6)); | 78 const Array& dart_arguments = Array::Handle(Array::New(6)); |
| 79 dart_arguments.SetAt(0, instance); | 79 dart_arguments.SetAt(0, instance); |
| 80 dart_arguments.SetAt(1, member_name); | 80 dart_arguments.SetAt(1, member_name); |
| 81 dart_arguments.SetAt(2, invocation_type); | 81 dart_arguments.SetAt(2, invocation_type); |
| 82 dart_arguments.SetAt(3, func_args); | 82 dart_arguments.SetAt(3, func_args); |
| 83 dart_arguments.SetAt(4, func_named_args); | 83 dart_arguments.SetAt(4, func_named_args); |
| 84 | 84 |
| 85 if (is_method.value() && | 85 if (is_method.value() && |
| 86 (((invocation_type.Value() >> InvocationMirror::kCallShift) & | 86 (((invocation_type.Value() >> InvocationMirror::kCallShift) & |
| 87 InvocationMirror::kCallMask) != InvocationMirror::kSuper)) { | 87 InvocationMirror::kCallMask) != InvocationMirror::kSuper)) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); | 169 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); |
| 170 const TypeArguments& instantiator_type_arguments = | 170 const TypeArguments& instantiator_type_arguments = |
| 171 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); | 171 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); |
| 172 const AbstractType& type = | 172 const AbstractType& type = |
| 173 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); | 173 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); |
| 174 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(3)); | 174 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(3)); |
| 175 ASSERT(type.IsFinalized()); | 175 ASSERT(type.IsFinalized()); |
| 176 ASSERT(!type.IsMalformed()); | 176 ASSERT(!type.IsMalformed()); |
| 177 ASSERT(!type.IsMalbounded()); | 177 ASSERT(!type.IsMalbounded()); |
| 178 Error& bound_error = Error::Handle(zone, Error::null()); | 178 Error& bound_error = Error::Handle(zone, Error::null()); |
| 179 const bool is_instance_of = instance.IsInstanceOf(type, | 179 const bool is_instance_of = |
| 180 instantiator_type_arguments, | 180 instance.IsInstanceOf(type, instantiator_type_arguments, &bound_error); |
| 181 &bound_error); | |
| 182 if (FLAG_trace_type_checks) { | 181 if (FLAG_trace_type_checks) { |
| 183 const char* result_str = is_instance_of ? "true" : "false"; | 182 const char* result_str = is_instance_of ? "true" : "false"; |
| 184 OS::Print("Native Object.instanceOf: result %s\n", result_str); | 183 OS::Print("Native Object.instanceOf: result %s\n", result_str); |
| 185 const AbstractType& instance_type = | 184 const AbstractType& instance_type = |
| 186 AbstractType::Handle(zone, instance.GetType()); | 185 AbstractType::Handle(zone, instance.GetType()); |
| 187 OS::Print(" instance type: %s\n", | 186 OS::Print(" instance type: %s\n", |
| 188 String::Handle(zone, instance_type.Name()).ToCString()); | 187 String::Handle(zone, instance_type.Name()).ToCString()); |
| 189 OS::Print(" test type: %s\n", | 188 OS::Print(" test type: %s\n", |
| 190 String::Handle(zone, type.Name()).ToCString()); | 189 String::Handle(zone, type.Name()).ToCString()); |
| 191 if (!bound_error.IsNull()) { | 190 if (!bound_error.IsNull()) { |
| 192 OS::Print(" bound error: %s\n", bound_error.ToErrorCString()); | 191 OS::Print(" bound error: %s\n", bound_error.ToErrorCString()); |
| 193 } | 192 } |
| 194 } | 193 } |
| 195 if (!is_instance_of && !bound_error.IsNull()) { | 194 if (!is_instance_of && !bound_error.IsNull()) { |
| 196 // Throw a dynamic type error only if the instanceof test fails. | 195 // Throw a dynamic type error only if the instanceof test fails. |
| 197 DartFrameIterator iterator; | 196 DartFrameIterator iterator; |
| 198 StackFrame* caller_frame = iterator.NextFrame(); | 197 StackFrame* caller_frame = iterator.NextFrame(); |
| 199 ASSERT(caller_frame != NULL); | 198 ASSERT(caller_frame != NULL); |
| 200 const TokenPosition location = caller_frame->GetTokenPos(); | 199 const TokenPosition location = caller_frame->GetTokenPos(); |
| 201 String& bound_error_message = String::Handle( | 200 String& bound_error_message = |
| 202 zone, String::New(bound_error.ToErrorCString())); | 201 String::Handle(zone, String::New(bound_error.ToErrorCString())); |
| 203 Exceptions::CreateAndThrowTypeError( | 202 Exceptions::CreateAndThrowTypeError(location, AbstractType::Handle(zone), |
| 204 location, AbstractType::Handle(zone), AbstractType::Handle(zone), | 203 AbstractType::Handle(zone), |
| 205 Symbols::Empty(), bound_error_message); | 204 Symbols::Empty(), bound_error_message); |
| 206 UNREACHABLE(); | 205 UNREACHABLE(); |
| 207 } | 206 } |
| 208 return Bool::Get(negate.value() ? !is_instance_of : is_instance_of).raw(); | 207 return Bool::Get(negate.value() ? !is_instance_of : is_instance_of).raw(); |
| 209 } | 208 } |
| 210 | 209 |
| 211 DEFINE_NATIVE_ENTRY(Object_simpleInstanceOf, 2) { | 210 DEFINE_NATIVE_ENTRY(Object_simpleInstanceOf, 2) { |
| 212 // This native is only called when the right hand side passes | 211 // This native is only called when the right hand side passes |
| 213 // simpleInstanceOfType and it is a non-negative test. | 212 // simpleInstanceOfType and it is a non-negative test. |
| 214 const Instance& instance = | 213 const Instance& instance = |
| 215 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); | 214 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); |
| 216 const AbstractType& type = | 215 const AbstractType& type = |
| 217 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(1)); | 216 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(1)); |
| 218 const TypeArguments& instantiator_type_arguments = | 217 const TypeArguments& instantiator_type_arguments = |
| 219 TypeArguments::Handle(TypeArguments::null()); | 218 TypeArguments::Handle(TypeArguments::null()); |
| 220 ASSERT(type.IsFinalized()); | 219 ASSERT(type.IsFinalized()); |
| 221 ASSERT(!type.IsMalformed()); | 220 ASSERT(!type.IsMalformed()); |
| 222 ASSERT(!type.IsMalbounded()); | 221 ASSERT(!type.IsMalbounded()); |
| 223 Error& bound_error = Error::Handle(zone, Error::null()); | 222 Error& bound_error = Error::Handle(zone, Error::null()); |
| 224 const bool is_instance_of = instance.IsInstanceOf(type, | 223 const bool is_instance_of = |
| 225 instantiator_type_arguments, | 224 instance.IsInstanceOf(type, instantiator_type_arguments, &bound_error); |
| 226 &bound_error); | |
| 227 if (!is_instance_of && !bound_error.IsNull()) { | 225 if (!is_instance_of && !bound_error.IsNull()) { |
| 228 // Throw a dynamic type error only if the instanceof test fails. | 226 // Throw a dynamic type error only if the instanceof test fails. |
| 229 DartFrameIterator iterator; | 227 DartFrameIterator iterator; |
| 230 StackFrame* caller_frame = iterator.NextFrame(); | 228 StackFrame* caller_frame = iterator.NextFrame(); |
| 231 ASSERT(caller_frame != NULL); | 229 ASSERT(caller_frame != NULL); |
| 232 const TokenPosition location = caller_frame->GetTokenPos(); | 230 const TokenPosition location = caller_frame->GetTokenPos(); |
| 233 String& bound_error_message = String::Handle( | 231 String& bound_error_message = |
| 234 zone, String::New(bound_error.ToErrorCString())); | 232 String::Handle(zone, String::New(bound_error.ToErrorCString())); |
| 235 Exceptions::CreateAndThrowTypeError( | 233 Exceptions::CreateAndThrowTypeError(location, AbstractType::Handle(zone), |
| 236 location, AbstractType::Handle(zone), AbstractType::Handle(zone), | 234 AbstractType::Handle(zone), |
| 237 Symbols::Empty(), bound_error_message); | 235 Symbols::Empty(), bound_error_message); |
| 238 UNREACHABLE(); | 236 UNREACHABLE(); |
| 239 } | 237 } |
| 240 return Bool::Get(is_instance_of).raw(); | 238 return Bool::Get(is_instance_of).raw(); |
| 241 } | 239 } |
| 242 | 240 |
| 243 DEFINE_NATIVE_ENTRY(Object_instanceOfNum, 2) { | 241 DEFINE_NATIVE_ENTRY(Object_instanceOfNum, 2) { |
| 244 const Instance& instance = | 242 const Instance& instance = |
| 245 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); | 243 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); |
| 246 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(1)); | 244 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(1)); |
| 247 bool is_instance_of = instance.IsNumber(); | 245 bool is_instance_of = instance.IsNumber(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); | 305 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); |
| 308 AbstractType& type = | 306 AbstractType& type = |
| 309 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); | 307 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); |
| 310 ASSERT(type.IsFinalized()); | 308 ASSERT(type.IsFinalized()); |
| 311 ASSERT(!type.IsMalformed()); | 309 ASSERT(!type.IsMalformed()); |
| 312 ASSERT(!type.IsMalbounded()); | 310 ASSERT(!type.IsMalbounded()); |
| 313 Error& bound_error = Error::Handle(zone); | 311 Error& bound_error = Error::Handle(zone); |
| 314 if (instance.IsNull()) { | 312 if (instance.IsNull()) { |
| 315 return instance.raw(); | 313 return instance.raw(); |
| 316 } | 314 } |
| 317 const bool is_instance_of = instance.IsInstanceOf(type, | 315 const bool is_instance_of = |
| 318 instantiator_type_arguments, | 316 instance.IsInstanceOf(type, instantiator_type_arguments, &bound_error); |
| 319 &bound_error); | |
| 320 if (FLAG_trace_type_checks) { | 317 if (FLAG_trace_type_checks) { |
| 321 const char* result_str = is_instance_of ? "true" : "false"; | 318 const char* result_str = is_instance_of ? "true" : "false"; |
| 322 OS::Print("Object.as: result %s\n", result_str); | 319 OS::Print("Object.as: result %s\n", result_str); |
| 323 const AbstractType& instance_type = | 320 const AbstractType& instance_type = |
| 324 AbstractType::Handle(zone, instance.GetType()); | 321 AbstractType::Handle(zone, instance.GetType()); |
| 325 OS::Print(" instance type: %s\n", | 322 OS::Print(" instance type: %s\n", |
| 326 String::Handle(zone, instance_type.Name()).ToCString()); | 323 String::Handle(zone, instance_type.Name()).ToCString()); |
| 327 OS::Print(" cast type: %s\n", | 324 OS::Print(" cast type: %s\n", |
| 328 String::Handle(zone, type.Name()).ToCString()); | 325 String::Handle(zone, type.Name()).ToCString()); |
| 329 if (!bound_error.IsNull()) { | 326 if (!bound_error.IsNull()) { |
| 330 OS::Print(" bound error: %s\n", bound_error.ToErrorCString()); | 327 OS::Print(" bound error: %s\n", bound_error.ToErrorCString()); |
| 331 } | 328 } |
| 332 } | 329 } |
| 333 if (!is_instance_of) { | 330 if (!is_instance_of) { |
| 334 DartFrameIterator iterator; | 331 DartFrameIterator iterator; |
| 335 StackFrame* caller_frame = iterator.NextFrame(); | 332 StackFrame* caller_frame = iterator.NextFrame(); |
| 336 ASSERT(caller_frame != NULL); | 333 ASSERT(caller_frame != NULL); |
| 337 const TokenPosition location = caller_frame->GetTokenPos(); | 334 const TokenPosition location = caller_frame->GetTokenPos(); |
| 338 const AbstractType& instance_type = | 335 const AbstractType& instance_type = |
| 339 AbstractType::Handle(zone, instance.GetType()); | 336 AbstractType::Handle(zone, instance.GetType()); |
| 340 if (!type.IsInstantiated()) { | 337 if (!type.IsInstantiated()) { |
| 341 // Instantiate type before reporting the error. | 338 // Instantiate type before reporting the error. |
| 342 type = type.InstantiateFrom(instantiator_type_arguments, NULL, | 339 type = type.InstantiateFrom(instantiator_type_arguments, NULL, NULL, NULL, |
| 343 NULL, NULL, Heap::kNew); | 340 Heap::kNew); |
| 344 // Note that the instantiated type may be malformed. | 341 // Note that the instantiated type may be malformed. |
| 345 } | 342 } |
| 346 if (bound_error.IsNull()) { | 343 if (bound_error.IsNull()) { |
| 347 Exceptions::CreateAndThrowTypeError( | 344 Exceptions::CreateAndThrowTypeError(location, instance_type, type, |
| 348 location, instance_type, type, | 345 Symbols::InTypeCast(), |
| 349 Symbols::InTypeCast(), Object::null_string()); | 346 Object::null_string()); |
| 350 } else { | 347 } else { |
| 351 ASSERT(isolate->type_checks()); | 348 ASSERT(isolate->type_checks()); |
| 352 const String& bound_error_message = | 349 const String& bound_error_message = |
| 353 String::Handle(zone, String::New(bound_error.ToErrorCString())); | 350 String::Handle(zone, String::New(bound_error.ToErrorCString())); |
| 354 Exceptions::CreateAndThrowTypeError( | 351 Exceptions::CreateAndThrowTypeError( |
| 355 location, instance_type, AbstractType::Handle(zone), | 352 location, instance_type, AbstractType::Handle(zone), Symbols::Empty(), |
| 356 Symbols::Empty(), bound_error_message); | 353 bound_error_message); |
| 357 } | 354 } |
| 358 UNREACHABLE(); | 355 UNREACHABLE(); |
| 359 } | 356 } |
| 360 return instance.raw(); | 357 return instance.raw(); |
| 361 } | 358 } |
| 362 | 359 |
| 363 | 360 |
| 364 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) { | 361 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) { |
| 365 const AbstractType& type = | 362 const AbstractType& type = |
| 366 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(0)); | 363 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(0)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 402 |
| 406 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { | 403 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { |
| 407 #if defined(ARCH_IS_64_BIT) | 404 #if defined(ARCH_IS_64_BIT) |
| 408 return Bool::True().raw(); | 405 return Bool::True().raw(); |
| 409 #else | 406 #else |
| 410 return Bool::False().raw(); | 407 return Bool::False().raw(); |
| 411 #endif // defined(ARCH_IS_64_BIT) | 408 #endif // defined(ARCH_IS_64_BIT) |
| 412 } | 409 } |
| 413 | 410 |
| 414 } // namespace dart | 411 } // namespace dart |
| OLD | NEW |