Skip to content

Commit

Permalink
ACTIONSCRIPT: Fix super and this variable handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Aug 7, 2020
1 parent 3cdfe5f commit f7cf44e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/aurora/actionscript/asbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,31 +482,42 @@ void ASBuffer::actionCallMethod(AVM &avm) {
}

Function *function;
bool superFunction = false;
if (name.empty()) {
function = dynamic_cast<Function *>(object.get());
} else {
function = dynamic_cast<Function *>(object->getMember(name).asObject().get());
if (!function) {
function = dynamic_cast<Function *>(object->getMember("prototype").asObject()->getMember(name).asObject().get());

if (function)
superFunction = true;
}
}

if (!function)
throw Common::Exception("Object is not a function");

byte counter = 1;
Variable prevThis;

// Since this is the first variable to initialize, it can only be at register 1
Variable currentThis = avm.getRegister(1);

avm.pushRegisters(function->getNumRegisters());

if (function->getPreloadThisFlag()) {
prevThis = avm.getRegister(counter);
avm.storeRegister(object, counter);
if (name.empty() || superFunction)
avm.storeRegister(currentThis, counter);
else
avm.storeRegister(object, counter);
counter += 1;
}
if (function->getPreloadRootFlag()) {
avm.storeRegister(avm.getVariable("_root"), counter);
counter += 1;
}
if (function->getPreloadSuperFlag()) {
// TODO: Add super variable
avm.storeRegister(object->getMember("prototype").asObject()->getMember("constructor"), counter);
counter += 1;
}
if (function->getPreloadGlobalFlag()) {
Expand All @@ -529,8 +540,8 @@ void ASBuffer::actionCallMethod(AVM &avm) {
_stack.push((*function)(avm));
avm.setReturnValue(Variable());

if (!prevThis.isUndefined())
avm.storeRegister(prevThis, 1);
if (!currentThis.isUndefined())
avm.storeRegister(currentThis, 1);

avm.popRegisters(function->getNumRegisters());

Expand Down

0 comments on commit f7cf44e

Please sign in to comment.