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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 String& bound_error_message = String::Handle( | 159 String& bound_error_message = String::Handle( |
160 zone, String::New(bound_error.ToErrorCString())); | 160 zone, String::New(bound_error.ToErrorCString())); |
161 Exceptions::CreateAndThrowTypeError( | 161 Exceptions::CreateAndThrowTypeError( |
162 location, AbstractType::Handle(zone), AbstractType::Handle(zone), | 162 location, AbstractType::Handle(zone), AbstractType::Handle(zone), |
163 Symbols::Empty(), bound_error_message); | 163 Symbols::Empty(), bound_error_message); |
164 UNREACHABLE(); | 164 UNREACHABLE(); |
165 } | 165 } |
166 return Bool::Get(negate.value() ? !is_instance_of : is_instance_of).raw(); | 166 return Bool::Get(negate.value() ? !is_instance_of : is_instance_of).raw(); |
167 } | 167 } |
168 | 168 |
169 DEFINE_NATIVE_ENTRY(Object_simpleInstanceOf, 2) { | |
170 // This native is only called when the right hand side passes | |
171 // simpleInstanceOfType and it is a non-negative test. | |
regis
2016/07/14 01:41:45
It would be interesting to do it for the negative
bakster
2016/07/14 17:59:41
Yes, that is an easy change.
However, in the bench
| |
172 const Instance& instance = | |
173 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); | |
174 const AbstractType& type = | |
175 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(1)); | |
176 const TypeArguments& instantiator_type_arguments = | |
177 TypeArguments::Handle(TypeArguments::null()); | |
178 ASSERT(type.IsFinalized()); | |
179 ASSERT(!type.IsMalformed()); | |
180 ASSERT(!type.IsMalbounded()); | |
181 Error& bound_error = Error::Handle(zone, Error::null()); | |
182 const bool is_instance_of = instance.IsInstanceOf(type, | |
183 instantiator_type_arguments, | |
184 &bound_error); | |
185 if (!is_instance_of && !bound_error.IsNull()) { | |
186 // Throw a dynamic type error only if the instanceof test fails. | |
187 DartFrameIterator iterator; | |
188 StackFrame* caller_frame = iterator.NextFrame(); | |
189 ASSERT(caller_frame != NULL); | |
190 const TokenPosition location = caller_frame->GetTokenPos(); | |
191 String& bound_error_message = String::Handle( | |
192 zone, String::New(bound_error.ToErrorCString())); | |
193 Exceptions::CreateAndThrowTypeError( | |
194 location, AbstractType::Handle(zone), AbstractType::Handle(zone), | |
195 Symbols::Empty(), bound_error_message); | |
196 UNREACHABLE(); | |
197 } | |
198 return Bool::Get(is_instance_of).raw(); | |
199 } | |
169 | 200 |
170 DEFINE_NATIVE_ENTRY(Object_instanceOfNum, 2) { | 201 DEFINE_NATIVE_ENTRY(Object_instanceOfNum, 2) { |
171 const Instance& instance = | 202 const Instance& instance = |
172 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); | 203 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); |
173 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(1)); | 204 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(1)); |
174 bool is_instance_of = instance.IsNumber(); | 205 bool is_instance_of = instance.IsNumber(); |
175 if (negate.value()) { | 206 if (negate.value()) { |
176 is_instance_of = !is_instance_of; | 207 is_instance_of = !is_instance_of; |
177 } | 208 } |
178 return Bool::Get(is_instance_of).raw(); | 209 return Bool::Get(is_instance_of).raw(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 | 363 |
333 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { | 364 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { |
334 #if defined(ARCH_IS_64_BIT) | 365 #if defined(ARCH_IS_64_BIT) |
335 return Bool::True().raw(); | 366 return Bool::True().raw(); |
336 #else | 367 #else |
337 return Bool::False().raw(); | 368 return Bool::False().raw(); |
338 #endif // defined(ARCH_IS_64_BIT) | 369 #endif // defined(ARCH_IS_64_BIT) |
339 } | 370 } |
340 | 371 |
341 } // namespace dart | 372 } // namespace dart |
OLD | NEW |