28using InnerScopeCallsEvalField = ScopeSloppyEvalCanExtendVarsBit::Next<bool, 1>;
29using NeedsPrivateNameContextChainRecalcField =
30 InnerScopeCallsEvalField::Next<bool, 1>;
31using ShouldSaveClassVariableIndexField =
32 NeedsPrivateNameContextChainRecalcField::Next<bool, 1>;
35using VariableContextAllocatedField = VariableMaybeAssignedField::Next<bool, 1>;
37using HasDataField = base::BitField<bool, 0, 1>;
38using LengthEqualsParametersField = HasDataField::Next<bool, 1>;
39using NumberOfParametersField = LengthEqualsParametersField::Next<uint16_t, 16>;
42using UsesSuperField = LanguageField::Next<bool, 1>;
94 std::vector<void*>* children_buffer)
97 children_buffer_(children_buffer),
98 function_scope_(nullptr),
100 num_inner_functions_(0),
101 num_inner_with_data_(0),
117 preparser_->set_preparse_data_builder(
parent);
120 if (
parent ==
nullptr)
return;
121 if (!
builder_->HasDataForParent())
return;
136 uint8_t* raw_zone_data =
142 is_finalized_ =
true;
150 if (capacity >= bytes)
return;
151 size_t delta = bytes - capacity;
160 (*byte_data_)[
index_++] = byte;
164void PreparseDataBuilder::ByteData::WriteUint32(uint32_t data) {
168 Add((data >> 8) & 0xFF);
169 Add((data >> 16) & 0xFF);
170 Add((data >> 24) & 0xFF);
171 free_quarters_in_last_byte_ = 0;
174void PreparseDataBuilder::ByteData::SaveCurrentSizeAtFirstUint32() {
175 int current_length =
length();
178 WriteUint32(current_length);
190 uint8_t next_byte = (data & 0x7F);
193 if (data) next_byte |= 0x80;
194 Add(next_byte & 0xFF);
197 Add(kVarint32EndMarker);
199 free_quarters_in_last_byte_ = 0;
209 free_quarters_in_last_byte_ = 0;
215 if (free_quarters_in_last_byte_ == 0) {
221 free_quarters_in_last_byte_ = 3;
223 --free_quarters_in_last_byte_;
226 uint8_t shift_amount = free_quarters_in_last_byte_ * 2;
228 (*byte_data_)[
index_ - 1] |= (data << shift_amount);
233 int num_inner_functions) {
235 builder_->function_scope_ = function_scope;
237 builder_->function_length_ = function_length;
238 builder_->num_inner_functions_ = num_inner_functions;
239 builder_->parent_->has_data_ =
true;
253 DCHECK(!finalized_children_);
258 DCHECK(!finalized_children_);
264 finalized_children_ =
true;
295 bool has_data = builder->
HasData();
296 bool length_equals_parameters =
298 uint32_t has_data_and_num_parameters =
299 HasDataField::encode(has_data) |
300 LengthEqualsParametersField::encode(length_equals_parameters) |
301 NumberOfParametersField::encode(function_scope->
num_parameters());
303 if (!length_equals_parameters) {
308 uint8_t language_and_super =
328 DCHECK(finalized_children_);
365 uint8_t scope_data_flags =
366 ScopeSloppyEvalCanExtendVarsBit::encode(
370 NeedsPrivateNameContextChainRecalcField::encode(
374 ShouldSaveClassVariableIndexField::encode(
400 for (
int i = 0;
i < name->
length(); ++
i) {
405 uint8_t variable_data = VariableMaybeAssignedField::encode(
407 VariableContextAllocatedField::encode(
419 if (inner->IsSkippableFunctionScope()) {
432 Isolate* isolate,
int children_length) {
434 int data_length = zone_byte_data_.length();
436 isolate->factory()->NewPreparseData(data_length, children_length);
437 data->copy_in(0, zone_byte_data_.begin(), data_length);
444 int data_length = zone_byte_data_.length();
446 isolate->factory()->NewPreparseData(data_length, children_length);
447 data->copy_in(0, zone_byte_data_.begin(), data_length);
453 DCHECK(!ThisOrParentBailedOut());
457 DCHECK(finalized_children_);
459 if (!builder->HasData())
continue;
461 data->set_child(
i++, *child_data);
469 DCHECK(!ThisOrParentBailedOut());
473 DCHECK(finalized_children_);
475 if (!builder->HasData())
continue;
477 data->set_child(
i++, *child_data);
485 DCHECK(!ThisOrParentBailedOut());
488 DCHECK(finalized_children_);
490 if (!builder->HasData())
continue;
492 data->set_child(
i++, child);
506 return builder_->Serialize(isolate);
510 return builder_->Serialize(isolate);
534 isolate->heap()->ContainsLocalHandle(
data_.location()));
552 return data_->Serialize(isolate);
556 return data_->Serialize(isolate);
561 data_->byte_data()->size());
587 Zone* zone,
int start_position,
int* end_position,
int* num_parameters,
588 int* function_length,
int* num_inner_functions,
bool* uses_super_property,
593 CHECK(scope_data_->HasRemainingBytes(
595 int start_position_from_data = scope_data_->ReadVarint32();
596 CHECK_EQ(start_position, start_position_from_data);
597 *end_position = scope_data_->ReadVarint32();
598 DCHECK_GT(*end_position, start_position);
600 uint32_t has_data_and_num_parameters = scope_data_->ReadVarint32();
601 bool has_data = HasDataField::decode(has_data_and_num_parameters);
603 NumberOfParametersField::decode(has_data_and_num_parameters);
604 bool length_equals_parameters =
605 LengthEqualsParametersField::decode(has_data_and_num_parameters);
606 if (length_equals_parameters) {
607 *function_length = *num_parameters;
609 *function_length = scope_data_->ReadVarint32();
611 *num_inner_functions = scope_data_->ReadVarint32();
613 uint8_t language_and_super = scope_data_->ReadQuarter();
614 *language_mode =
LanguageMode(LanguageField::decode(language_and_super));
615 *uses_super_property = UsesSuperField::decode(language_and_super);
617 if (!has_data)
return nullptr;
622 return GetChildData(zone, child_index_++);
632 int magic_value_from_data = scope_data_->ReadUint32();
634 DCHECK_EQ(magic_value_from_data, ByteData::kMagicValue);
636 int start_position_from_data = scope_data_->ReadUint32();
637 int end_position_from_data = scope_data_->ReadUint32();
642 RestoreDataForScope(scope, ast_value_factory, zone);
645 DCHECK_EQ(scope_data_->RemainingBytes(), 0);
648template <
typename Data>
665 uint32_t scope_data_flags = scope_data_->ReadUint8();
666 if (ScopeSloppyEvalCanExtendVarsBit::decode(scope_data_flags)) {
669 if (InnerScopeCallsEvalField::decode(scope_data_flags)) {
672 if (NeedsPrivateNameContextChainRecalcField::decode(scope_data_flags)) {
675 if (ShouldSaveClassVariableIndexField::decode(scope_data_flags)) {
681 if (var ==
nullptr) {
684 ast_value_factory, ast_value_factory->empty_string(),
699 if (function !=
nullptr) RestoreDataForVariable(function);
705 RestoreDataForInnerScopes(scope, ast_value_factory, zone);
708template <
typename Data>
712 bool data_one_byte = scope_data_->ReadUint8();
714 DCHECK_EQ(scope_data_->ReadUint32(),
static_cast<uint32_t
>(name->length()));
715 if (!name->is_one_byte() && data_one_byte) {
718 for (
int i = 0;
i < 2 * name->
length();
i += 2) {
719#if defined(V8_TARGET_LITTLE_ENDIAN)
720 DCHECK_EQ(scope_data_->ReadUint8(), name->raw_data()[
i]);
723 DCHECK_EQ(scope_data_->ReadUint8(), name->raw_data()[
i + 1]);
728 for (
int i = 0;
i < name->
length(); ++
i) {
729 DCHECK_EQ(scope_data_->ReadUint8(), name->raw_data()[
i]);
733 uint8_t variable_data = scope_data_->ReadQuarter();
734 if (VariableMaybeAssignedField::decode(variable_data)) {
737 if (VariableContextAllocatedField::decode(variable_data)) {
743template <
typename Data>
748 RestoreDataForScope(inner, ast_value_factory, zone);
755 typename ByteData::ReadingScope reading_scope(
this);
757 int scope_data_start = scope_data_->ReadUint32();
758 scope_data_->SetPosition(scope_data_start);
759 CHECK_EQ(scope_data_->ReadUint32(), ByteData::kMagicValue);
783 DCHECK(IsPreparseData(*data));
784 DCHECK(VerifyDataStart());
789 : byte_data_(byte_data->begin(), byte_data->
end(), zone),
796 isolate->factory()->NewPreparseData(data_size, child_data_length);
799 for (
int i = 0;
i < child_data_length;
i++) {
803 result->set_child(
i, *child_data);
812 isolate->factory()->NewPreparseData(data_size, child_data_length);
815 for (
int i = 0;
i < child_data_length;
i++) {
819 result->set_child(
i, *child_data);
826 :
data_(data), scope_data_wrapper_(
data_->byte_data()) {
827 DCHECK(VerifyDataStart());
838 if (child_data ==
nullptr)
return nullptr;
850 return std::make_unique<OnHeapConsumedPreparseData>(isolate, data);
855 if (data ==
nullptr)
return {};
856 return std::make_unique<ZoneConsumedPreparseData>(zone, data);
uint8_t data_[MAX_STACK_LENGTH]
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
VariableDeclaration * NewVariableDeclaration(int pos)
void RestoreDataForVariable(Variable *var)
void RestoreDataForScope(Scope *scope, AstValueFactory *ast_value_factory, Zone *zone)
void RestoreDataForInnerScopes(Scope *scope, AstValueFactory *ast_value_factory, Zone *zone)
void RestoreScopeAllocationData(DeclarationScope *scope, AstValueFactory *ast_value_factory, Zone *zone) final
ProducedPreparseData * GetDataForSkippableFunction(Zone *zone, int start_position, int *end_position, int *num_parameters, int *function_length, int *num_inner_functions, bool *uses_super_property, LanguageMode *language_mode) final
Handle< PreparseData > Serialize(Isolate *isolate) final
PreparseDataBuilder * builder_
ZonePreparseData * Serialize(Zone *zone) final
Handle< PreparseData > Serialize(LocalIsolate *isolate) final
BuilderProducedPreparseData(PreparseDataBuilder *builder)
bool should_save_class_variable_index() const
Variable * DeclareClassVariable(AstValueFactory *ast_value_factory, const AstRawString *name, int class_token_pos)
bool is_anonymous_class() const
Variable * class_variable()
void set_should_save_class_variable_index()
static V8_EXPORT_PRIVATE std::unique_ptr< ConsumedPreparseData > For(Isolate *isolate, Handle< PreparseData > data)
bool uses_super_property() const
FunctionKind function_kind() const
Variable * function_var() const
bool needs_private_name_context_chain_recalc() const
void RecordNeedsPrivateNameContextChainRecalc()
bool is_skipped_function() const
int num_parameters() const
bool sloppy_eval_can_extend_vars() const
void set_preparse_data_builder(PreparseDataBuilder *preparse_data_builder)
Tagged< PreparseData > GetScopeData() final
OnHeapConsumedPreparseData(LocalIsolate *isolate, Handle< PreparseData > data)
ProducedPreparseData * GetChildData(Zone *zone, int child_index) final
OnHeapProducedPreparseData(Handle< PreparseData > data)
Handle< PreparseData > Serialize(LocalIsolate *isolate) final
ZonePreparseData * Serialize(Zone *zone) final
Handle< PreparseData > Serialize(Isolate *isolate) final
Handle< PreparseData > data_
std::vector< uint8_t > * preparse_data_buffer()
std::vector< void * > * preparse_data_builder_buffer()
PreparseDataBuilder * preparse_data_builder() const
void set_preparse_data_builder(PreparseDataBuilder *preparse_data_builder)
void WriteQuarter(uint8_t data)
Handle< PreparseData > CopyToLocalHeap(LocalIsolate *isolate, int children_length)
ZonePreparseData * CopyToZone(Zone *zone, int children_length)
void Finalize(Zone *zone)
void WriteUint8(uint8_t data)
void WriteVarint32(uint32_t data)
void Reserve(size_t bytes)
Handle< PreparseData > CopyToHeap(Isolate *isolate, int children_length)
void Start(std::vector< uint8_t > *buffer)
void SetSkippableFunction(DeclarationScope *function_scope, int function_length, int num_inner_functions)
void Start(DeclarationScope *function_scope)
PreparseDataBuilder * builder_
bool HasDataForParent() const
base::Vector< PreparseDataBuilder * > children_
static bool ScopeNeedsData(Scope *scope)
PreparseDataBuilder(Zone *zone, PreparseDataBuilder *parent_builder, std::vector< void * > *children_buffer)
void SaveScopeAllocationData(DeclarationScope *scope, Parser *parser)
DeclarationScope * function_scope_
PreparseDataBuilder * parent_
void SaveDataForInnerScopes(Scope *scope)
bool HasInnerFunctions() const
Handle< PreparseData > Serialize(Isolate *isolate)
ScopedPtrList< PreparseDataBuilder > children_buffer_
void AddChild(PreparseDataBuilder *child)
PreparseDataBuilder * parent() const
bool SaveDataForSkippableFunction(PreparseDataBuilder *builder)
void FinalizeChildren(Zone *zone)
void SaveDataForScope(Scope *scope)
void SaveDataForVariable(Variable *var)
static ProducedPreparseData * For(PreparseDataBuilder *builder, Zone *zone)
void RecordInnerScopeEvalCall()
base::ThreadedList< Declaration > * declarations()
DeclarationScope * AsDeclarationScope()
ClassScope * AsClassScope()
base::ThreadedList< Variable > * locals()
bool is_class_scope() const
bool is_function_scope() const
ScopeType scope_type() const
bool inner_scope_calls_eval() const
Scope * inner_scope() const
LanguageMode language_mode() const
int start_position() const
bool is_declaration_scope() const
MaybeAssignedFlag maybe_assigned() const
bool has_forced_context_allocation() const
const AstRawString * raw_name() const
void ForceContextAllocation()
ZoneConsumedPreparseData(Zone *zone, ZonePreparseData *data)
ZoneVectorWrapper GetScopeData() final
ProducedPreparseData * GetChildData(Zone *zone, int child_index) final
ZoneVectorWrapper scope_data_wrapper_
V8_EXPORT_PRIVATE ZonePreparseData(Zone *zone, base::Vector< uint8_t > *byte_data, int child_length)
int children_length() const
ZoneVector< uint8_t > * byte_data()
Handle< PreparseData > Serialize(Isolate *isolate)
ZonePreparseData * get_child(int index)
ZonePreparseData * Serialize(Zone *zone) final
Handle< PreparseData > Serialize(Isolate *isolate) final
ZoneProducedPreparseData(ZonePreparseData *data)
Handle< PreparseData > Serialize(LocalIsolate *isolate) final
T * AllocateArray(size_t length)
std::vector< std::unique_ptr< InstanceTypeTree > > children
ZoneVector< RpoNumber > & result
BitField< T, shift, size, uint8_t > BitField8
constexpr int kNoSourcePosition
bool IsSerializableVariableMode(VariableMode mode)
base::Vector< T > CloneVector(Zone *zone, base::Vector< const T > other)
bool IsDefaultConstructor(FunctionKind kind)
static const size_t LanguageModeSize
BytecodeSequenceNode * parent_
ZoneUnorderedMap< int, BytecodeSequenceNode * > children_
#define DCHECK_LE(v1, v2)
#define CHECK_GE(lhs, rhs)
#define CHECK_GT(lhs, rhs)
#define CHECK_LE(lhs, rhs)
#define DCHECK_NOT_NULL(val)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK_NE(v1, v2)
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
#define DCHECK_GT(v1, v2)
static constexpr size_t kUint32Size
static const size_t kSkippableFunctionMinDataSize
static constexpr size_t kPlaceholderSize
static const size_t kSkippableFunctionMaxDataSize
static constexpr size_t kUint8Size
static constexpr size_t kVarint32MinSize