Restore operability of Circle3D from JavaScript

There were two small problems. First, the type-checking in MacroRunner.run
was too strict, so applications that worked manually were failing from
JavaScript. The fix was to replace all of the type-checking code in that
function with a single call to isAdmissible(), which also simplified the code
and removed duplication.

Second, when assembling return values in ExecuteMacro in JSFunctions.java the
code would commit array bounds violations when there were no targets from
the MacroRunner. This commit fixes both problems and avoids silently dropping
the exceptions caught in Circle3D.
This commit is contained in:
Glen Whitney 2018-09-05 00:12:43 -04:00
parent c312811084
commit e2f0f34394
4 changed files with 29 additions and 46 deletions

3
.gitignore vendored
View File

@ -12,6 +12,8 @@ local.properties
.loadpath
.recommenders
*.class
# Eclipse Core
.project
@ -55,4 +57,3 @@ local.properties
.cache-main
.scala_dependencies
.worksheet

View File

@ -5758,7 +5758,9 @@ public class JSFunctions {
getC().lastButN(i).setShowName(false);
}
if(TargetsNamesArray.length<2) {
if (TargetsNamesArray.length == 0) {
return getC().lastButN(0).getName();
} else if (TargetsNamesArray.length == 1) {
return TargetsNamesArray[0];
} else {
return TargetsNamesArray;
@ -5785,7 +5787,9 @@ public class JSFunctions {
getC().lastButN(i).setShowName(false);
}
if(TargetsNamesArray.length<2) {
if (TargetsNamesArray.length == 0) {
return getC().lastButN(0).getName();
} else if (TargetsNamesArray.length == 1) {
return TargetsNamesArray[0];
} else {
return TargetsNamesArray;
@ -7650,14 +7654,21 @@ public class JSFunctions {
try {
ExecuteMacro("","@builtin@/3Dcircle1","O,X,Y,Z,"+a+","+b);
}
catch (final Exception f) {}
catch (final Exception f) {
Println("Potential problem executing macro @builtin@/3Dcircle1(O,X,Y,Z,"
+ a + "," + b + "):" + f.getMessage());
}
getC().lastButN(0).setShowName(false);
} else {
name=parseVariables(name);
try {
ExecuteMacro("","@builtin@/3Dcircle1","O,X,Y,Z,"+a+","+b);
}
catch (final Exception f) {}
catch (final Exception f) {
Println("Potential problem executing macro assignment " +
name + " = @builtin@/3Dcircle1(O,X,Y,Z," +
a + "," + b + "):" + f.getMessage());
}
getC().lastButN(0).setName(name);
}
Normalize(0);
@ -7679,14 +7690,21 @@ public class JSFunctions {
try {
ExecuteMacro("","@builtin@/3Dcircle1","O,X,Y,Z,"+a+","+b);
}
catch (final Exception f) {}
catch (final Exception f) {
Println("Il y a peut-etre une probleme avec macro @builtin@/3Dcircle1(O,X,Y,Z,"
+ a + "," + b + "):" + f.getMessage());
}
getC().lastButN(0).setShowName(false);
} else {
name=parseVariables(name);
try {
ExecuteMacro("","@builtin@/3Dcircle1","O,X,Y,Z,"+a+","+b);
}
catch (final Exception f) {}
catch (final Exception f) {
Println("Il y a peut-etre une probleme avec macro assignment " +
name + " = @builtin@/3Dcircle1(O,X,Y,Z," +
a + "," + b + "):" + f.getMessage());
}
getC().lastButN(0).setName(name);
}
Normalize(0);

Binary file not shown.

View File

@ -1290,43 +1290,7 @@ public class MacroRunner extends ObjectConstructor implements Selector {
if (o==null) {
throw new ConstructionException(Global.name("exception.notfound"));
}
if (p[Param] instanceof PointObject) {
if (!(o instanceof PointObject)) {
throw new ConstructionException(Global.name("exception.type"));
}
} else if (p[Param] instanceof SegmentObject) {
if (!(o instanceof SegmentObject)) {
throw new ConstructionException(Global.name("exception.type"));
}
} else if (p[Param] instanceof LineObject) {
if (!(o instanceof LineObject)) {
throw new ConstructionException(Global.name("exception.type"));
}
} else if (p[Param] instanceof RayObject) {
if (!(o instanceof RayObject)) {
throw new ConstructionException(Global.name("exception.type"));
}
} else if (p[Param] instanceof PrimitiveLineObject) {
if (!(o instanceof PrimitiveLineObject)) {
throw new ConstructionException(Global.name("exception.type"));
}
} else if (p[Param] instanceof PrimitiveCircleObject) {
if (!(o instanceof PrimitiveCircleObject)) {
throw new ConstructionException(Global.name("exception.type"));
}
} else if (p[Param] instanceof QuadricObject) {
if (!(o instanceof QuadricObject)) {
throw new ConstructionException(Global.name("exception.type"));
}
} else if (p[Param] instanceof ExpressionObject) {
if (!(o instanceof ExpressionObject)) {
throw new ConstructionException(Global.name("exception.type"));
}
} else if (p[Param] instanceof TextObject) {
if (!(o instanceof TextObject)) {
throw new ConstructionException(Global.name("exception.type"));
}
} else {
if (!isAdmissible(zc, o)) {
throw new ConstructionException(Global.name("exception.type"));
}
Params[i]=o;