41void AstNode::Print(Isolate* isolate) { AstPrinter::PrintOut(isolate,
this); }
45#define RETURN_NODE(Node) \
47 return static_cast<Node*>(this);
72 return IsLiteral() && AsLiteral()->IsNumber();
100 if (IsLiteral())
return true;
102 if (
literal ==
nullptr)
return false;
110 if (var_proxy ==
nullptr)
return false;
115 var_proxy->
raw_name()->IsOneByteEqualTo(
"undefined");
123 return IsLiteral() && AsLiteral()->ToBooleanIsTrue();
127 return IsLiteral() && AsLiteral()->ToBooleanIsFalse();
131 return IsVariableProxy() && AsVariableProxy()->IsPrivateName();
135 return IsProperty() ||
136 (IsVariableProxy() && AsVariableProxy()->IsValidReferenceExpression());
140 return (IsFunctionLiteral() &&
143 AsClassLiteral()->IsAnonymousFunctionDefinition());
156 raw_name_(var->raw_name()),
157 next_unresolved_(nullptr) {
167 next_unresolved_(nullptr) {
242 char* empty_str =
new char[1];
244 return std::unique_ptr<char[]>(empty_str);
248 std::vector<char> result_vec;
249 std::forward_list<const AstRawString*> strings = cons_string->
ToRawStrings();
251 if (!string->is_one_byte())
break;
252 for (
int i = 0;
i <
string->
length();
i++) {
253 result_vec.push_back(string->raw_data()[
i]);
256 std::unique_ptr<char[]>
result(
new char[result_vec.size() + 1]);
257 if (result_vec.size()) {
258 memcpy(
result.get(), result_vec.data(), result_vec.size());
260 result[result_vec.size()] =
'\0';
284 bool is_computed_name)
287 key->AsLiteral()->AsRawString() == ast_value_factory->proto_string()) {
290 kind_ = MATERIALIZED_LITERAL;
291 }
else if (
value_->IsLiteral()) {
306 bool is_computed_name,
310 is_static_(is_static),
311 is_private_(is_private),
312 private_or_computed_name_proxy_(nullptr) {}
317 bool is_computed_name,
321 is_static_(is_static),
322 is_private_(is_private),
323 auto_accessor_info_(info) {
347 if (property->is_computed_name())
continue;
348 if (property->IsPrototype())
continue;
352 uint32_t hash =
literal->Hash();
354 if (entry->
value ==
nullptr) {
373 bool complementary_accessors =
376 if (!complementary_accessors) {
377 property->set_emit_store(
false);
413 bool has_seen_prototype =
false;
416 uint32_t nof_properties = 0;
417 uint32_t elements = 0;
418 uint32_t max_element_index = 0;
421 if (property->IsPrototype()) {
422 has_seen_prototype =
true;
425 if (property->IsNullPrototype()) {
434 DCHECK(property->is_computed_name());
439 DCHECK(!property->is_computed_name());
458 uint32_t element_index = 0;
459 if (
key->AsArrayIndex(&element_index)) {
460 max_element_index = std::max(element_index, max_element_index);
474 ((2 * elements) >= max_element_index));
477template <
typename IsolateT>
483 bool has_seen_proto =
false;
486 if (property->IsPrototype()) {
487 has_seen_proto =
true;
490 if (property->is_computed_name())
continue;
493 if (!
key->IsPropertyName()) index_keys++;
497 isolate->factory()->NewObjectBoilerplateDescription(
504 if (property->IsPrototype())
continue;
507 DCHECK(property->is_computed_name());
510 DCHECK(!property->is_computed_name());
513 if (m_literal !=
nullptr) {
520 Literal* key_literal =
property->key()->AsLiteral();
521 uint32_t element_index = 0;
525 ->template NewNumberFromUint<AllocationType::kOld>(
554template <
typename IsolateT>
557 if (expression->IsLiteral()) {
558 return expression->AsLiteral()->BuildValue(isolate);
560 if (expression->IsCompileTimeValue()) {
561 if (expression->IsObjectLiteral()) {
562 ObjectLiteral* object_literal = expression->AsObjectLiteral();
564 return object_literal->
builder()->boilerplate_description();
566 DCHECK(expression->IsArrayLiteral());
567 ArrayLiteral* array_literal = expression->AsArrayLiteral();
569 return array_literal->
builder()->boilerplate_description();
572 return isolate->factory()->uninitialized_value();
584 int constants_length =
589 bool is_holey =
false;
593 for (; array_index < constants_length; array_index++) {
597 if (materialized_literal !=
nullptr) {
612 Literal*
literal = element->AsLiteral();
617 DCHECK(element->IsObjectLiteral() || element->IsArrayLiteral());
661template <
typename IsolateT>
666 int constants_length =
673 elements = isolate->factory()->NewFixedDoubleArray(constants_length,
676 elements = isolate->factory()->NewFixedArrayWithHoles(constants_length,
682 for (; array_index < constants_length; array_index++) {
684 DCHECK(!element->IsSpread());
704 if (m_literal !=
nullptr) {
709 typename IsolateT::HandleScopeType scope(isolate);
715 if (IsTheHole(boilerplate_value, isolate)) {
720 if (IsUninitialized(boilerplate_value, isolate)) {
737 elements->set_map_safe_transition(
742 isolate->factory()->NewArrayBoilerplateDescription(
kind, elements);
760 if (IsArrayLiteral())
return AsArrayLiteral()->builder()->is_simple();
761 if (IsObjectLiteral())
return AsObjectLiteral()->builder()->is_simple();
762 DCHECK(IsRegExpLiteral());
768 if (expr->IsArrayLiteral()) {
769 return expr->AsArrayLiteral()->builder()->InitDepthAndFlags();
771 if (expr->IsObjectLiteral()) {
772 return expr->AsObjectLiteral()->builder()->InitDepthAndFlags();
774 DCHECK(expr->IsRegExpLiteral());
780 if (IsArrayLiteral()) {
781 return AsArrayLiteral()->builder()->needs_initial_allocation_site();
783 if (IsObjectLiteral()) {
784 return AsObjectLiteral()->builder()->needs_initial_allocation_site();
786 DCHECK(IsRegExpLiteral());
790template <
typename IsolateT>
793 if (expr->IsArrayLiteral()) {
794 expr->AsArrayLiteral()->builder()->BuildBoilerplateDescription(isolate);
797 if (expr->IsObjectLiteral()) {
798 expr->AsObjectLiteral()->builder()->BuildBoilerplateDescription(isolate);
801 DCHECK(expr->IsRegExpLiteral());
808template <
typename IsolateT>
814 bool raw_and_cooked_match =
true;
828 raw_and_cooked_match =
false;
833 DirectHandle<FixedArray> cooked_strings_handle = raw_strings_handle;
834 if (!raw_and_cooked_match) {
835 cooked_strings_handle = isolate->factory()->NewFixedArray(
839 ReadOnlyRoots roots(isolate);
848 return isolate->factory()->NewTemplateObjectDescription(
849 raw_strings_handle, cooked_strings_handle);
856 LocalIsolate* isolate);
860 return op == Token::kMul || op == Token::kBitAnd || op == Token::kBitOr ||
861 op == Token::kBitXor;
867 if (right->IsSmiLiteral()) {
869 *
literal = right->AsLiteral()->AsSmiLiteral();
884 return maybe_unary !=
nullptr && maybe_unary->
op() == Token::kVoid &&
947 *expr = left->AsVariableProxy();
963 int first_spread_index = 0;
964 for (; first_spread_index < arguments_length; first_spread_index++) {
965 if (
arguments_.at(first_spread_index)->IsSpread())
break;
968 if (first_spread_index == arguments_length - 1) {
971 DCHECK_LT(first_spread_index, arguments_length - 1);
979 if (proxy !=
nullptr) {
993 bool is_optional_chain =
false;
995 is_optional_chain =
true;
996 property =
expression()->AsOptionalChain()->expression()->AsProperty();
998 if (property !=
nullptr) {
999 if (property->IsPrivateReference()) {
1003 bool is_super = property->IsSuperAccess();
1006 DCHECK(!is_super || !is_optional_chain);
1007 if (property->key()->IsPropertyName()) {
1023 :
label_(
label), statements_(statements.ToConstVector(), zone) {}
1028 return !
string_->AsArrayIndex(&index);
1034 return string_->AsArrayIndex(value);
1036 if (
smi_ < 0)
return false;
1037 *value =
static_cast<uint32_t
>(
smi_);
1050template <
typename IsolateT>
1056 return isolate->factory()->template NewNumber<AllocationType::kOld>(
1063 return isolate->factory()->ToBoolean(
boolean_);
1065 return isolate->factory()->null_value();
1067 return isolate->factory()->undefined_value();
1069 return isolate->factory()->the_hole_value();
1099 size_t length = strlen(bigint_str);
1101 if (length == 1 && bigint_str[0] ==
'0')
return false;
1104 for (
size_t i = (bigint_str[0] ==
'0') ? 2 : 0;
i <
length; ++
i) {
1105 if (bigint_str[
i] !=
'0')
return true;
1133 if (
x->AsArrayIndex(&index_x)) {
1134 return y->AsArrayIndex(&index_y) && index_x == index_y;
1136 return (
x->IsRawString() &&
y->IsRawString() &&
1137 x->AsRawString() ==
y->AsRawString()) ||
1138 (
x->IsNumber() &&
y->IsNumber() &&
x->AsNumber() ==
y->AsNumber());
#define LITERAL_NODE_LIST(V)
#define ITERATION_NODE_LIST(V)
#define RETURN_NODE(Node)
static constexpr U encode(T value)
static const uint32_t kDefaultHashMapCapacity
bool IsFastCloningSupported() const
const ZonePtrList< Expression > * values_
IndirectHandle< ArrayBoilerplateDescription > boilerplate_description_
void BuildBoilerplateDescription(IsolateT *isolate)
const ArrayLiteralBoilerplateBuilder * builder() const
Assignment(NodeType type, Token::Value op, Expression *target, Expression *value, int pos)
const char * c_str() const
Handle< String > AllocateFlat(IsolateT *isolate) const
std::forward_list< const AstRawString * > ToRawStrings() const
IndirectHandle< String > GetString(IsolateT *isolate)
Literal * NewNumberLiteral(double number, int pos)
Literal * NewSmiLiteral(int number, int pos)
MaterializedLiteral * AsMaterializedLiteral()
NodeType node_type() const
IterationStatement * AsIterationStatement()
bool IsSmiLiteralOperation(Expression **subexpr, Tagged< Smi > *literal)
void ComputeSpreadPosition()
ZonePtrList< Expression > arguments_
Expression * expression() const
CallType GetCallType() const
@ PRIVATE_OPTIONAL_CHAIN_CALL
@ KEYED_OPTIONAL_CHAIN_PROPERTY_CALL
@ NAMED_SUPER_PROPERTY_CALL
@ KEYED_SUPER_PROPERTY_CALL
@ NAMED_OPTIONAL_CHAIN_PROPERTY_CALL
CaseClause(Zone *zone, Expression *label, const ScopedPtrList< Statement > &statements)
ClassLiteralProperty(Expression *key, Expression *value, Kind kind, bool is_static, bool is_computed_name, bool is_private)
bool IsLiteralCompareEqualVariable(Expression **expr, Literal **literal)
bool IsLiteralStrictCompareBoolean(Expression **expr, Literal **literal)
bool IsLiteralCompareUndefined(Expression **expr)
bool IsLiteralCompareNull(Expression **expr)
static const int kMaximumClonedShallowArrayElements
static const int kMaximumClonedShallowObjectProperties
FunctionKind function_kind() const
bool class_scope_has_private_brand() const
bool ShouldEagerCompile() const
void set_should_eager_compile()
void set_has_inferred_function_name(bool value)
bool AllowsLazyCompilation() const
void set_class_scope_has_private_brand(bool value)
bool ToBooleanIsFalse() const
bool IsUndefinedLiteral() const
bool IsAccessorFunctionDefinition() const
bool IsBooleanLiteral() const
bool IsValidReferenceExpression() const
bool IsPrivateName() const
bool IsNullOrUndefinedLiteral() const
bool IsAnonymousFunctionDefinition() const
bool IsCompileTimeValue()
V8_EXPORT_PRIVATE bool IsNumberLiteral() const
bool IsStringLiteral() const
bool IsConsStringLiteral() const
bool ToBooleanIsTrue() const
bool IsTheHoleLiteral() const
bool IsNullLiteral() const
bool IsLiteralButNotNullOrUndefined() const
bool IsSmiLiteral() const
bool IsConciseMethodDefinition() const
bool IsPropertyName() const
FunctionKind kind() const
V8_EXPORT_PRIVATE void SetShouldEagerCompile()
void set_raw_inferred_name(AstConsString *raw_inferred_name)
Handle< SharedFunctionInfo > shared_function_info() const
void set_class_scope_has_private_brand(bool value)
V8_EXPORT_PRIVATE LanguageMode language_mode() const
const AstConsString * raw_name_
const AstConsString * raw_inferred_name()
bool AllowsLazyCompilation()
int start_position() const
AstConsString * raw_inferred_name_
IndirectHandle< SharedFunctionInfo > shared_function_info_
bool class_scope_has_private_brand() const
bool private_name_lookup_skips_outer_class() const
Handle< String > GetInferredName(Isolate *isolate)
DeclarationScope * scope() const
V8_EXPORT_PRIVATE bool ShouldEagerCompile() const
std::unique_ptr< char[]> GetDebugName() const
void set_shared_function_info(Handle< SharedFunctionInfo > shared_function_info)
const ZonePtrList< const AstRawString > * raw_strings() const
Handle< TemplateObjectDescription > GetOrBuildDescription(IsolateT *isolate)
const ZonePtrList< const AstRawString > * cooked_strings() const
void set_needs_initial_allocation_site(bool required)
void set_boilerplate_descriptor_kind(ElementsKind kind)
ElementsKind boilerplate_descriptor_kind() const
bool is_initialized() const
int ComputeFlags(bool disable_mementos=false) const
void set_is_simple(bool is_simple)
static DirectHandle< Object > GetBoilerplateValue(Expression *expression, IsolateT *isolate)
bool needs_initial_allocation_site() const
void BuildConstants(IsolateT *isolate, MaterializedLiteral *expr)
static void InitDepthAndFlags(MaterializedLiteral *expr)
void set_depth(DepthKind depth)
bool NeedsSetFunctionName() const
bool is_computed_name() const
bool AsArrayIndex(uint32_t *index) const
static bool Match(void *literal1, void *literal2)
bool ToUint32(uint32_t *value) const
const AstRawString * AsRawPropertyName()
DirectHandle< Object > BuildValue(IsolateT *isolate) const
bool IsPropertyName() const
const AstRawString * AsRawString()
V8_EXPORT_PRIVATE bool ToBooleanIsTrue() const
const AstRawString * string_
AstConsString * cons_string_
bool NeedsInitialAllocationSite()
void set_has_elements(bool has_elements)
const ZonePtrList< Property > * properties() const
void BuildBoilerplateDescription(IsolateT *isolate)
int properties_count() const
uint32_t boilerplate_properties_
bool has_null_prototype() const
void InitFlagsForPendingNullPrototype(int i)
bool IsFastCloningSupported() const
DirectHandle< ObjectBoilerplateDescription > boilerplate_description() const
bool fast_elements() const
IndirectHandle< ObjectBoilerplateDescription > boilerplate_description_
int ComputeFlags(bool disable_mementos=false) const
void set_has_null_protoype(bool has_null_prototype)
void set_fast_elements(bool fast_elements)
void set_emit_store(bool emit_store)
bool IsCompileTimeValue() const
ObjectLiteralProperty(Expression *key, Expression *value, Kind kind, bool is_computed_name)
const ObjectLiteralBoilerplateBuilder * builder() const
ZoneList< Property * > * properties()
void CalculateEmitStore(Zone *zone)
static ElementsKind OptimalElementsKind(Tagged< Object > obj, PtrComprCageBase cage_base)
bool private_name_lookup_skips_outer_class() const
LanguageMode language_mode() const
int start_position() const
static constexpr Tagged< Smi > FromInt(int value)
static constexpr Tagged< Smi > zero()
static bool IsEqualityOp(Value op)
Expression * expression() const
void BindTo(Variable *var)
const AstRawString * raw_name() const
VariableProxy(Variable *var, int start_position)
void set_var(Variable *v)
const AstRawString * raw_name_
VariableMode mode() const
bool IsLookupSlot() const
const AstRawString * raw_name() const
bool IsUnallocated() const
#define EXPORT_TEMPLATE_DEFINE(export)
std::optional< TNode< JSArray > > a
ZoneVector< RpoNumber > & result
FunctionLiteral * literal
constexpr uint64_t double_to_uint64(double d)
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
template EXPORT_TEMPLATE_DEFINE(V8_BASE_EXPORT) Handle< TemplateObjectDescription > GetTemplateObject template static EXPORT_TEMPLATE_DEFINE(V8_BASE_EXPORT) Handle< TemplateObjectDescription > GetTemplateObject bool IsCommutativeOperationWithSmiLiteral(Token::Value op)
static bool MatchSmiLiteralOperation(Expression *left, Expression *right, Expression **expr, Tagged< Smi > *literal)
static bool MatchLiteralCompareNull(Expression *left, Token::Value op, Expression *right, Expression **expr)
PerThreadAssertScopeDebugOnly< false, SAFEPOINTS_ASSERT, HEAP_ALLOCATION_ASSERT > DisallowGarbageCollection
uint32_t ComputeLongHash(uint64_t key)
constexpr bool IsHoleyElementsKind(ElementsKind kind)
bool DoubleToUint32IfEqualToSelf(double value, uint32_t *uint32_value)
bool DoubleToSmiInteger(double value, int *smi_int_value)
bool DoubleToBoolean(double d)
bool IsConciseMethod(FunctionKind kind)
kStaticElementsTemplateOffset kInstancePropertiesTemplateOffset Tagged< FixedArray >
MaybeHandle< BigInt > BigIntLiteral(IsolateT *isolate, const char *string)
bool IsAccessorFunction(FunctionKind kind)
@ FIRST_FAST_ELEMENTS_KIND
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
static bool MatchLiteralCompareEqualVariable(Expression *left, Token::Value op, Expression *right, Expression **expr, Literal **literal)
bool IsSmiOrObjectElementsKind(ElementsKind kind)
V8_INLINE PtrComprCageBase GetPtrComprCageBase()
ElementsKind GetHoleyElementsKind(ElementsKind packed_kind)
static bool MatchLiteralCompareUndefined(Expression *left, Token::Value op, Expression *right, Expression **expr)
static bool IsVoidOfLiteral(Expression *expr)
static bool MatchLiteralStrictCompareBoolean(Expression *left, Token::Value op, Expression *right, Expression **expr, Literal **literal)
constexpr bool IsDoubleElementsKind(ElementsKind kind)
ElementsKind GetMoreGeneralElementsKind(ElementsKind from_kind, ElementsKind to_kind)
constexpr uint32_t kMaxUInt32
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
static constexpr ReleaseStoreTag kReleaseStore
#define DCHECK_NOT_NULL(val)
#define DCHECK_IMPLIES(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)
#define V8_EXPORT_PRIVATE
#define V8_UNLIKELY(condition)