Fixed #1195 this keyword in functions outside class

This commit is contained in:
Jindra Petřík
2021-02-08 10:39:34 +01:00
parent 47e9857acb
commit a8d1f2b293
12 changed files with 61 additions and 75 deletions

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions;
import com.jpexs.decompiler.flash.abc.ABC;
@@ -32,7 +33,6 @@ import com.jpexs.decompiler.flash.abc.avm2.model.ClassAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NewActivationAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NewActivationAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.ThisAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.clauses.ExceptionAVM2Item;
import com.jpexs.helpers.Reference;
@@ -332,7 +332,7 @@ public abstract class InstructionDefinition implements Serializable {
private Multiname searchSlotName(int slotIndex, AVM2LocalData localData, GraphTargetItem obj, int multiNameIndex) {
if ((obj instanceof ExceptionAVM2Item) && (multiNameIndex == -1 || ((ExceptionAVM2Item) obj).exception.name_index == multiNameIndex)) {
return localData.getConstants().getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
return localData.getConstants().getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
} else if ((obj instanceof ThisAVM2Item) || (obj instanceof ClassAVM2Item)) {
List<Trait> traits = localData.getScriptInfo().get(localData.scriptIndex).traits.traits;
for (int t = 0; t < traits.size(); t++) {
Trait trait = traits.get(t);

View File

@@ -32,7 +32,6 @@ import com.jpexs.decompiler.flash.abc.avm2.model.IncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.PostDecrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.PostIncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.ScriptAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.SetLocalAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.SetPropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.SetTypeAVM2Item;
@@ -71,17 +70,16 @@ public abstract class GetLocalTypeIns extends InstructionDefinition {
if (regId == 0) {
if ((localData.classIndex >= localData.getInstanceInfo().size()) || localData.classIndex < 0) {
stack.push(new ScriptAVM2Item(localData.scriptIndex));
stack.push(new ThisAVM2Item(ins, localData.lineStartInstruction, null, false));
return;
}
if (localData.isStatic) {
stack.push(new ClassAVM2Item(localData.getInstanceInfo().get(localData.classIndex).getName(localData.getConstants())));
} else {
List<Trait> ts = localData.getInstanceInfo().get(localData.classIndex).instance_traits.traits;
boolean isBasicObject = localData.thisHasDefaultToPrimitive;
Multiname m = localData.getInstanceInfo().get(localData.classIndex).getName(localData.getConstants());
stack.push(new ThisAVM2Item(ins, localData.lineStartInstruction, m, m.getNameWithNamespace(localData.getConstants(), true), isBasicObject));
stack.push(new ThisAVM2Item(ins, localData.lineStartInstruction, m.getNameWithNamespace(localData.getConstants(), true), isBasicObject));
}
return;
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.other;
import com.jpexs.decompiler.flash.abc.ABC;
@@ -21,7 +22,6 @@ import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.List;
@@ -43,16 +43,6 @@ public class GetGlobalScopeIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
if (localData.scopeStack.isEmpty()) {
/*if (localData.classIndex == -1) {
} else {
stack.push(new ClassAVM2Item(localData.getInstanceInfo().get(localData.classIndex).getName(localData.getConstants())));
}*/
//FIXME??
stack.push(new ScriptAVM2Item(localData.scriptIndex));
return;
stack.push(localData.scopeStack.get(0));
}

View File

@@ -1,50 +0,0 @@
/*
* Copyright (C) 2010-2021 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.LocalData;
/**
*
* @author JPEXS
*/
public class ScriptAVM2Item extends AVM2Item {
public int scriptIndex;
public ScriptAVM2Item(int scriptIndex) {
super(null, null, NOPRECEDENCE);
this.scriptIndex = scriptIndex;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
return writer.append("script").append(scriptIndex);
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
@Override
public boolean hasReturnValue() {
return false;
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -42,12 +43,9 @@ public class ThisAVM2Item extends AVM2Item {
public boolean basicObject;
public Multiname classMultiname;
public ThisAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, DottedChain className, boolean basicObject) {
super(instruction, lineStartIns, PRECEDENCE_PRIMARY);
this.className = className;
this.className = className;
this.basicObject = basicObject;
getSrcData().localName = "this";
}