public Object[] toJavaAry(JSHandle jsAry, Class javaClass) { int length = ((Number) jsAry.getMember("length")).intValue(); if (javaClass == null) { javaClass = Object.class; } Object ary = Array.newInstance(javaClass, length); for (int i = 0; i < length; i++) { Object obj = jsAry.getSlot(i); if (JSObject.class.isAssignableFrom(javaClass) && obj instanceof JSHandle) { obj = ((JSHandle) obj).getJSObject(); } Array.set(ary, i, obj); } return (Object[]) ary; }
public URL[] toURLAry(JSHandle jsAry) throws java.net.MalformedURLException { int length = ((Number) jsAry.getMember("length")).intValue(); URL[] ary = new URL[length]; for (int i = 0; i < length; i++) { Object obj = jsAry.getSlot(i); if (obj == null) { continue; } String spec = obj.toString(); if (!spec.matches("^\\w+:.+")) { String location = (String) handle.eval("document.location.toString()"); spec = location.replaceFirst("/[^/]*$", "/" + spec); } ary[i] = new URL(spec); } return ary; }
public JSHandle jsFunction(JSHandle handle, Invocable ivk, Object object, String name) { return (JSHandle) handle.call("createCallback", new Object[] {ivk, object, name}); }