android: protect color type error

This commit is contained in:
pengfei.zhou 2021-04-29 14:11:25 +08:00 committed by osborn
parent 2e3f8f3cea
commit 91b1a3c24c

View File

@ -239,7 +239,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
if (prop.isNumber()) { if (prop.isNumber()) {
setBackgroundColor(prop.asNumber().toInt()); setBackgroundColor(prop.asNumber().toInt());
} else if (prop.isObject()) { } else if (prop.isObject()) {
final JSValue dict = prop; final JSObject dict = prop.asObject();
ShapeDrawable shapeDrawable = new ShapeDrawable(); ShapeDrawable shapeDrawable = new ShapeDrawable();
shapeDrawable.setShape(new RectShape()); shapeDrawable.setShape(new RectShape());
@ -252,23 +252,31 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
int[] colors = null; int[] colors = null;
float[] locations = null; float[] locations = null;
if (dict.asObject().propertySet().contains("colors")) { if (dict.propertySet().contains("colors")) {
colors = dict.asObject().getProperty("colors").asArray().toIntArray(); JSValue colorsValue = dict.getProperty("colors");
if (colorsValue.isArray()) {
if (dict.asObject().propertySet().contains("locations")) { colors = colorsValue.asArray().toIntArray();
locations = dict.asObject().getProperty("locations").asArray().toFloatArray(); }
if (dict.propertySet().contains("locations")) {
JSValue locationsValue = dict.getProperty("locations");
if (locationsValue.isArray()) {
locations = locationsValue.asArray().toFloatArray();
}
} }
} else { } else {
if (dict.asObject().propertySet().contains("start") && dict.asObject().propertySet().contains("end")) { if (dict.propertySet().contains("start") && dict.propertySet().contains("end")) {
JSValue start = dict.asObject().getProperty("start"); JSValue start = dict.getProperty("start");
JSValue end = dict.asObject().getProperty("end"); JSValue end = dict.getProperty("end");
if (start.isNumber() && end.isNumber()) {
colors = new int[]{start.asNumber().toInt(), end.asNumber().toInt()}; colors = new int[]{start.asNumber().toInt(), end.asNumber().toInt()};
}
} }
} }
if (colors == null) {
colors = new int[]{Color.TRANSPARENT, Color.TRANSPARENT};
}
JSValue orientation = dict.asObject().getProperty("orientation"); JSValue orientation = dict.getProperty("orientation");
if (orientation.isNumber()) { if (orientation.isNumber()) {
switch (orientation.asNumber().toInt()) { switch (orientation.asNumber().toInt()) {
case 0: case 0: