Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: "Richard Maher" Newsgroups: comp.lang.java.programmer Subject: Re: JSObject.call(method, ARGS) with Safari Date: Sat, 21 Apr 2012 21:30:10 +0800 Organization: HTTP *is* The Box - Let's think outside Lines: 238 Message-ID: References: <49ykr.15811$FQ1.5673@newsfe12.iad> NNTP-Posting-Host: jOhPn0KFjrxwuMc9OPMmCw.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-RFC2646: Format=Flowed; Original X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-Priority: 3 X-MSMail-Priority: Normal Xref: csiph.com comp.lang.java.programmer:13745 "Arved Sandstrom" wrote in message news:49ykr.15811$FQ1.5673@newsfe12.iad... > On 12-04-21 08:45 AM, Lew wrote: > > 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: - 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); System.out.println("ans is " + ans.booleanValue()); // 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 } 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 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); 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 Thanks agin Cheers Richard Maher