Skip to content

Commit

Permalink
ACTIONSCRIPT: Add _root variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Sep 9, 2018
1 parent c8c2d45 commit bfc8209
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/aurora/actionscript/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ static Variable as_pop(AVM &avm) {
}

Array::Array(const std::list<Variable> &values) : _values(values) {
setMember("push", new NativeFunction(boost::bind(as_push, _1), true, false));
setMember("pop", new NativeFunction(boost::bind(as_pop, _1), true, false));
setMember("push", new NativeFunction(boost::bind(as_push, _1), true, false, false));
setMember("pop", new NativeFunction(boost::bind(as_pop, _1), true, false, false));
}

size_t Array::length() const {
Expand Down
20 changes: 7 additions & 13 deletions src/aurora/actionscript/asbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ void ASBuffer::actionCallMethod(AVM &avm) {
byte counter = 1;
Variable prevThis;

if (function->getPreloadRootFlag()) {
avm.storeRegister(avm.getVariable("_root"), counter);
counter += 1;
}
if (function->getPreloadThisFlag()) {
if (!name.empty()) {
prevThis = avm.getRegister(counter);
Expand Down Expand Up @@ -579,7 +583,8 @@ void ASBuffer::actionDefineFunction2() {
new Common::SeekableSubReadStream(_script, _script->pos(), _script->pos() + codeSize),
_constants,
preloadThisFlag,
preloadSuperFlag
preloadSuperFlag,
preloadRootFlag
)
)
);
Expand Down Expand Up @@ -748,18 +753,7 @@ void ASBuffer::actionDefineFunction() {
}

uint16 codeSize = _script->readUint16LE();
_script->seek(codeSize, Common::SeekableReadStream::kOriginCurrent);

ASBuffer buffer(new Common::SeekableSubReadStream(_script, _script->pos(), _script->pos() + codeSize));

_stack.push(
ObjectPtr(
new ScriptedFunction(
new Common::SeekableSubReadStream(_script, _script->pos(), _script->pos() + codeSize),
_constants, false, false
)
)
);
_stack.push(ObjectPtr(new ScriptedFunction(_script->readStream(codeSize), _constants, false, false, false)));

_seeked = codeSize;

Expand Down
5 changes: 5 additions & 0 deletions src/aurora/actionscript/avm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ AVM::AVM() {
_stopFlag = false;

_variables["_global"] = ObjectPtr(new Object());
_variables["_root"] = ObjectPtr(new Object());
_variables["Object"] = ObjectPtr(new DummyFunction());
_variables["Object"].asObject()->setMember("prototype", ObjectPtr(new Object()));
_variables["Array"] = ObjectPtr(new DummyFunction());
Expand Down Expand Up @@ -112,6 +113,10 @@ Variable AVM::createNewObject(const Common::UString &name, std::vector<Variable>
throw Common::Exception("Constructor is not a function");

byte counter = 1;
if (constructor->getPreloadRootFlag()) {
storeRegister(_variables["_root"], counter);
counter += 1;
}
if (constructor->getPreloadThisFlag()) {
storeRegister(Variable(newObject), counter);
counter += 1;
Expand Down
17 changes: 11 additions & 6 deletions src/aurora/actionscript/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace Aurora {

namespace ActionScript {

Function::Function(bool preloadThisFlag, bool preloadSuperFlag) : _preloadThisFlag(preloadThisFlag), _preloadSuperFlag(preloadSuperFlag) {
Function::Function(bool preloadThisFlag, bool preloadSuperFlag, bool preloadRootFlag) :
_preloadThisFlag(preloadThisFlag), _preloadSuperFlag(preloadSuperFlag), _preloadRootFlag(preloadRootFlag) {
}

bool Function::getPreloadThisFlag() {
Expand All @@ -39,9 +40,13 @@ bool Function::getPreloadSuperFlag() {
return _preloadSuperFlag;
}

bool Function::getPreloadRootFlag() {
return _preloadRootFlag;
}

ScriptedFunction::ScriptedFunction(Common::SeekableReadStream *as, std::vector<Common::UString> constants,
bool preloadThisFlag, bool preloadSuperFlag) :
Function(preloadThisFlag, preloadSuperFlag), _stream(as), _buffer(as) {
bool preloadThisFlag, bool preloadSuperFlag, bool preloadRootFlag) :
Function(preloadThisFlag, preloadSuperFlag, preloadRootFlag), _stream(as), _buffer(as) {
_buffer.setConstantPool(constants);
}

Expand All @@ -54,15 +59,15 @@ Variable ScriptedFunction::operator()(AVM &avm) {
return avm.getReturnValue();
}

NativeFunction::NativeFunction(boost::function<Variable(AVM &)> function, bool preloadThisFlag, bool preloadSuperFlag)
: Function(preloadThisFlag, preloadSuperFlag), _function(function) {
NativeFunction::NativeFunction(boost::function<Variable(AVM &)> function, bool preloadThisFlag, bool preloadSuperFlag, bool preloadRootFlag)
: Function(preloadThisFlag, preloadSuperFlag, preloadRootFlag), _function(function) {
}

Variable NativeFunction::operator()(AVM &avm) {
return _function(avm);
}

DummyFunction::DummyFunction() : Function(false, false) {
DummyFunction::DummyFunction() : Function(false, false, false) {

}

Expand Down
9 changes: 6 additions & 3 deletions src/aurora/actionscript/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@ typedef boost::shared_ptr<Function> FunctionPtr;

class Function : public Object {
public:
Function(bool preloadThisFlag, bool preloadSuperFlag);
Function(bool preloadThisFlag, bool preloadSuperFlag, bool preloadRootFlag);

bool getPreloadThisFlag();
bool getPreloadSuperFlag();
bool getPreloadRootFlag();

virtual Variable operator()(AVM &avm) = 0;

private:
bool _preloadThisFlag;
bool _preloadSuperFlag;
bool _preloadRootFlag;
};

class ScriptedFunction : public Function {
Expand All @@ -60,7 +62,8 @@ class ScriptedFunction : public Function {
Common::SeekableReadStream *as,
std::vector<Common::UString> constantPool,
bool preloadThisFlag,
bool preloadSuperFlag
bool preloadSuperFlag,
bool preloadRootFlag
);
~ScriptedFunction();

Expand All @@ -73,7 +76,7 @@ class ScriptedFunction : public Function {

class NativeFunction : public Function {
public:
NativeFunction(boost::function<Variable(AVM &)> function, bool preloadThisFlag, bool preloadSuperFlag);
NativeFunction(boost::function<Variable(AVM &)> function, bool preloadThisFlag, bool preloadSuperFlag, bool preloadRootFlag);

Variable operator()(AVM &avm);

Expand Down
5 changes: 5 additions & 0 deletions src/aurora/actionscript/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ Variable Object::call(const Common::UString &function, AVM &avm, const std::vect
Function *f = reinterpret_cast<Function *>(getMember(function).asObject().get());

byte counter = 1;
if (f->getPreloadRootFlag()) {
avm.storeRegister(avm.getVariable("_root"), counter);
counter += 1;
}

if (f->getPreloadThisFlag()) {
avm.storeRegister(shared_from_this(), counter);
counter += 1;
Expand Down

0 comments on commit bfc8209

Please sign in to comment.