NativeArray arr = (NativeArray) result; Object [] array = new Object[(int) arr.getLength()]; for (Object o : arr.getIds()) { int index = (Integer) o; array[index] = arr.get(index, null); }
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (args.length == 0) { throw new RuntimeException("'load' function takes at least one argument"); } for (Object arg : args) { if (arg instanceof NativeArray) { NativeArray array = (NativeArray)arg; for (int i = 0; i < array.getLength(); i++) { Object path = array.get(i); if (path != null) { load(path.toString(), cx, scope); } else { throw new NullPointerException("Cannot have null argument in load function"); } } } else if (arg == null) { throw new NullPointerException("Cannot have null argument in load function"); } else { load(arg.toString(), cx, scope); } } return null; }
/** @deprecated Use {@link #getLength()} instead. */ public long jsGet_length() { return getLength(); }
/** @deprecated Use {@link #getLength()} instead. */ public long jsGet_length() { return getLength(); }
/** @deprecated Use {@link #getLength()} instead. */ public long jsGet_length() { return getLength(); }
/** @deprecated Use {@link #getLength()} instead. */ public long jsGet_length() { return getLength(); }
/** @deprecated Use {@link #getLength()} instead. */ public long jsGet_length() { return getLength(); }
public boolean hasNext() { return index < (int) arr.getLength(); }
/** @deprecated Use {@link #getLength()} instead. */ @Deprecated public long jsGet_length() { return getLength(); }
private static List<Object> asList(final NativeArray array) { final List<Object> list = new ArrayList<>((int)array.getLength()); for (final Object id : array.getIds()) { list.add(array.get((int)id, null)); } return list; } }
private static List<Object> asList(final NativeArray array) { final List<Object> list = new ArrayList<>((int)array.getLength()); for (final Object id : array.getIds()) { list.add(array.get((int)id, null)); } return list; } }
static long getLengthProperty(Context cx, Scriptable obj) { // These will both give numeric lengths within Uint32 range. if (obj instanceof NativeString) { return ((NativeString)obj).getLength(); } else if (obj instanceof NativeArray) { return ((NativeArray)obj).getLength(); } return ScriptRuntime.toUint32( ScriptRuntime.getObjectProp(obj, "length", cx)); }
static long getLengthProperty(Context cx, Scriptable obj) { // These will both give numeric lengths within Uint32 range. if (obj instanceof NativeString) { return ((NativeString)obj).getLength(); } else if (obj instanceof NativeArray) { return ((NativeArray)obj).getLength(); } return ScriptRuntime.toUint32( ScriptRuntime.getObjectProp(obj, "length", cx)); }
static long getLengthProperty(Context cx, Scriptable obj) { // These will both give numeric lengths within Uint32 range. if (obj instanceof NativeString) { return ((NativeString)obj).getLength(); } else if (obj instanceof NativeArray) { return ((NativeArray)obj).getLength(); } return ScriptRuntime.toUint32( ScriptRuntime.getObjectProp(obj, "length", cx)); }
static long getLengthProperty(Context cx, Scriptable obj) { // These will both give numeric lengths within Uint32 range. if (obj instanceof NativeString) { return ((NativeString)obj).getLength(); } else if (obj instanceof NativeArray) { return ((NativeArray)obj).getLength(); } return ScriptRuntime.toUint32( ScriptRuntime.getObjectProp(obj, "length", cx)); }
static long getLengthProperty(Context cx, Scriptable obj) { // These will both give numeric lengths within Uint32 range. if (obj instanceof NativeString) { return ((NativeString)obj).getLength(); } else if (obj instanceof NativeArray) { return ((NativeArray)obj).getLength(); } Object len = ScriptableObject.getProperty(obj, "length"); if (len == Scriptable.NOT_FOUND) { // toUint32(undefined) == 0 return 0; } return ScriptRuntime.toUint32(len); }
static long getLengthProperty(Context cx, Scriptable obj) { // These will both give numeric lengths within Uint32 range. if (obj instanceof NativeString) { return ((NativeString)obj).getLength(); } else if (obj instanceof NativeArray) { return ((NativeArray)obj).getLength(); } Object len = ScriptableObject.getProperty(obj, "length"); if (len == Scriptable.NOT_FOUND) { // toUint32(undefined) == 0 return 0; } return ScriptRuntime.toUint32(len); }
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) { String url = "http://localhost/test.html"; HtmlPage htmlPage = webClient.getPage(url); NativeArray array = (NativeArray) htmlPage.executeJavaScript("arMailRuMessages").getJavaScriptResult(); for (int i = 0; i < array.getLength(); i++) { NativeObject object = (NativeObject) array.get(i); String id = (String) object.get("id"); System.out.println(id); NativeObject correspondents = (NativeObject) object.get("correspondents"); NativeArray from = (NativeArray) correspondents.get("from"); System.out.println(((NativeObject) from.get(0)).get("name")); } }
public Object convert( final Object o ) { if ( o instanceof NativeJavaObject ) { final NativeJavaObject object = (NativeJavaObject) o; return object.unwrap(); } if ( o instanceof NativeArray ) { final NativeArray array = (NativeArray) o; final Object[] result = new Object[(int) array.getLength()]; for ( final Object val : array.getIds() ) { final int index = (Integer) val; result[index] = array.get( index, null ); } return result; } return null; } }