FIXME triage and formatting cleanups
[org.ibex.js.git] / src / org / ibex / js / JSU.java
index a20d075..805224b 100644 (file)
@@ -2,12 +2,19 @@ package org.ibex.js;
 
 import java.io.Reader;
 import java.io.IOException;
+import java.io.InputStream;
 import org.ibex.util.*;
 
 public class JSU {
 
     public static final JS[] emptyArgs = new JS[] { };
 
+    public static InputStream getInputStream(JS j) throws IOException {
+        while(j != null && j instanceof JS.Cloneable) j = j.unclone();
+        if (j != null && j instanceof Fountain) return ((Fountain)j).getInputStream();
+        return null;
+    }
+
     /** returns a Pausable which will restart the context;
      *  expects a value to be pushed onto the stack when unpaused. */
     public static Pausable pause() throws Pausable.NotPausableException {
@@ -115,13 +122,8 @@ public class JSU {
     public static JS fromReader(String sourceName, int firstLine, Reader source) throws IOException {
         return Parser.fromReader(sourceName, firstLine, source); }
 
-    // FIXME
     public static JS cloneWithNewGlobalScope(JS js, JS s) {
-        if(js instanceof JSFunction)
-            return ((JSFunction)js)._cloneWithNewParentScope(new JSScope.Top(s));
-        else
-            return js;
-    }
+        return js instanceof JSFunction ?  ((JSFunction)js)._cloneWithNewParentScope(new JSScope.Top(s)) : js; }
 
     /** log a message with the current JavaScript sourceName/line */
     public static void log(Object message) { info(message); }