summaryrefslogtreecommitdiff
path: root/deps/v8/src/runtime/runtime-forin.cc
blob: c793e88b9203611cd67532d1777d803d1af88b7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/arguments.h"
#include "src/runtime/runtime-utils.h"
#include "src/v8.h"

namespace v8 {
namespace internal {

RUNTIME_FUNCTION(Runtime_ForInDone) {
  SealHandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
  CONVERT_SMI_ARG_CHECKED(index, 0);
  CONVERT_SMI_ARG_CHECKED(length, 1);
  DCHECK_LE(0, index);
  DCHECK_LE(index, length);
  return isolate->heap()->ToBoolean(index == length);
}


RUNTIME_FUNCTION(Runtime_ForInFilter) {
  HandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
  CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
  CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
  // TODO(turbofan): Fast case for array indices.
  Handle<Name> name;
  if (!Runtime::ToName(isolate, key).ToHandle(&name)) {
    return isolate->heap()->exception();
  }
  Maybe<bool> result = JSReceiver::HasProperty(receiver, name);
  if (!result.IsJust()) return isolate->heap()->exception();
  if (result.FromJust()) return *name;
  return isolate->heap()->undefined_value();
}


RUNTIME_FUNCTION(Runtime_ForInNext) {
  HandleScope scope(isolate);
  DCHECK_EQ(4, args.length());
  CONVERT_ARG_HANDLE_CHECKED(JSReceiver, receiver, 0);
  CONVERT_ARG_HANDLE_CHECKED(FixedArray, cache_array, 1);
  CONVERT_ARG_HANDLE_CHECKED(Object, cache_type, 2);
  CONVERT_SMI_ARG_CHECKED(index, 3);
  Handle<Object> key = handle(cache_array->get(index), isolate);
  // Don't need filtering if expected map still matches that of the receiver,
  // and neither for proxies.
  if (receiver->map() == *cache_type || *cache_type == Smi::FromInt(0)) {
    return *key;
  }
  // TODO(turbofan): Fast case for array indices.
  Handle<Name> name;
  if (!Runtime::ToName(isolate, key).ToHandle(&name)) {
    return isolate->heap()->exception();
  }
  Maybe<bool> result = JSReceiver::HasProperty(receiver, name);
  if (!result.IsJust()) return isolate->heap()->exception();
  if (result.FromJust()) return *name;
  return isolate->heap()->undefined_value();
}


RUNTIME_FUNCTION(Runtime_ForInStep) {
  SealHandleScope scope(isolate);
  DCHECK_EQ(1, args.length());
  CONVERT_SMI_ARG_CHECKED(index, 0);
  DCHECK_LE(0, index);
  DCHECK_LT(index, Smi::kMaxValue);
  return Smi::FromInt(index + 1);
}

}  // namespace internal
}  // namespace v8