struct-inl.h 1.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2018 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.

#ifndef V8_OBJECTS_STRUCT_INL_H_
#define V8_OBJECTS_STRUCT_INL_H_

#include "src/objects/struct.h"

#include "src/heap/heap-write-barrier-inl.h"
11
#include "src/objects/objects-inl.h"
12
#include "src/objects/oddball.h"
13
#include "src/roots/roots-inl.h"
14
#include "torque-generated/class-definitions-tq-inl.h"
15 16 17 18 19 20 21

// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"

namespace v8 {
namespace internal {

22 23 24
TQ_OBJECT_CONSTRUCTORS_IMPL(Struct)
TQ_OBJECT_CONSTRUCTORS_IMPL(Tuple2)
TQ_OBJECT_CONSTRUCTORS_IMPL(Tuple3)
25
OBJECT_CONSTRUCTORS_IMPL(AccessorPair, Struct)
26

27 28
OBJECT_CONSTRUCTORS_IMPL(ClassPositions, Struct)

29
CAST_ACCESSOR(AccessorPair)
30 31
CAST_ACCESSOR(ClassPositions)

32
void Struct::InitializeBody(int object_size) {
33
  Object value = GetReadOnlyRoots().undefined_value();
34
  for (int offset = kHeaderSize; offset < object_size; offset += kTaggedSize) {
35
    WRITE_FIELD(*this, offset, value);
36 37 38
  }
}

39 40 41
ACCESSORS(AccessorPair, getter, Object, kGetterOffset)
ACCESSORS(AccessorPair, setter, Object, kSetterOffset)

42 43 44
SMI_ACCESSORS(ClassPositions, start, kStartOffset)
SMI_ACCESSORS(ClassPositions, end, kEndOffset)

45
Object AccessorPair::get(AccessorComponent component) {
46 47 48
  return component == ACCESSOR_GETTER ? getter() : setter();
}

49
void AccessorPair::set(AccessorComponent component, Object value) {
50 51 52 53 54 55 56
  if (component == ACCESSOR_GETTER) {
    set_getter(value);
  } else {
    set_setter(value);
  }
}

57
void AccessorPair::SetComponents(Object getter, Object setter) {
58 59
  if (!getter.IsNull()) set_getter(getter);
  if (!setter.IsNull()) set_setter(setter);
60 61
}

62
bool AccessorPair::Equals(Object getter_value, Object setter_value) {
63 64 65 66 67 68 69 70 71
  return (getter() == getter_value) && (setter() == setter_value);
}

}  // namespace internal
}  // namespace v8

#include "src/objects/object-macros-undef.h"

#endif  // V8_OBJECTS_STRUCT_INL_H_