From f80d4788f859959265c091fa906f7ddab985c750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 14 Jan 2023 10:18:08 +0100 Subject: [PATCH] Fixed #1936 AS3 Direct editation - handling undefined variables --- CHANGELOG.md | 1 + .../flash/abc/avm2/parser/script/UnresolvedAVM2Item.java | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 635cdd638..9d495bba9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file. - AS3 Direct editation - removing method bodies after unsuccessful edit - [#1936] AS3 - Parentheses around function definition call - [#1936] AS3 - Scope stack in second pass +- [#1936] AS3 Direct editation - handling undefined variables ## [18.3.2] - 2023-01-10 ### Removed diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java index d84c0f52a..1adf743c1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java @@ -228,7 +228,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { if (resolved == null) { - throw new RuntimeException("Unresolved: " + toString()); + throw new CompilationException("Undefined variable or property: "+ toString(), line); } return resolved.toSource(localData, generator); } @@ -236,7 +236,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { @Override public List toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { if (resolved == null) { - throw new RuntimeException("Unresolved"); + throw new CompilationException("Undefined variable or property: "+ toString(), line); } return resolved.toSourceIgnoreReturnValue(localData, generator); } @@ -279,12 +279,12 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { @Override public List toSourceChange(SourceGeneratorLocalData localData, SourceGenerator generator, boolean post, boolean decrement, boolean needsReturn) throws CompilationException { if (resolved == null) { - throw new RuntimeException("Unresolved"); + throw new CompilationException("Undefined variable or property: "+ toString(), line); } if (resolved instanceof AssignableAVM2Item) { return ((AssignableAVM2Item) resolved).toSourceChange(localData, generator, post, decrement, needsReturn); } - throw new RuntimeException("Cannot assign"); + throw new CompilationException("Cannot assign", line); } public GraphTargetItem resolve(SourceGeneratorLocalData localData /*can be null!!!*/, String currentClass, GraphTargetItem thisType, List paramTypes, List paramNames, AbcIndexing abc, List callStack, List variables) throws CompilationException {