Chromium Code Reviews| Index: runtime/lib/object.cc |
| =================================================================== |
| --- runtime/lib/object.cc (revision 16582) |
| +++ runtime/lib/object.cc (working copy) |
| @@ -7,6 +7,8 @@ |
| #include "vm/exceptions.h" |
| #include "vm/native_entry.h" |
| #include "vm/object.h" |
| +#include "vm/stack_frame.h" |
| +#include "vm/symbols.h" |
| namespace dart { |
| @@ -63,6 +65,43 @@ |
| } |
| + |
| +DEFINE_NATIVE_ENTRY(Object_instanceOf, 5) { |
| + const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
| + // Instantiator at position 1 is not used. It is passed along so that the call |
| + // can be easily converted to an optimized implementation. Instantiator is |
| + // the used to populate the subtype cache. |
|
regis
2013/01/02 21:11:52
remove "the".
srdjan
2013/01/02 21:47:12
Done.
|
| + const AbstractTypeArguments& instantiator_type_arguments = |
| + AbstractTypeArguments::CheckedHandle(arguments->NativeArgAt(2)); |
| + const AbstractType& type = |
| + AbstractType::CheckedHandle(arguments->NativeArgAt(3)); |
| + const Bool& negate = Bool::CheckedHandle(arguments->NativeArgAt(4)); |
| + ASSERT(type.IsFinalized()); |
| + Error& malformed_error = Error::Handle(); |
| + const bool is_instance_of = instance.IsInstanceOf(type, |
| + instantiator_type_arguments, |
| + &malformed_error); |
| + if (!is_instance_of && !malformed_error.IsNull()) { |
| + // Throw a dynamic type error only if the instanceof test fails. |
| + DartFrameIterator iterator; |
| + StackFrame* caller_frame = iterator.NextFrame(); |
| + ASSERT(caller_frame != NULL); |
| + const intptr_t location = caller_frame->GetTokenPos(); |
| + String& malformed_error_message = String::Handle( |
| + String::New(malformed_error.ToErrorCString())); |
| + const String& no_name = String::Handle(Symbols::Empty()); |
| + Exceptions::CreateAndThrowTypeError( |
| + location, no_name, no_name, no_name, malformed_error_message); |
| + UNREACHABLE(); |
| + } |
| + if (negate.value()) { |
| + return is_instance_of ? Bool::False() : Bool::True(); |
| + } else { |
| + return is_instance_of ? Bool::True() : Bool::False(); |
| + } |
| +} |
| + |
| + |
| DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) { |
| const AbstractType& type = |
| AbstractType::CheckedHandle(arguments->NativeArgAt(0)); |