Fix read private property on inner object method

Signed-off-by: Seonghyun Kim <sh8281.kim@samsung.com>
This commit is contained in:
Seonghyun Kim 2026-04-15 13:34:04 +09:00 committed by Patrick Kim
commit e52f0ce0cf
3 changed files with 22 additions and 5 deletions

View file

@ -127,7 +127,7 @@ Optional<LexicalEnvironment*> ExecutionState::mostNearestHeapAllocatedLexicalEnv
return nullptr;
}
Optional<Object*> ExecutionState::mostNearestHomeObject()
Optional<Object*> ExecutionState::mostNearestHomeObject(size_t skipCount)
{
LexicalEnvironment* env = m_lexicalEnvironment;
@ -136,7 +136,11 @@ Optional<Object*> ExecutionState::mostNearestHomeObject()
if (rec->isDeclarativeEnvironmentRecord() && rec->asDeclarativeEnvironmentRecord()->isFunctionEnvironmentRecord()) {
auto homeObject = rec->asDeclarativeEnvironmentRecord()->asFunctionEnvironmentRecord()->homeObject();
if (homeObject) {
return homeObject;
if (skipCount) {
skipCount--;
} else {
return homeObject;
}
}
}
env = env->outerEnvironment();
@ -154,11 +158,24 @@ Object* ExecutionState::convertHomeObjectIntoPrivateMemberContextObject(Object*
Object* ExecutionState::findPrivateMemberContextObject()
{
auto o = mostNearestHomeObject();
size_t skipCount = 0;
Optional<Object*> o;
while (true) {
auto test = mostNearestHomeObject(skipCount);
if (!test) {
break;
}
if (test->isScriptClassConstructorPrototypeObject() || test->isScriptClassConstructorFunctionObject()) {
o = test;
break;
}
skipCount++;
}
if (!o) {
ErrorObject::throwBuiltinError(*this, ErrorCode::TypeError, "Cannot read/write private member here");
return nullptr;
}
return convertHomeObjectIntoPrivateMemberContextObject(o.value());
}

View file

@ -301,7 +301,7 @@ public:
LexicalEnvironment* mostNearestFunctionLexicalEnvironment();
Optional<LexicalEnvironment*> mostNearestHeapAllocatedLexicalEnvironment();
Optional<Object*> mostNearestHomeObject();
Optional<Object*> mostNearestHomeObject(size_t skipCount = 0);
static Object* convertHomeObjectIntoPrivateMemberContextObject(Object* o);
Object* findPrivateMemberContextObject();

@ -1 +1 @@
Subproject commit 9f6270fde5d89d049be2e375fd85250688110b93
Subproject commit 0db8e32d96a15fcd392021c29fe9103cd52b86a6