- public Object[] keys() {
- Object[] ret = graftee.keys();
- for(int i=0; i<ret.length; i++) if (replaced_key.equals(ret[i])) return ret;
- Object[] ret2 = new Object[ret.length + 1];
- System.arraycopy(ret, 0, ret2, 0, ret.length);
- ret2[ret2.length - 1] = replaced_key;
- return ret2;
- }
- }
-
- /** anything that is callable with the () operator */
- public static abstract class Callable extends JS.Obj {
- public abstract Object call(JS.Array args) throws JS.Exn;
- }
-
- /** a Callable which was compiled from JavaScript code */
- public static class CompiledFunction extends CompiledFunctionImpl {
- public int getNumFormalArgs() { return numFormalArgs; }
- CompiledFunction(String sourceName, int firstLine, Reader sourceCode, Scope scope) throws IOException {
- super(sourceName, firstLine, sourceCode, scope);
- }
- }
-
- /** a scope that is populated with js objects and functions normally found in the global scope */
- public static class GlobalScope extends GlobalScopeImpl {
- public GlobalScope() { this(null); }
- public GlobalScope(JS.Scope parent) { super(parent); }
- }
-
- public static final JS Math = new org.xwt.js.Math();
-
- /** encapsulates a single JavaScript thread; the JS.Thread->java.lang.Thread mapping is 1:1 */
- public static class Thread {
-
- CompiledFunction currentCompiledFunction = null;
- Vec stack = new Vec();
- int pc;
-
- /** binds this thread to the current Java Thread */
- public void bindToCurrentJavaThread() { javaThreadToJSThread.put(java.lang.Thread.currentThread(), this); }
-
- /** returns the line of code that is currently executing */
- public int getLine() { return currentCompiledFunction == null ? -1 : currentCompiledFunction.getLine(pc); }
-
- /** returns the name of the source code file which declared the currently executing function */
- public String getSourceName() { return currentCompiledFunction == null ? null : currentCompiledFunction.getSourceName(); }
-
- /** fetches the currently-executing javascript function */
- public JS.CompiledFunction getCurrentCompiledFunction() { return currentCompiledFunction; }
-
-
- // Statics ///////////////////////////////////////////////////////////////////////
-
- private static Hashtable javaThreadToJSThread = new Hashtable();
-
- /** returns the JS thread for a given Java thread, creating one if necessary */
- public static JS.Thread fromJavaThread(java.lang.Thread t) {
- JS.Thread ret = (JS.Thread)javaThreadToJSThread.get(t);
- if (ret == null) {
- ret = new JS.Thread();
- ret.bindToCurrentJavaThread();
- }
- return ret;
- }
-
- public static JS.Thread currentJSThread() {
- return fromJavaThread(java.lang.Thread.currentThread());
+ public Enumeration keys() {
+ return new Enumeration() {
+ Enumeration graftee_enumeration = graftee.keys();
+ boolean returned_replaced = false;
+ public boolean hasMoreElements() {
+ if (graftee_enumeration.hasMoreElements()) return true;
+ return !returned_replaced;
+ }
+ public Object nextElement() {
+ if (!graftee_enumeration.hasMoreElements()) {
+ if (returned_replaced) throw new NoSuchElementException();
+ returned_replaced = true;
+ return replaced_key;
+ } else {
+ Object ret = graftee_enumeration.nextElement();
+ if (!returned_replaced && ret.equals(replaced_key)) returned_replaced = true;
+ return ret;
+ }
+ }
+ };