templates-inl.h 7.37 KB
Newer Older
1 2 3 4 5 6 7 8 9
// 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_TEMPLATES_INL_H_
#define V8_OBJECTS_TEMPLATES_INL_H_

#include "src/objects/templates.h"

10
#include "src/heap/heap-write-barrier-inl.h"
11
#include "src/objects/oddball.h"
12
#include "src/objects/shared-function-info-inl.h"
13 14 15 16 17 18 19

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

namespace v8 {
namespace internal {

20
OBJECT_CONSTRUCTORS_IMPL(TemplateInfo, Struct)
21 22
OBJECT_CONSTRUCTORS_IMPL(FunctionTemplateInfo, TemplateInfo)
OBJECT_CONSTRUCTORS_IMPL(ObjectTemplateInfo, TemplateInfo)
23
OBJECT_CONSTRUCTORS_IMPL(FunctionTemplateRareData, Struct)
24 25 26

NEVER_READ_ONLY_SPACE_IMPL(TemplateInfo)

27 28
ACCESSORS(TemplateInfo, tag, Object, kTagOffset)
ACCESSORS(TemplateInfo, serial_number, Object, kSerialNumberOffset)
29
SMI_ACCESSORS(TemplateInfo, number_of_properties, kNumberOfPropertiesOffset)
30 31 32 33 34 35 36 37
ACCESSORS(TemplateInfo, property_list, Object, kPropertyListOffset)
ACCESSORS(TemplateInfo, property_accessors, Object, kPropertyAccessorsOffset)

ACCESSORS(FunctionTemplateInfo, call_code, Object, kCallCodeOffset)
ACCESSORS(FunctionTemplateInfo, class_name, Object, kClassNameOffset)
ACCESSORS(FunctionTemplateInfo, signature, Object, kSignatureOffset)
ACCESSORS(FunctionTemplateInfo, shared_function_info, Object,
          kSharedFunctionInfoOffset)
38 39
ACCESSORS(FunctionTemplateInfo, rare_data, HeapObject,
          kFunctionTemplateRareDataOffset)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
ACCESSORS(FunctionTemplateInfo, cached_property_name, Object,
          kCachedPropertyNameOffset)
SMI_ACCESSORS(FunctionTemplateInfo, length, kLengthOffset)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable, kUndetectableBit)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check,
               kNeedsAccessCheckBit)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, read_only_prototype,
               kReadOnlyPrototypeBit)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, remove_prototype,
               kRemovePrototypeBit)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, do_not_cache, kDoNotCacheBit)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, accept_any_receiver,
               kAcceptAnyReceiver)
SMI_ACCESSORS(FunctionTemplateInfo, flag, kFlagOffset)

55
// static
56
FunctionTemplateRareData FunctionTemplateInfo::EnsureFunctionTemplateRareData(
57
    Isolate* isolate, Handle<FunctionTemplateInfo> function_template_info) {
58
  HeapObject extra = function_template_info->rare_data(isolate);
59
  if (extra.IsUndefined(isolate)) {
60 61 62 63 64 65
    return AllocateFunctionTemplateRareData(isolate, function_template_info);
  } else {
    return FunctionTemplateRareData::cast(extra);
  }
}

66
#define RARE_ACCESSORS(Name, CamelName, Type)                                 \
67 68 69
  DEF_GETTER(FunctionTemplateInfo, Get##CamelName, Type) {                    \
    HeapObject extra = rare_data(isolate);                                    \
    HeapObject undefined = GetReadOnlyRoots(isolate).undefined_value();       \
70 71 72 73 74 75 76 77 78
    return extra == undefined ? undefined                                     \
                              : FunctionTemplateRareData::cast(extra).Name(); \
  }                                                                           \
  inline void FunctionTemplateInfo::Set##CamelName(                           \
      Isolate* isolate, Handle<FunctionTemplateInfo> function_template_info,  \
      Handle<Type> Name) {                                                    \
    FunctionTemplateRareData rare_data =                                      \
        EnsureFunctionTemplateRareData(isolate, function_template_info);      \
    rare_data.set_##Name(*Name);                                              \
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
  }

RARE_ACCESSORS(prototype_template, PrototypeTemplate, Object)
RARE_ACCESSORS(prototype_provider_template, PrototypeProviderTemplate, Object)
RARE_ACCESSORS(parent_template, ParentTemplate, Object)
RARE_ACCESSORS(named_property_handler, NamedPropertyHandler, Object)
RARE_ACCESSORS(indexed_property_handler, IndexedPropertyHandler, Object)
RARE_ACCESSORS(instance_template, InstanceTemplate, Object)
RARE_ACCESSORS(instance_call_handler, InstanceCallHandler, Object)
RARE_ACCESSORS(access_check_info, AccessCheckInfo, Object)
#undef RARE_ACCESSORS

