Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1 | // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/runtime/runtime-utils.h" |
| 6 | |
| 7 | #include "src/arguments.h" |
| 8 | #include "src/objects-inl.h" |
| 9 | |
| 10 | namespace v8 { |
| 11 | namespace internal { |
| 12 | |
| 13 | RUNTIME_FUNCTION(Runtime_ForInDone) { |
| 14 | SealHandleScope scope(isolate); |
| 15 | DCHECK_EQ(2, args.length()); |
| 16 | CONVERT_SMI_ARG_CHECKED(index, 0); |
| 17 | CONVERT_SMI_ARG_CHECKED(length, 1); |
| 18 | DCHECK_LE(0, index); |
| 19 | DCHECK_LE(index, length); |
| 20 | return isolate->heap()->ToBoolean(index == length); |
| 21 | } |
| 22 | |
| 23 | |
| 24 | RUNTIME_FUNCTION(Runtime_ForInFilter) { |
| 25 | HandleScope scope(isolate); |
| 26 | DCHECK_EQ(2, args.length()); |
| 27 | CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0); |
| 28 | CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| 29 | // TODO(turbofan): Fast case for array indices. |
| 30 | Handle<Name> name; |
| 31 | if (!Object::ToName(isolate, key).ToHandle(&name)) { |
| 32 | return isolate->heap()->exception(); |
| 33 | } |
| 34 | Maybe<bool> result = JSReceiver::HasProperty(receiver, name); |
| 35 | if (!result.IsJust()) return isolate->heap()->exception(); |
| 36 | if (result.FromJust()) return *name; |
| 37 | return isolate->heap()->undefined_value(); |
| 38 | } |
| 39 | |
| 40 | |
| 41 | RUNTIME_FUNCTION(Runtime_ForInNext) { |
| 42 | HandleScope scope(isolate); |
| 43 | DCHECK_EQ(4, args.length()); |
| 44 | CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0); |
| 45 | CONVERT_ARG_HANDLE_CHECKED(FixedArray, cache_array, 1); |
| 46 | CONVERT_ARG_HANDLE_CHECKED(Object, cache_type, 2); |
| 47 | CONVERT_SMI_ARG_CHECKED(index, 3); |
| 48 | Handle<Object> key = handle(cache_array->get(index), isolate); |
| 49 | // Don't need filtering if expected map still matches that of the receiver, |
| 50 | // and neither for proxies. |
| 51 | if (receiver->map() == *cache_type || *cache_type == Smi::FromInt(0)) { |
| 52 | return *key; |
| 53 | } |
| 54 | // TODO(turbofan): Fast case for array indices. |
| 55 | Handle<Name> name; |
| 56 | if (!Object::ToName(isolate, key).ToHandle(&name)) { |
| 57 | return isolate->heap()->exception(); |
| 58 | } |
| 59 | Maybe<bool> result = JSReceiver::HasProperty(receiver, name); |
| 60 | if (!result.IsJust()) return isolate->heap()->exception(); |
| 61 | if (result.FromJust()) return *name; |
| 62 | return isolate->heap()->undefined_value(); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | RUNTIME_FUNCTION(Runtime_ForInStep) { |
| 67 | SealHandleScope scope(isolate); |
| 68 | DCHECK_EQ(1, args.length()); |
| 69 | CONVERT_SMI_ARG_CHECKED(index, 0); |
| 70 | DCHECK_LE(0, index); |
| 71 | DCHECK_LT(index, Smi::kMaxValue); |
| 72 | return Smi::FromInt(index + 1); |
| 73 | } |
| 74 | |
| 75 | } // namespace internal |
| 76 | } // namespace v8 |