Path: csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: JSObject.call(method, ARGS) with Safari Date: Sat, 21 Apr 2012 13:07:06 -0700 Organization: albasani.net Lines: 256 Message-ID: References: <49ykr.15811$FQ1.5673@newsfe12.iad> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net QZVZMDC5NZib/r3pDd+NmGYzvmBtoUVvOZG3F62PhHp5oT80pft4FNLIjlgOua7OvuNyk4EnT9ivZFeby0BYPDY3jHF60cbcAR3d3UPSvfmmK7a+pgQUGE729VzR62NI NNTP-Posting-Date: Sat, 21 Apr 2012 20:07:08 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="oTwgSRmkpVL7EMObvnoRQ9IGJXCmek/MBRsiZcu7AP7BvFbVd4VPlhpnrfH0rR8a6/JmKM22RPnL2fQe6WerMGavFT2A8qDld4QRmcMdf+6eJYn/bhXw0PP46Pld1mfn"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 In-Reply-To: Cancel-Lock: sha1:C46YbwZrwDaxTO9MBQy32XPeKw0= Xref: csiph.com comp.lang.java.programmer:13753 Richard Maher wrote: > Arved Sandstrom wrote .. >> Lew wrote: >>> ... SSCCE ... [context restored] >> I agree that an SSCCE is called for in any case. >> > > Thanks for the replies. I'll cut it down to just the jsobject.call(m, ARGS) > test tomorrow, but for now: - Thanks for this fragment of your problem. The missing fragment is what went wrong. Please copy and paste the actual output or errors and describe what you expect instead. You haven't even told us what the error is! > import java.applet.Applet; > import netscape.javascript.JSObject; > import netscape.javascript.JSException; > > public class JavaJSTest extends Applet { > > JSObject laundry; > Object rinseArgs[] = new Object[1]; > > public synchronized void init() { > > System.out.println("Starting Tests. . ."); > > JSObject window = JSObject.getWindow(this); > > final String createLaundry = > "(function(){" + > "function Laundry(){" + > "this.launder = function(JSObject){" + > "alert('In Laundry');" + > "return JSObject;}}" + > "return new Laundry();" + > "})();"; > > laundry = (JSObject)window.eval(createLaundry); > > // Test function calls > String str = (String) window.eval("getString();"); > if (!str.equals("Hello, world!")) { > throw new RuntimeException(); // test failed > } > Number num = (Number) window.eval("getNumber()"); > if (num.intValue() != 5) { > throw new RuntimeException(); // test failed > } > // Test field access > JSObject res = (JSObject) window.eval("new cities();"); > if (!((String) res.getMember("b")).equals("Belgrade")) { > throw new RuntimeException(); // test failed > } > res.setMember("b", "Belfast"); > if (!res.getMember("b").equals("Belfast")) { > throw new RuntimeException(); // test failed > } > // Test CALL > Boolean ans = (Boolean)res.call("d", null); Could this possibly be where the error occurs? > System.out.println("ans is " + ans.booleanValue()); Really, 'System.out.println()'? Check out java.util.logger or log4j. > // Test CALL with param > rinseArgs[0] = new String("A param"); > Boolean pans = (Boolean)res.call("e", rinseArgs); > System.out.println("param ans is " + pans.booleanValue()); > > // Test array access > res = (JSObject) window.eval("getTestArray();"); > if (!((String) res.getSlot(0)).equals("foo") || > !((String) res.getSlot(1)).equals("bar")) { > throw new RuntimeException(); // test failed > } Could this possibly be where the error occurs? > res.setSlot(1, "baz"); > if (!((String) res.getSlot(1)).equals("baz")) { > throw new RuntimeException(); // test failed > } > res.setSlot(2, "qux"); // Define new array element > if (!((String) res.getSlot(2)).equals("qux")) { > throw new RuntimeException(); // test failed > } > res.removeMember("b"); > try { > res.getMember("b"); > // throw new RuntimeException(); // test failed For this sort of thing, 'IllegalStateException' is a good match. > System.out.println("This browser does not support > removeMember"); // test failed > } catch (JSException e) { > // Member should not be present any more > } > > System.out.println(". . .Tests complete"); > } > > public void hello() { > System.out.println("Hello"); > } > > public boolean testCall(JSObject blob) { > System.out.println("In method - testCall()"); > > JSObject cleanBuf; > boolean retVal = false; > > try { > rinseArgs[0] = blob; > System.out.println("before launder"); > try { > cleanBuf = (JSObject)laundry.call("launder", rinseArgs); > } > catch (Exception e) { > throw e; > } > System.out.println("after launder"); > // System.out.println("ans is " + abc.booleanValue()); > > System.out.println("blob.call()"); > Boolean resp = (Boolean)cleanBuf.call("e",null); Could this possibly be where the error occurs? > System.out.println("Setting retVal"); > retVal = resp.booleanValue(); > } catch (JSException ex) { > Exception ex2 = (Exception)ex.getWrappedException(); > if(ex2 != null) { > System.out.println(ex2.getClass().getName() + " " + > ex2.getMessage()); > } else { > System.out.println(ex.getClass().getName() + " " + > ex.getMessage()); > } > } catch (Exception ex) { > System.out.println(ex.getClass().getName() + " " + > ex.getMessage()); > } > return retVal; > } > > } > > > And the HTML: _ > > > > > > > > STUFF > > > > > -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg