v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
property.cc
Go to the documentation of this file.
1// Copyright 2014 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
6
11#include "src/objects/smi.h"
12#include "src/utils/ostreams.h"
13
14namespace v8 {
15namespace internal {
16
17std::ostream& operator<<(std::ostream& os,
18 const Representation& representation) {
19 switch (representation.kind()) {
21 return os << "none";
23 return os << "smi";
25 return os << "double";
27 return os << "heap-object";
29 return os << "tagged";
31 return os << "wasm-value";
34 }
36}
37
38std::ostream& operator<<(std::ostream& os,
39 const PropertyAttributes& attributes) {
40 os << "[";
41 os << (((attributes & READ_ONLY) == 0) ? "W" : "_"); // writable
42 os << (((attributes & DONT_ENUM) == 0) ? "E" : "_"); // enumerable
43 os << (((attributes & DONT_DELETE) == 0) ? "C" : "_"); // configurable
44 os << "]";
45 return os;
46}
47
48std::ostream& operator<<(std::ostream& os, PropertyConstness constness) {
49 switch (constness) {
51 return os << "mutable";
53 return os << "const";
54 }
56}
57
58Descriptor::Descriptor() : details_(Smi::zero()) {}
59
62 PropertyAttributes attributes, PropertyLocation location,
63 PropertyConstness constness,
64 Representation representation, int field_index)
65 : key_(key),
66 value_(value),
67 details_(kind, attributes, location, constness, representation,
68 field_index) {
70 DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
71}
72
74 const MaybeObjectDirectHandle& value,
75 PropertyDetails details)
76 : key_(key), value_(value), details_(details) {
78 DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
79}
80
82 int field_index, PropertyAttributes attributes,
83 Representation representation) {
84 return DataField(key, field_index, attributes, PropertyConstness::kMutable,
85 representation,
87}
88
90 DirectHandle<Name> key, int field_index, PropertyAttributes attributes,
91 PropertyConstness constness, Representation representation,
92 const MaybeObjectDirectHandle& wrapped_field_type) {
93 DCHECK(IsSmi(*wrapped_field_type) || IsWeak(*wrapped_field_type));
94 PropertyDetails details(PropertyKind::kData, attributes,
95 PropertyLocation::kField, constness, representation,
96 field_index);
97 return Descriptor(key, wrapped_field_type, details);
98}
99
109
111 int field_index, DirectHandle<Object> value,
112 PropertyAttributes attributes) {
113 MaybeObjectDirectHandle any_type(FieldType::Any(), isolate);
114 return DataField(key, field_index, attributes, PropertyConstness::kConst,
115 Representation::Tagged(), any_type);
116}
117
126
127// Outputs PropertyDetails as a dictionary details.
128void PropertyDetails::PrintAsSlowTo(std::ostream& os, bool print_dict_index) {
129 os << "(";
130 if (constness() == PropertyConstness::kConst) os << "const ";
131 os << (kind() == PropertyKind::kData ? "data" : "accessor");
132 if (print_dict_index) {
133 os << ", dict_index: " << dictionary_index();
134 }
135 os << ", attrs: " << attributes() << ")";
136}
137
138// Outputs PropertyDetails as a descriptor array details.
139void PropertyDetails::PrintAsFastTo(std::ostream& os, PrintMode mode) {
140 os << "(";
141 if (constness() == PropertyConstness::kConst) os << "const ";
142 os << (kind() == PropertyKind::kData ? "data" : "accessor");
144 os << " field";
145 if (mode & kPrintFieldIndex) {
146 os << " " << field_index();
147 }
148 if (mode & kPrintRepresentation) {
149 os << ":" << representation().Mnemonic();
150 }
151 } else {
152 os << " descriptor";
153 }
154 if (mode & kPrintPointer) {
155 os << ", p: " << pointer();
156 }
157 if (mode & kPrintAttributes) {
158 os << ", attrs: " << attributes();
159 }
160 os << ")";
161}
162
163#ifdef OBJECT_PRINT
164void PropertyDetails::Print(bool dictionary_mode) {
165 StdoutStream os;
166 if (dictionary_mode) {
167 PrintAsSlowTo(os, true);
168 } else {
170 }
171 os << "\n" << std::flush;
172}
173#endif
174
175} // namespace internal
176} // namespace v8
Builtins::Kind kind
Definition builtins.cc:40
static Descriptor DataField(Isolate *isolate, DirectHandle< Name > key, int field_index, PropertyAttributes attributes, Representation representation)
Definition property.cc:81
static Descriptor AccessorConstant(DirectHandle< Name > key, DirectHandle< Object > foreign, PropertyAttributes attributes)
Definition property.cc:118
static Descriptor DataConstant(DirectHandle< Name > key, DirectHandle< Object > value, PropertyAttributes attributes)
Definition property.cc:100
PropertyDetails details_
Definition property.h:59
static V8_EXPORT_PRIVATE Tagged< FieldType > Any()
Definition field-type.cc:22
static Representation OptimalRepresentation(Tagged< Object > obj, PtrComprCageBase cage_base)
PropertyAttributes attributes() const
PropertyLocation location() const
Representation representation() const
void PrintAsFastTo(std::ostream &out, PrintMode mode=kPrintFull)
Definition property.cc:139
PropertyConstness constness() const
void PrintAsSlowTo(std::ostream &out, bool print_dict_index)
Definition property.cc:128
const char * Mnemonic() const
constexpr Kind kind() const
static constexpr Representation Tagged()
Register const value_
Handle< SharedFunctionInfo > key_
V8_INLINE constexpr bool IsWeak(TaggedImpl< HeapObjectReferenceType::WEAK, StorageType > obj)
Definition objects.h:673
V8_INLINE constexpr bool IsSmi(TaggedImpl< kRefType, StorageType > obj)
Definition objects.h:665
std::ostream & operator<<(std::ostream &os, AtomicMemoryOrder order)
V8_INLINE PtrComprCageBase GetPtrComprCageBase()
bool IsUniqueName(Tagged< Name > obj)
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK(condition)
Definition logging.h:482