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 // Special handling for following types outside this native. | 119 if (instance.IsString()) { |
120 ASSERT(!instance.IsString() && !instance.IsInteger() && !instance.IsDouble()); | 120 return Type::StringType(); |
121 } else if (instance.IsInteger()) { | |
122 return Type::IntType(); | |
123 } else if (instance.IsDouble()) { | |
124 return Type::Double(); | |
125 } | |
121 return instance.GetType(); | 126 return instance.GetType(); |
122 } | 127 } |
123 | 128 |
124 | 129 |
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() || (cls.NumTypeArguments() <= 0)) { | |
Florian Schneider
2016/09/28 22:49:24
It reads a bit strange. Can <0 ever occur here?
Vyacheslav Egorov (Google)
2016/09/29 00:31:22
Yeah, it don't think it can... num_type_arguments
| |
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 | |
125 DEFINE_NATIVE_ENTRY(Object_instanceOf, 4) { | 167 DEFINE_NATIVE_ENTRY(Object_instanceOf, 4) { |
126 const Instance& instance = | 168 const Instance& instance = |
127 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); | 169 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); |
128 const TypeArguments& instantiator_type_arguments = | 170 const TypeArguments& instantiator_type_arguments = |
129 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); | 171 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); |
130 const AbstractType& type = | 172 const AbstractType& type = |
131 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); | 173 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); |
132 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(3)); | 174 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(3)); |
133 ASSERT(type.IsFinalized()); | 175 ASSERT(type.IsFinalized()); |
134 ASSERT(!type.IsMalformed()); | 176 ASSERT(!type.IsMalformed()); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 | 405 |
364 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { | 406 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { |
365 #if defined(ARCH_IS_64_BIT) | 407 #if defined(ARCH_IS_64_BIT) |
366 return Bool::True().raw(); | 408 return Bool::True().raw(); |
367 #else | 409 #else |
368 return Bool::False().raw(); | 410 return Bool::False().raw(); |
369 #endif // defined(ARCH_IS_64_BIT) | 411 #endif // defined(ARCH_IS_64_BIT) |
370 } | 412 } |
371 | 413 |
372 } // namespace dart | 414 } // namespace dart |
OLD | NEW |