From cb5b2b60928d25179b1f21518b8ad1f1846802fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Mon, 30 Jan 2023 18:41:10 +0100 Subject: [PATCH] Fixed #688 AS3 Direct editation - construction (new keyword) converted to call when result not used --- CHANGELOG.md | 3 +- .../script/ConstructSomethingAVM2Item.java | 29 +++++++------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df90dc60f..311e15f2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file. - AS3 - incorrect switching P-code causing empty text - AS3 - Select the trait after adding new - [#1955] AS3 - Exception during removing trait +- [#688] AS3 Direct editation - construction (new keyword) converted to call when result not used ## [18.3.3] - 2023-01-22 ### Added @@ -2934,6 +2935,7 @@ All notable changes to this project will be documented in this file. [#1944]: https://www.free-decompiler.com/flash/issues/1944 [#1940]: https://www.free-decompiler.com/flash/issues/1940 [#1955]: https://www.free-decompiler.com/flash/issues/1955 +[#688]: https://www.free-decompiler.com/flash/issues/688 [#1913]: https://www.free-decompiler.com/flash/issues/1913 [#1894]: https://www.free-decompiler.com/flash/issues/1894 [#1801]: https://www.free-decompiler.com/flash/issues/1801 @@ -3456,7 +3458,6 @@ All notable changes to this project will be documented in this file. [#710]: https://www.free-decompiler.com/flash/issues/710 [#711]: https://www.free-decompiler.com/flash/issues/711 [#681]: https://www.free-decompiler.com/flash/issues/681 -[#688]: https://www.free-decompiler.com/flash/issues/688 [#691]: https://www.free-decompiler.com/flash/issues/691 [#524]: https://www.free-decompiler.com/flash/issues/524 [#663]: https://www.free-decompiler.com/flash/issues/663 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstructSomethingAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstructSomethingAVM2Item.java index 9de718c92..c447f68b6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstructSomethingAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ConstructSomethingAVM2Item.java @@ -45,18 +45,8 @@ public class ConstructSomethingAVM2Item extends CallAVM2Item { return name.returnType(); } - private int allNsSetWithVec(AbcIndexing abc) throws CompilationException { - int[] nssa = new int[openedNamespaces.size() + 1]; - for (int i = 0; i < openedNamespaces.size(); i++) { - nssa[i] = openedNamespaces.get(i).getCpoolIndex(abc); - } - nssa[nssa.length - 1] = abc.getSelectedAbc().constants.getNamespaceId(Namespace.KIND_PACKAGE, "__AS3__.vec", 0, true); - return abc.getSelectedAbc().constants.getNamespaceSetId(nssa, true); - - } - @Override - public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { GraphTargetItem resname = name; if (resname instanceof UnresolvedAVM2Item) { @@ -68,35 +58,38 @@ public class ConstructSomethingAVM2Item extends CallAVM2Item { if (localData.isStatic && localData.pkg.addWithSuffix(localData.currentClass).equals(prop.fullTypeName)) { return toSourceMerge(localData, generator, new AVM2Instruction(0, AVM2Instructions.GetLocal0, new int[]{}), arguments, - new AVM2Instruction(0, AVM2Instructions.Construct, new int[]{arguments.size()})); + new AVM2Instruction(0, AVM2Instructions.Construct, new int[]{arguments.size()}), + needsReturn ? null : ins(AVM2Instructions.Pop)); } int type_index = AVM2SourceGenerator.resolveType(localData, resname, ((AVM2SourceGenerator) generator).abcIndex); return toSourceMerge(localData, generator, new AVM2Instruction(0, AVM2Instructions.FindPropertyStrict, new int[]{type_index, arguments.size()}), arguments, - new AVM2Instruction(0, AVM2Instructions.ConstructProp, new int[]{type_index, arguments.size()}) + new AVM2Instruction(0, AVM2Instructions.ConstructProp, new int[]{type_index, arguments.size()}), + needsReturn ? null : ins(AVM2Instructions.Pop) ); } if (resname instanceof PropertyAVM2Item) { PropertyAVM2Item prop = (PropertyAVM2Item) resname; return toSourceMerge(localData, generator, prop.resolveObject(localData, generator, true), arguments, - ins(AVM2Instructions.ConstructProp, prop.resolveProperty(localData), arguments.size()) + ins(AVM2Instructions.ConstructProp, prop.resolveProperty(localData), arguments.size()), + needsReturn ? null : ins(AVM2Instructions.Pop) ); } if (resname instanceof NameAVM2Item) { - return toSourceMerge(localData, generator, resname, arguments, ins(AVM2Instructions.Construct, arguments.size())); + return toSourceMerge(localData, generator, resname, arguments, ins(AVM2Instructions.Construct, arguments.size()), needsReturn ? null : ins(AVM2Instructions.Pop)); } if (resname instanceof IndexAVM2Item) { - return ((IndexAVM2Item) resname).toSource(localData, generator, true, false, arguments, false, true); + return ((IndexAVM2Item) resname).toSource(localData, generator, needsReturn, false, arguments, false, true); } if (resname instanceof NamespacedAVM2Item) { - return ((NamespacedAVM2Item) resname).toSource(localData, generator, true, false, arguments, false, true); + return ((NamespacedAVM2Item) resname).toSource(localData, generator, needsReturn, false, arguments, false, true); } - return toSourceMerge(localData, generator, resname, arguments, ins(AVM2Instructions.Construct, arguments.size())); + return toSourceMerge(localData, generator, resname, arguments, ins(AVM2Instructions.Construct, arguments.size()), needsReturn ? null : ins(AVM2Instructions.Pop)); } @Override