2014-04-01 11:16:13 +00:00
|
|
|
// Copyright 2014 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.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/property.h"
|
2014-04-01 11:16:13 +00:00
|
|
|
|
2016-02-16 13:28:12 +00:00
|
|
|
#include "src/field-type.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/handles-inl.h"
|
2017-01-09 13:43:28 +00:00
|
|
|
#include "src/objects-inl.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/ostreams.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-10-23 11:31:33 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os,
|
|
|
|
const PropertyAttributes& attributes) {
|
|
|
|
os << "[";
|
|
|
|
os << (((attributes & READ_ONLY) == 0) ? "W" : "_"); // writable
|
|
|
|
os << (((attributes & DONT_ENUM) == 0) ? "E" : "_"); // enumerable
|
|
|
|
os << (((attributes & DONT_DELETE) == 0) ? "C" : "_"); // configurable
|
|
|
|
os << "]";
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2016-12-21 16:40:00 +00:00
|
|
|
Descriptor Descriptor::DataField(Handle<Name> key, int field_index,
|
|
|
|
PropertyAttributes attributes,
|
|
|
|
Representation representation) {
|
2017-01-19 12:02:07 +00:00
|
|
|
return DataField(key, field_index, attributes, kMutable, representation,
|
|
|
|
FieldType::Any(key->GetIsolate()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Descriptor Descriptor::DataField(Handle<Name> key, int field_index,
|
|
|
|
PropertyAttributes attributes,
|
|
|
|
PropertyConstness constness,
|
|
|
|
Representation representation,
|
|
|
|
Handle<Object> wrapped_field_type) {
|
|
|
|
DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeakCell());
|
|
|
|
PropertyDetails details(kData, attributes, kField, constness, representation,
|
|
|
|
field_index);
|
|
|
|
return Descriptor(key, wrapped_field_type, details);
|
2016-12-21 16:40:00 +00:00
|
|
|
}
|
2014-10-23 11:31:33 +00:00
|
|
|
|
2017-02-10 08:05:25 +00:00
|
|
|
Descriptor Descriptor::DataConstant(Handle<Name> key, int field_index,
|
|
|
|
Handle<Object> value,
|
|
|
|
PropertyAttributes attributes) {
|
|
|
|
if (FLAG_track_constant_fields) {
|
|
|
|
Handle<Object> any_type(FieldType::Any(), key->GetIsolate());
|
|
|
|
return DataField(key, field_index, attributes, kConst,
|
|
|
|
Representation::Tagged(), any_type);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return Descriptor(key, value, kData, attributes, kDescriptor, kConst,
|
|
|
|
value->OptimalRepresentation(), field_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-19 11:45:17 +00:00
|
|
|
// Outputs PropertyDetails as a dictionary details.
|
2017-01-12 21:22:48 +00:00
|
|
|
void PropertyDetails::PrintAsSlowTo(std::ostream& os) {
|
2014-10-23 11:31:33 +00:00
|
|
|
os << "(";
|
2017-01-19 12:02:07 +00:00
|
|
|
if (constness() == kConst) os << "const ";
|
2017-01-12 21:22:48 +00:00
|
|
|
os << (kind() == kData ? "data" : "accessor");
|
2017-03-02 14:54:45 +00:00
|
|
|
os << ", dict_index: " << dictionary_index();
|
2017-01-12 21:22:48 +00:00
|
|
|
os << ", attrs: " << attributes() << ")";
|
2014-11-19 11:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Outputs PropertyDetails as a descriptor array details.
|
2017-01-12 21:22:48 +00:00
|
|
|
void PropertyDetails::PrintAsFastTo(std::ostream& os, PrintMode mode) {
|
2014-11-19 11:45:17 +00:00
|
|
|
os << "(";
|
2017-01-19 12:02:07 +00:00
|
|
|
if (constness() == kConst) os << "const ";
|
2017-01-12 21:22:48 +00:00
|
|
|
os << (kind() == kData ? "data" : "accessor");
|
|
|
|
if (location() == kField) {
|
|
|
|
os << " field";
|
|
|
|
if (mode & kPrintFieldIndex) {
|
|
|
|
os << " " << field_index();
|
|
|
|
}
|
|
|
|
if (mode & kPrintRepresentation) {
|
|
|
|
os << ":" << representation().Mnemonic();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
os << " descriptor";
|
|
|
|
}
|
|
|
|
if (mode & kPrintPointer) {
|
|
|
|
os << ", p: " << pointer();
|
2014-10-23 11:31:33 +00:00
|
|
|
}
|
2017-01-12 21:22:48 +00:00
|
|
|
if (mode & kPrintAttributes) {
|
|
|
|
os << ", attrs: " << attributes();
|
2014-12-16 13:22:23 +00:00
|
|
|
}
|
2017-01-12 21:22:48 +00:00
|
|
|
os << ")";
|
2014-11-19 11:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef OBJECT_PRINT
|
|
|
|
void PropertyDetails::Print(bool dictionary_mode) {
|
|
|
|
OFStream os(stdout);
|
|
|
|
if (dictionary_mode) {
|
2017-01-12 21:22:48 +00:00
|
|
|
PrintAsSlowTo(os);
|
2014-11-19 11:45:17 +00:00
|
|
|
} else {
|
2017-01-12 21:22:48 +00:00
|
|
|
PrintAsFastTo(os, PrintMode::kPrintFull);
|
2014-11-19 11:45:17 +00:00
|
|
|
}
|
|
|
|
os << "\n" << std::flush;
|
2014-10-23 11:31:33 +00:00
|
|
|
}
|
2014-11-19 11:45:17 +00:00
|
|
|
#endif
|
2014-10-23 11:31:33 +00:00
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|