ACCESSORS(FunctionTemplateRareData, prototype_template, Object,
          kPrototypeTemplateOffset)
ACCESSORS(FunctionTemplateRareData, prototype_provider_template, Object,
          kPrototypeProviderTemplateOffset)
ACCESSORS(FunctionTemplateRareData, parent_template, Object,
          kParentTemplateOffset)
ACCESSORS(FunctionTemplateRareData, named_property_handler, Object,
          kNamedPropertyHandlerOffset)
ACCESSORS(FunctionTemplateRareData, indexed_property_handler, Object,
          kIndexedPropertyHandlerOffset)
ACCESSORS(FunctionTemplateRareData, instance_template, Object,
          kInstanceTemplateOffset)
ACCESSORS(FunctionTemplateRareData, instance_call_handler, Object,
          kInstanceCallHandlerOffset)
ACCESSORS(FunctionTemplateRareData, access_check_info, Object,
          kAccessCheckInfoOffset)

108 109 110
ACCESSORS(ObjectTemplateInfo, constructor, Object, kConstructorOffset)
ACCESSORS(ObjectTemplateInfo, data, Object, kDataOffset)

111 112 113 114
CAST_ACCESSOR(TemplateInfo)
CAST_ACCESSOR(FunctionTemplateInfo)
CAST_ACCESSOR(FunctionTemplateRareData)
CAST_ACCESSOR(ObjectTemplateInfo)
115 116

bool FunctionTemplateInfo::instantiated() {
117
  return shared_function_info().IsSharedFunctionInfo();
118 119 120
}

bool FunctionTemplateInfo::BreakAtEntry() {
121
  Object maybe_shared = shared_function_info();
122
  if (maybe_shared.IsSharedFunctionInfo()) {
123
    SharedFunctionInfo shared = SharedFunctionInfo::cast(maybe_shared);
124
    return shared.BreakAtEntry();
125 126 127 128
  }
  return false;
}

129
FunctionTemplateInfo FunctionTemplateInfo::GetParent(Isolate* isolate) {
130
  Object parent = GetParentTemplate();
131 132
  return parent.IsUndefined(isolate) ? FunctionTemplateInfo()
                                     : FunctionTemplateInfo::cast(parent);
133 134
}

135
ObjectTemplateInfo ObjectTemplateInfo::GetParent(Isolate* isolate) {
136
  Object maybe_ctor = constructor();
137
  if (maybe_ctor.IsUndefined(isolate)) return ObjectTemplateInfo();
138
  FunctionTemplateInfo constructor = FunctionTemplateInfo::cast(maybe_ctor);
139
  while (true) {
140
    constructor = constructor.GetParent(isolate);
141
    if (constructor.is_null()) return ObjectTemplateInfo();
142 143
    Object maybe_obj = constructor.GetInstanceTemplate();
    if (!maybe_obj.IsUndefined(isolate)) {
144 145 146
      return ObjectTemplateInfo::cast(maybe_obj);
    }
  }
147
  return ObjectTemplateInfo();
148 149 150
}

int ObjectTemplateInfo::embedder_field_count() const {
151
  Object value = data();
152
  DCHECK(value.IsSmi());
153 154 155 156 157 158 159 160 161 162
  return EmbedderFieldCount::decode(Smi::ToInt(value));
}

void ObjectTemplateInfo::set_embedder_field_count(int count) {
  DCHECK_LE(count, JSObject::kMaxEmbedderFields);
  return set_data(
      Smi::FromInt(EmbedderFieldCount::update(Smi::ToInt(data()), count)));
}

bool ObjectTemplateInfo::immutable_proto() const {
163
  Object value = data();
164
  DCHECK(value.IsSmi());
165 166 167 168 169 170 171 172
  return IsImmutablePrototype::decode(Smi::ToInt(value));
}

void ObjectTemplateInfo::set_immutable_proto(bool immutable) {
  return set_data(Smi::FromInt(
      IsImmutablePrototype::update(Smi::ToInt(data()), immutable)));
}

173
bool FunctionTemplateInfo::IsTemplateFor(JSObject object) {
174
  return IsTemplateFor(object.map());
175 176 177 178 179 180 181 182
}

}  // namespace internal
}  // namespace v8

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

#endif  // V8_OBJECTS_TEMPLATES_INL_H_