X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FJSU.java;h=db96ed35fec501782489aa99d3def2d4d750c37b;hb=a6fb49b55117ea4cf330b412d2a2fff403fcd053;hp=3954b45feceed74ffc001f7d854646d0938f7059;hpb=a7bfcfc7dd092c7a163de97d6ab1bc0584119f11;p=org.ibex.js.git diff --git a/src/org/ibex/js/JSU.java b/src/org/ibex/js/JSU.java index 3954b45..db96ed3 100644 --- a/src/org/ibex/js/JSU.java +++ b/src/org/ibex/js/JSU.java @@ -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.Clone) 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 { @@ -104,7 +111,7 @@ public class JSU { } /** Internal method for coercing to String without throwing a JSExn. */ - static String str(JS o) { + public static String str(JS o) { try { return toString(o); } catch(JSExn e) { return o.toString(); } } @@ -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); }