Chromium Code Reviews| 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 "vm/exceptions.h" | 7 #include "vm/exceptions.h" |
| 8 #include "vm/native_entry.h" | 8 #include "vm/native_entry.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/stack_frame.h" | |
| 11 #include "vm/symbols.h" | |
| 10 | 12 |
| 11 namespace dart { | 13 namespace dart { |
| 12 | 14 |
| 13 DEFINE_NATIVE_ENTRY(Object_toString, 1) { | 15 DEFINE_NATIVE_ENTRY(Object_toString, 1) { |
| 14 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 16 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
| 15 const char* c_str = instance.ToCString(); | 17 const char* c_str = instance.ToCString(); |
| 16 return String::New(c_str); | 18 return String::New(c_str); |
| 17 } | 19 } |
| 18 | 20 |
| 19 | 21 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 58 } |
| 57 | 59 |
| 58 | 60 |
| 59 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { | 61 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { |
| 60 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 62 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
| 61 const Type& type = Type::Handle(instance.GetType()); | 63 const Type& type = Type::Handle(instance.GetType()); |
| 62 return type.Canonicalize(); | 64 return type.Canonicalize(); |
| 63 } | 65 } |
| 64 | 66 |
| 65 | 67 |
| 68 | |
| 69 DEFINE_NATIVE_ENTRY(Object_instanceOf, 5) { | |
| 70 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | |
| 71 // Instantiator at position 1 is not used. It is passed along so that the call | |
| 72 // can be easily converted to an optimized implementation. Instantiator is | |
| 73 // the used to populate the subtype cache. | |
|
regis
2013/01/02 21:11:52
remove "the".
srdjan
2013/01/02 21:47:12
Done.
| |
| 74 const AbstractTypeArguments& instantiator_type_arguments = | |
| 75 AbstractTypeArguments::CheckedHandle(arguments->NativeArgAt(2)); | |
| 76 const AbstractType& type = | |
| 77 AbstractType::CheckedHandle(arguments->NativeArgAt(3)); | |
| 78 const Bool& negate = Bool::CheckedHandle(arguments->NativeArgAt(4)); | |
| 79 ASSERT(type.IsFinalized()); | |
| 80 Error& malformed_error = Error::Handle(); | |
| 81 const bool is_instance_of = instance.IsInstanceOf(type, | |
| 82 instantiator_type_arguments, | |
| 83 &malformed_error); | |
| 84 if (!is_instance_of && !malformed_error.IsNull()) { | |
| 85 // Throw a dynamic type error only if the instanceof test fails. | |
| 86 DartFrameIterator iterator; | |
| 87 StackFrame* caller_frame = iterator.NextFrame(); | |
| 88 ASSERT(caller_frame != NULL); | |
| 89 const intptr_t location = caller_frame->GetTokenPos(); | |
| 90 String& malformed_error_message = String::Handle( | |
| 91 String::New(malformed_error.ToErrorCString())); | |
| 92 const String& no_name = String::Handle(Symbols::Empty()); | |
| 93 Exceptions::CreateAndThrowTypeError( | |
| 94 location, no_name, no_name, no_name, malformed_error_message); | |
| 95 UNREACHABLE(); | |
| 96 } | |
| 97 if (negate.value()) { | |
| 98 return is_instance_of ? Bool::False() : Bool::True(); | |
| 99 } else { | |
| 100 return is_instance_of ? Bool::True() : Bool::False(); | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 | |
| 66 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) { | 105 DEFINE_NATIVE_ENTRY(AbstractType_toString, 1) { |
| 67 const AbstractType& type = | 106 const AbstractType& type = |
| 68 AbstractType::CheckedHandle(arguments->NativeArgAt(0)); | 107 AbstractType::CheckedHandle(arguments->NativeArgAt(0)); |
| 69 return type.UserVisibleName(); | 108 return type.UserVisibleName(); |
| 70 } | 109 } |
| 71 | 110 |
| 72 } // namespace dart | 111 } // namespace dart |
| OLD | NEW |