1// Copyright 2018 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#ifndef V8_OBJECTS_INSTANCE_TYPE_INL_H_
6#define V8_OBJECTS_INSTANCE_TYPE_INL_H_
7
8#include "src/objects/map-inl.h"
9#include "src/utils.h"
10
11// Has to be the last include (doesn't have include guards):
12#include "src/objects/object-macros.h"
13
14namespace v8 {
15namespace internal {
16
17namespace InstanceTypeChecker {
18
19// Define type checkers for classes with single instance type.
20INSTANCE_TYPE_CHECKERS_SINGLE(INSTANCE_TYPE_CHECKER)
21
22#define TYPED_ARRAY_INSTANCE_TYPE_CHECKER(Type, type, TYPE, ctype) \
23 INSTANCE_TYPE_CHECKER(Fixed##Type##Array, FIXED_##TYPE##_ARRAY_TYPE)
24TYPED_ARRAYS(TYPED_ARRAY_INSTANCE_TYPE_CHECKER)
25#undef TYPED_ARRAY_INSTANCE_TYPE_CHECKER
26
27#define STRUCT_INSTANCE_TYPE_CHECKER(TYPE, Name, name) \
28 INSTANCE_TYPE_CHECKER(Name, TYPE)
29STRUCT_LIST(STRUCT_INSTANCE_TYPE_CHECKER)
30#undef STRUCT_INSTANCE_TYPE_CHECKER
31
32// Define type checkers for classes with ranges of instance types.
33#define INSTANCE_TYPE_CHECKER_RANGE(type, first_instance_type, \
34 last_instance_type) \
35 V8_INLINE bool Is##type(InstanceType instance_type) { \
36 return IsInRange(instance_type, first_instance_type, last_instance_type); \
37 }
38INSTANCE_TYPE_CHECKERS_RANGE(INSTANCE_TYPE_CHECKER_RANGE)
39#undef INSTANCE_TYPE_CHECKER_RANGE
40
41V8_INLINE bool IsFixedArrayBase(InstanceType instance_type) {
42 return IsFixedArray(instance_type) || IsFixedDoubleArray(instance_type) ||
43 IsFixedTypedArrayBase(instance_type) || IsByteArray(instance_type) ||
44 IsBytecodeArray(instance_type);
45}
46
47V8_INLINE bool IsHeapObject(InstanceType instance_type) { return true; }
48
49V8_INLINE bool IsInternalizedString(InstanceType instance_type) {
50 STATIC_ASSERT(kNotInternalizedTag != 0);
51 return (instance_type & (kIsNotStringMask | kIsNotInternalizedMask)) ==
52 (kStringTag | kInternalizedTag);
53}
54
55V8_INLINE bool IsJSObject(InstanceType instance_type) {
56 STATIC_ASSERT(LAST_TYPE == LAST_JS_OBJECT_TYPE);
57 return instance_type >= FIRST_JS_OBJECT_TYPE;
58}
59
60V8_INLINE bool IsJSReceiver(InstanceType instance_type) {
61 STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
62 return instance_type >= FIRST_JS_RECEIVER_TYPE;
63}
64
65} // namespace InstanceTypeChecker
66
67// TODO(v8:7786): For instance types that have a single map instance on the
68// roots, and when that map is a embedded in the binary, compare against the map
69// pointer rather than looking up the instance type.
70INSTANCE_TYPE_CHECKERS(TYPE_CHECKER)
71
72#define TYPED_ARRAY_TYPE_CHECKER(Type, type, TYPE, ctype) \
73 TYPE_CHECKER(Fixed##Type##Array)
74TYPED_ARRAYS(TYPED_ARRAY_TYPE_CHECKER)
75#undef TYPED_ARRAY_TYPE_CHECKER
76
77} // namespace internal
78} // namespace v8
79
80#include "src/objects/object-macros-undef.h"
81
82#endif // V8_OBJECTS_INSTANCE_TYPE_INL_H_
83