diff --git a/js/rhino/src/org/mozilla/javascript/Node.java b/js/rhino/src/org/mozilla/javascript/Node.java index 273f3052ffa4..9c94648cb3e7 100644 --- a/js/rhino/src/org/mozilla/javascript/Node.java +++ b/js/rhino/src/org/mozilla/javascript/Node.java @@ -316,47 +316,49 @@ public class Node implements Cloneable { LEFT = 1, RIGHT = 2; - private static String propNames[]; - private static final String propToString(int propType) { - if (Context.printTrees && propNames == null) { + if (Context.printTrees) { // If Context.printTrees is false, the compiler // can remove all these strings. - String[] a = { - "target", - "break", - "continue", - "enum", - "function", - "temp", - "local", - "codeoffset", - "fixups", - "vars", - "uses", - "regexp", - "cases", - "default", - "casearray", - "sourcename", - "source", - "type", - "special_prop", - "label", - "finally", - "localcount", - "targetblock", - "variable", - "lastuse", - "isnumber", - "directcall", - "base_lineno", - "end_lineno", - "specialcall" - }; - propNames = a; + switch (propType) { + case TARGET_PROP: return "target"; + case BREAK_PROP: return "break"; + case CONTINUE_PROP: return "continue"; + case ENUM_PROP: return "enum"; + case FUNCTION_PROP: return "function"; + case TEMP_PROP: return "temp"; + case LOCAL_PROP: return "local"; + case CODEOFFSET_PROP: return "codeoffset"; + case FIXUPS_PROP: return "fixups"; + case VARS_PROP: return "vars"; + case USES_PROP: return "uses"; + case REGEXP_PROP: return "regexp"; + case CASES_PROP: return "cases"; + case DEFAULT_PROP: return "default"; + case CASEARRAY_PROP: return "casearray"; + case SOURCENAME_PROP: return "sourcename"; + case SOURCE_PROP: return "source"; + case TYPE_PROP: return "type"; + case SPECIAL_PROP_PROP: return "special_prop"; + case LABEL_PROP: return "label"; + case FINALLY_PROP: return "finally"; + case LOCALCOUNT_PROP: return "localcount"; + + case TARGETBLOCK_PROP: return "targetblock"; + case VARIABLE_PROP: return "variable"; + case LASTUSE_PROP: return "lastuse"; + case ISNUMBER_PROP: return "isnumber"; + case DIRECTCALL_PROP: return "directcall"; + + case BASE_LINENO_PROP: return "base_lineno"; + case END_LINENO_PROP: return "end_lineno"; + case SPECIALCALL_PROP: return "specialcall"; + case DEBUGSOURCE_PROP: return "debugsource"; + + default: Context.codeBug(); + } } - return propNames[propType-1]; + return null; } public Object getProp(int propType) { @@ -475,10 +477,10 @@ public class Node implements Cloneable { sb.append("last use property"); break; default : - if (props.isObjectType(key)) { - sb.append(props.getObject(key).toString()); - } - else { + Object obj = props.getObject(key); + if (obj != null) { + sb.append(obj.toString()); + }else { sb.append(props.getExistingInt(key)); } break; @@ -522,11 +524,11 @@ public class Node implements Cloneable { public Node getFirst() { return first; } public Node getNext() { return next; } - protected int type; // type of the node; TokenStream.NAME for example - protected Node next; // next sibling - protected Node first; // first element of a linked list of children - protected Node last; // last element of a linked list of children - protected UintMap props; - protected Object datum; // encapsulated data; depends on type + protected int type; // type of the node; TokenStream.NAME for example + protected Node next; // next sibling + protected Node first; // first element of a linked list of children + protected Node last; // last element of a linked list of children + private Object datum; // encapsulated data; depends on type + private UintMap props; } diff --git a/js/rhino/src/org/mozilla/javascript/UintMap.java b/js/rhino/src/org/mozilla/javascript/UintMap.java index 59be5746b38a..8a4a15b89e88 100644 --- a/js/rhino/src/org/mozilla/javascript/UintMap.java +++ b/js/rhino/src/org/mozilla/javascript/UintMap.java @@ -82,22 +82,9 @@ class UintMap implements Serializable { return 0 <= findIndex(key); } - public boolean isObjectType(int key) { - if (key < 0) Context.codeBug(); - int index = findIndex(key); - return index >= 0 && isObjectTypeValue(index); - } - - public boolean isIntType(int key) { - if (key < 0) Context.codeBug(); - int index = findIndex(key); - return index >= 0 && !isObjectTypeValue(index); - } - /** * Get object value assigned with key. - * @return key object value or null if key is absent or does - * not have object value + * @return key object value or null if key is absent */ public Object getObject(int key) { if (key < 0) Context.codeBug(); @@ -112,18 +99,16 @@ class UintMap implements Serializable { /** * Get integer value assigned with key. - * @return key integer value or defaultValue if key is absent or does - * not have int value + * @return key integer value or defaultValue if key is absent */ public int getInt(int key, int defaultValue) { if (key < 0) Context.codeBug(); - if (ivaluesShift != 0) { - int index = findIndex(key); - if (0 <= index) { - if (!isObjectTypeValue(index)) { - return keys[ivaluesShift + index]; - } + int index = findIndex(key); + if (0 <= index) { + if (ivaluesShift != 0) { + return keys[ivaluesShift + index]; } + return 0; } return defaultValue; } @@ -132,26 +117,28 @@ class UintMap implements Serializable { * Get integer value assigned with key. * @return key integer value or defaultValue if key does not exist or does * not have int value - * @throws RuntimeException if key does not exist or does - * not have int value + * @throws RuntimeException if key does not exist */ public int getExistingInt(int key) { if (key < 0) Context.codeBug(); - if (ivaluesShift != 0) { - int index = findIndex(key); - if (0 <= index) { - if (!isObjectTypeValue(index)) { - return keys[ivaluesShift + index]; - } + int index = findIndex(key); + if (0 <= index) { + if (ivaluesShift != 0) { + return keys[ivaluesShift + index]; } + return 0; } // Key must exist Context.codeBug(); return 0; } + /** + * Set object value of the key. + * If key does not exist, also set its int value to 0. + */ public void put(int key, Object value) { - if (!(key >= 0 && value != null)) Context.codeBug(); + if (key < 0) Context.codeBug(); int index = ensureIndex(key, false); if (values == null) { values = new Object[1 << power]; @@ -159,12 +146,16 @@ class UintMap implements Serializable { values[index] = value; } + /** + * Set int value of the key. + * If key does not exist, also set its object value to null. + */ public void put(int key, int value) { if (key < 0) Context.codeBug(); int index = ensureIndex(key, true); if (ivaluesShift == 0) { int N = 1 << power; - // keys.length cam be N * 2 after clear which set ivaluesShift to 0 + // keys.length can be N * 2 after clear which set ivaluesShift to 0 if (keys.length != N * 2) { int[] tmp = new int[N * 2]; System.arraycopy(keys, 0, tmp, 0, N); @@ -173,7 +164,6 @@ class UintMap implements Serializable { ivaluesShift = N; } keys[ivaluesShift + index] = value; - if (values != null) { values[index] = null; } } public void remove(int key) { @@ -370,12 +360,6 @@ class UintMap implements Serializable { return index; } - private boolean isObjectTypeValue(int index) { - if (check && !(index >= 0 && index < (1 << power))) - Context.codeBug(); - return values != null && values[index] != null; - } - private void writeObject(ObjectOutputStream out) throws IOException {