![JAR search and dependency download from the Maven repository](/logo.png)
org.mozilla.javascript.NativeJavaList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rhino-runtime Show documentation
Show all versions of rhino-runtime Show documentation
Rhino is an open-source implementation of JavaScript written entirely in Java.
It is typically embedded into Java applications to provide scripting to end users.
The newest version!
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.javascript;
import java.util.ArrayList;
import java.util.List;
/**
* NativeJavaList
is a wrapper for java objects implementing java.util.List
*
interface. This wrapper delegates index based access in javascript (like
* value[x] = 3
) to the according {@link List#get(int)}, {@link List#set(int, Object)} and
* {@link List#add(Object)} methods. This allows you to use java lists in many places like a
* javascript Array
.
*
* Supported functions:
*
*
* - index based access is delegated to List.get/set/add. If
index >= length
,
* the skipped elements will be filled with null
values
* - iterator support with
for...of
(provided by NativeJavaObject for all
* iterables)
* - when iterating with
for .. in
(or for each .. in
) then
* getIds
*
+ index based access is used.
* - reading and setting
length
property. When modifying the length property, the
* list is either truncated or will be filled with null
values up to length
*
* - deleting entries:
delete value[index]
will be equivalent with
* value[index] = null
and is implemented to provide array compatibility.
*
*
* Important: JavaList does not support sparse arrays. So setting the length property to a
* high value or writing to a high index may allocate a lot of memory.
*
* Note: Although JavaList
looks like a javascript-Array
, it is
* not an
* Array
. Some methods behave very similar like Array.indexOf
and
* java.util.List.indexOf
, others are named differently like Array.includes
vs.
* java.util.List.contains
. Especially forEach
is different in Array
*
and java.util.List
. Also deleting entries will set entries to null
*
instead to Undefined
*/
public class NativeJavaList extends NativeJavaObject {
private static final long serialVersionUID = 660285467829047519L;
private List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy