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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 dart_arguments.SetAt(5, array); | 109 dart_arguments.SetAt(5, array); |
110 } | 110 } |
111 } | 111 } |
112 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); | 112 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); |
113 return Object::null(); | 113 return Object::null(); |
114 } | 114 } |
115 | 115 |
116 | 116 |
117 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { | 117 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { |
118 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 118 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
119 if (instance.IsString()) { | 119 // Special handling for following types outside this native. |
120 return Type::StringType(); | 120 ASSERT(!instance.IsString() && !instance.IsInteger() && !instance.IsDouble()); |
121 } else if (instance.IsInteger()) { | |
122 return Type::IntType(); | |
123 } else if (instance.IsDouble()) { | |
124 return Type::Double(); | |
125 } | |
126 return instance.GetType(); | 121 return instance.GetType(); |
127 } | 122 } |
128 | 123 |
129 | 124 |
130 DEFINE_NATIVE_ENTRY(Object_haveSameRuntimeType, 2) { | |
131 const Instance& left = Instance::CheckedHandle(arguments->NativeArgAt(0)); | |
132 const Instance& right = Instance::CheckedHandle(arguments->NativeArgAt(1)); | |
133 | |
134 const intptr_t left_cid = left.GetClassId(); | |
135 const intptr_t right_cid = right.GetClassId(); | |
136 | |
137 if (left_cid != right_cid) { | |
138 if (RawObject::IsIntegerClassId(left_cid)) { | |
139 return Bool::Get(RawObject::IsIntegerClassId(right_cid)).raw(); | |
140 } else if (RawObject::IsStringClassId(right_cid)) { | |
141 return Bool::Get(RawObject::IsStringClassId(right_cid)).raw(); | |
142 } else { | |
143 return Bool::False().raw(); | |
144 } | |
145 } | |
146 | |
147 const Class& cls = Class::Handle(left.clazz()); | |
148 if (cls.IsClosureClass()) { | |
149 // TODO(vegorov): provide faster implementation for closure classes. | |
150 const AbstractType& left_type = AbstractType::Handle(left.GetType()); | |
151 const AbstractType& right_type = AbstractType::Handle(right.GetType()); | |
152 return Bool::Get(left_type.raw() == right_type.raw()).raw(); | |
153 } | |
154 | |
155 if (!cls.IsGeneric()) { | |
156 return Bool::True().raw(); | |
157 } | |
158 | |
159 const TypeArguments& left_type_arguments = | |
160 TypeArguments::Handle(left.GetTypeArguments()); | |
161 const TypeArguments& right_type_arguments = | |
162 TypeArguments::Handle(right.GetTypeArguments()); | |
163 return Bool::Get(left_type_arguments.Equals(right_type_arguments)).raw(); | |
164 } | |
165 | |
166 | |
167 DEFINE_NATIVE_ENTRY(Object_instanceOf, 4) { | 125 DEFINE_NATIVE_ENTRY(Object_instanceOf, 4) { |
168 const Instance& instance = | 126 const Instance& instance = |
169 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); | 127 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); |
170 const TypeArguments& instantiator_type_arguments = | 128 const TypeArguments& instantiator_type_arguments = |
171 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); | 129 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); |
172 const AbstractType& type = | 130 const AbstractType& type = |
173 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); | 131 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); |
174 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(3)); | 132 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(3)); |
175 ASSERT(type.IsFinalized()); | 133 ASSERT(type.IsFinalized()); |
176 ASSERT(!type.IsMalformed()); | 134 ASSERT(!type.IsMalformed()); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 | 363 |
406 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { | 364 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { |
407 #if defined(ARCH_IS_64_BIT) | 365 #if defined(ARCH_IS_64_BIT) |
408 return Bool::True().raw(); | 366 return Bool::True().raw(); |
409 #else | 367 #else |
410 return Bool::False().raw(); | 368 return Bool::False().raw(); |
411 #endif // defined(ARCH_IS_64_BIT) | 369 #endif // defined(ARCH_IS_64_BIT) |
412 } | 370 } |
413 | 371 |
414 } // namespace dart | 372 } // namespace dart |
OLD | NEW |