I replaced java.util.Enumeration type for result and arguments of ScriptRuntime.initEnum/ScriptRuntime.nextEnum by Object to allow for greater flexibility in for (...in...) implementation.

This commit is contained in:
igor%mir2.org 2002-04-29 17:31:11 +00:00
parent 13bca713d5
commit ff45d81768
3 changed files with 15 additions and 23 deletions

View File

@ -39,7 +39,6 @@
package org.mozilla.javascript;
import java.io.*;
import java.util.Enumeration;
import org.mozilla.javascript.debug.*;
@ -2259,8 +2258,7 @@ public class Interpreter extends LabelTable {
int slot = (iCode[++pc] & 0xFF);
Object val = stack[LOCAL_SHFT + slot];
++stackTop;
stack[stackTop] = ScriptRuntime.
nextEnum((Enumeration)val);
stack[stackTop] = ScriptRuntime.nextEnum(val);
break;
}
case TokenStream.GETPROTO : {

View File

@ -40,7 +40,6 @@
package org.mozilla.javascript;
import java.util.Enumeration;
import java.lang.reflect.*;
import org.mozilla.classfile.DefiningClassLoader;
@ -1129,17 +1128,15 @@ public class ScriptRuntime {
return value;
}
public static Enumeration initEnum(Object value, Scriptable scope) {
public static Object initEnum(Object value, Scriptable scope) {
Scriptable m = toObject(scope, value);
return new IdEnumeration(m);
}
public static Object nextEnum(Enumeration enum) {
// OPT this could be more efficient; should junk the Enumeration
// interface
if (!enum.hasMoreElements())
return null;
return enum.nextElement();
public static Object nextEnum(Object enumObj) {
// OPT this could be more efficient
IdEnumeration enum = (IdEnumeration)enumObj;
return enum.nextId();
}
// Form used by class files generated by 1.4R3 and earlier.
@ -2066,24 +2063,21 @@ public class ScriptRuntime {
* to see if a given property has already been enumerated.
*
*/
class IdEnumeration implements Enumeration {
class IdEnumeration {
IdEnumeration(Scriptable m) {
used = new ObjToIntMap(27);
changeObject(m);
next = getNext();
}
public boolean hasMoreElements() {
return next != null;
}
public Object nextElement() {
Object nextId() {
Object result = next;
if (result != null) {
// only key used; 0 as value for convenience
used.put(next, 0);
// only key used; 0 as value for convenience
used.put(next, 0);
next = getNext();
next = getNext();
}
return result;
}

View File

@ -1691,7 +1691,7 @@ public class Codegen extends Interpreter {
aload(variableObjectLocal);
addScriptRuntimeInvoke("initEnum",
"(Ljava/lang/Object;Lorg/mozilla/javascript/Scriptable;)",
"Ljava/util/Enumeration;");
"Ljava/lang/Object;");
short x = getNewWordLocal();
astore(x);
node.putIntProp(Node.LOCAL_PROP, x);
@ -1705,7 +1705,7 @@ public class Codegen extends Interpreter {
Node init = (Node) node.getProp(Node.ENUM_PROP);
int local = init.getExistingIntProp(Node.LOCAL_PROP);
aload((short)local);
addScriptRuntimeInvoke("nextEnum", "(Ljava/util/Enumeration;)", "Ljava/lang/Object;");
addScriptRuntimeInvoke("nextEnum", "(Ljava/lang/Object;)", "Ljava/lang/Object;");
}
private void visitEnumDone(Node node, Node child) {