Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with top-level-await with class variable init #1260

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/parser/ScriptParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ ScriptParser::InitializeScriptResult ScriptParser::initializeScript(String* orig
if (LIKELY(needByteCodeGeneration)) {
try {
#if defined(ENABLE_CODE_CACHE)
// give up if there is top-level-await
if (topCodeBlock->isAsync()) {
cacheable = false;
deleteCodeBlockCacheInfo();
}

// Store cache
if (cacheable) {
codeCache->prepareCacheWriting(srcHash);
Expand Down
56 changes: 29 additions & 27 deletions src/runtime/ExecutionPauser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,43 +74,45 @@ ExecutionPauser::ExecutionPauser(ExecutionState& state, Object* sourceObject, Ex
{
}

class ExecutionPauserExecutionStateParentBinder {
public:
ExecutionPauserExecutionStateParentBinder(ExecutionState& state, ExecutionState* originalState)
: m_originalState(originalState)
{
m_oldParent = m_originalState->parent();


ExecutionState* pstate = m_originalState;
while (pstate) {
if (pstate == &state) {
// AsyncGeneratorObject::asyncGeneratorResolve can make loop
return;

Value ExecutionPauser::start(ExecutionState& state, ExecutionPauser* self, Object* source, const Value& resumeValue, bool isAbruptReturn, bool isAbruptThrow, StartFrom from)
{
class ExecutionPauserExecutionStateParentAndStackLimitBinder {
public:
ExecutionPauserExecutionStateParentAndStackLimitBinder(ExecutionState& state, ExecutionState* originalState)
: m_originalState(originalState)
{
m_oldParent = m_originalState->parent();

ExecutionState* pstate = m_originalState;
m_originalState->m_stackLimit = state.context()->vmInstance()->stackLimit();
while (pstate) {
if (pstate == &state) {
// AsyncGeneratorObject::asyncGeneratorResolve can make loop
return;
}
pstate = pstate->parent();
}
pstate = pstate->parent();
}

m_originalState->setParent(&state);
}
m_originalState->setParent(&state);
}

~ExecutionPauserExecutionStateParentBinder()
{
m_originalState->setParent(m_oldParent);
}
~ExecutionPauserExecutionStateParentAndStackLimitBinder()
{
m_originalState->setParent(m_oldParent);
m_originalState->m_stackLimit = 0;
}

ExecutionState* m_originalState;
ExecutionState* m_oldParent;
};
ExecutionState* m_originalState;
ExecutionState* m_oldParent;
};

Value ExecutionPauser::start(ExecutionState& state, ExecutionPauser* self, Object* source, const Value& resumeValue, bool isAbruptReturn, bool isAbruptThrow, StartFrom from)
{
ExecutionState* originalState = self->m_executionState;
while (!originalState->pauseSource()) {
originalState = originalState->parent();
}

ExecutionPauserExecutionStateParentBinder parentBinder(state, originalState);
ExecutionPauserExecutionStateParentAndStackLimitBinder parentBinder(state, originalState);

if (self->m_resumeValueIndex != REGISTER_LIMIT) {
self->m_registerFile[self->m_resumeValueIndex] = resumeValue;
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/ExecutionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ bool ExecutionState::inPauserScope()
auto env = state->lexicalEnvironment();
auto record = env->record();
if (record->isGlobalEnvironmentRecord() || record->isModuleEnvironmentRecord()) {
return state->hasRareData() && state->rareData()->m_pauseSource;
// class variable initializer can call {GlobalEnvironment, ModuleEnvironment}
// so we should check above of {GlobalEnvironment, ModuleEnvironment}
if (state->hasRareData() && state->rareData()->m_pauseSource) {
return true;
}
} else if (record->isDeclarativeEnvironmentRecord() && record->asDeclarativeEnvironmentRecord()->isFunctionEnvironmentRecord()) {
return record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->functionObject()->isScriptGeneratorFunctionObject()
|| record->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->functionObject()->isScriptAsyncFunctionObject()
Expand Down
2 changes: 1 addition & 1 deletion test/vendortest