Issue #2142 - Track isFieldInitializer on JSScript instead of Scope

Introduce a FunctionSyntaxKind for FieldInitializer since special rules
(around `arguments`) apply. At the same time we can move the flag from the
scope to the JSScript. This is similar to how derived constructors are handled
and makes the initWithEnclosingScope code closer to initWithEnclosingContext.

This version is a bit more complex than Mozilla's due to different storage of
bit flags on JSScript.

Based-on: m-c 1636800
This commit is contained in:
Martok 2023-04-11 03:02:33 +02:00 committed by roytam1
commit 22a9d46ef1
10 changed files with 77 additions and 48 deletions

View file

@ -1120,6 +1120,8 @@ class JSScript : public js::gc::TenuredCell
bool isDerivedClassConstructor_:1;
bool isDefaultClassConstructor_:1;
bool isFieldInitializer_:1;
bool isAsync_:1;
bool hasRest_:1;
@ -1129,7 +1131,10 @@ class JSScript : public js::gc::TenuredCell
// instead of private to suppress -Wunused-private-field compiler warnings.
protected:
#if JS_BITS_PER_WORD == 32
// Currently no padding is needed.
# ifndef DEBUG
// DEBUG is currently 4 bytes larger and doesn't need padding to gc::CellSize
uint32_t padding_;
# endif
#endif
//
@ -1458,6 +1463,10 @@ class JSScript : public js::gc::TenuredCell
return isDerivedClassConstructor_;
}
bool isFieldInitializer() const {
return isFieldInitializer_;
}
/*
* As an optimization, even when argsHasLocalBinding, the function prologue
* may not need to create an arguments object. This is determined by
@ -2096,6 +2105,7 @@ class LazyScript : public gc::TenuredCell
uint32_t hasBeenCloned : 1;
uint32_t treatAsRunOnce : 1;
uint32_t isDerivedClassConstructor : 1;
uint32_t isFieldInitializer : 1;
uint32_t needsHomeObject : 1;
uint32_t hasRest : 1;
uint32_t parseGoal : 1;
@ -2312,6 +2322,13 @@ class LazyScript : public gc::TenuredCell
p_.isDerivedClassConstructor = true;
}
bool isFieldInitializer() const {
return p_.isFieldInitializer;
}
void setIsFieldInitializer() {
p_.isFieldInitializer = true;
}
bool needsHomeObject() const {
return p_.needsHomeObject;
}