MCPcopy Create free account
hub / github.com/mozilla/rhino / SlotMap

Interface SlotMap

rhino/src/main/java/org/mozilla/javascript/SlotMap.java:18–94  ·  view source on GitHub ↗

A SlotMap is an interface to the main data structure that contains all the "Slots" that back a ScriptableObject. It is the primary property map in Rhino. It is Iterable but does not implement java.util.Map because that comes with a bunch of overhead that we do not need. This class generally has

Source from the content-addressed store, hash-verified

16 * substantial performance regressions so we are doing the best that we can.
17 */
18public interface SlotMap<T extends PropHolder<T>> extends Iterable<Slot<T>> {
19
20 @SuppressWarnings("AndroidJdkLibsChecker")
21 // https://developer.android.com/reference/java/lang/FunctionalInterface added in API level 24
22 @FunctionalInterface
23 public interface SlotComputer<S extends Slot<T>, T extends PropHolder<T>> {
24 S compute(
25 Object key,
26 int index,
27 Slot<T> existing,
28 CompoundOperationMap<T> mutableMap,
29 SlotMapOwner<T> owner);
30 }
31
32 /** Return the size of the map. */
33 int size();
34
35 /** Return whether the map is empty. */
36 boolean isEmpty();
37
38 /**
39 * Return the Slot that matches EITHER "key" or "index". (It will use "key" if it is not null,
40 * and otherwise "index".) If no slot exists, then create a default slot class.
41 *
42 * @param key The key for the slot, which should be a String or a Symbol.
43 * @param index if key is zero, then this will be used as the key instead.
44 * @param attributes the attributes to be set on the slot if a new slot is created. Existing
45 * slots will not be modified.
46 * @return a Slot, which will be created anew if no such slot exists.
47 */
48 Slot<T> modify(SlotMapOwner<T> owner, Object key, int index, int attributes);
49
50 /**
51 * Retrieve the slot at EITHER key or index, or return null if the slot cannot be found.
52 *
53 * @param key The key for the slot, which should be a String or a Symbol.
54 * @param index if key is zero, then this will be used as the key instead.
55 * @return either the Slot that matched the key and index, or null
56 */
57 Slot<T> query(Object key, int index);
58
59 /**
60 * Replace the value of key with the slot computed by the "compute" method. If "compute" throws
61 * an exception, make no change. If "compute" returns null, remove the mapping, otherwise,
62 * replace any existing mapping with the result of "compute", and create a new mapping if none
63 * exists. This is equivalent to the "compute" method on the Map interface, which simplifies
64 * code and is more efficient than making multiple calls to this interface. In order to allow
65 * use of multiple Slot subclasses, this function is templatized.
66 */
67 default <S extends Slot<T>> S compute(
68 SlotMapOwner<T> owner, Object key, int index, SlotComputer<S, T> compute) {
69 try (var mutableMap = owner.startCompoundOp(true)) {
70 return mutableMap.compute(owner, mutableMap, key, index, compute);
71 }
72 }
73
74 <S extends Slot<T>> S compute(
75 SlotMapOwner<T> owner,

Callers 62

live-connect.jsFile · 0.65
beautifyElementMethod · 0.65
childrenMethod · 0.65
getNamespacesMethod · 0.65
getMatchingChildrenMethod · 0.65
lengthMethod · 0.65
findRhinoFactoryMethod · 0.65
getTestOptLevelsMethod · 0.65
assertExceptionMethod · 0.65

Calls

no outgoing calls

Tested by

no test coverage detected