124 /** Seed getter for the primitive version of this field (in -Dnashorn.fields.dual=true mode) */
125 private MethodHandle primitiveGetter;
126
127 /** Seed setter for the primitive version of this field (in -Dnashorn.fields.dual=true mode) */
128 private MethodHandle primitiveSetter;
129
130 /** Seed getter for the Object version of this field */
131 private MethodHandle objectGetter;
132
133 /** Seed setter for the Object version of this field */
134 private MethodHandle objectSetter;
135
136 /**
137 * Current type of this object, in object only mode, this is an Object.class. In dual-fields mode
138 * null means undefined, and primitive types are allowed. The reason a special type is used for
139 * undefined, is that are no bits left to represent it in primitive types
140 */
141 private Class<?> currentType;
142
143 /**
144 * Delegate constructor. This is used when adding properties to the Global scope, which
145 * is necessary for outermost levels in a script (the ScriptObject is represented by
146 * a JO-prefixed ScriptObject class, but the properties need to be in the Global scope
147 * and are thus rebound with that as receiver
148 *
149 * @param property accessor property to rebind
150 * @param delegate delegate object to rebind receiver to
151 */
152 AccessorProperty(final AccessorProperty property, final Object delegate) {
153 super(property);
154
155 this.primitiveGetter = bindTo(property.primitiveGetter, delegate);
156 this.primitiveSetter = bindTo(property.primitiveSetter, delegate);
157 this.objectGetter = bindTo(property.ensureObjectGetter(), delegate);
158 this.objectSetter = bindTo(property.ensureObjectSetter(), delegate);
159
160 setCurrentType(property.getCurrentType());
161 }
162
163 /**
164 * Constructor for spill properties. Array getters and setters will be created on demand.
165 *
166 * @param key the property key
167 * @param flags the property flags
168 * @param slot spill slot
169 */
170 public AccessorProperty(final String key, final int flags, final int slot) {
171 super(key, flags, slot);
172 assert (flags & IS_SPILL) == IS_SPILL;
173
174 setCurrentType(Object.class);
175 }
176
177 /**
178 * Constructor. Similar to the constructor with both primitive getters and setters, the difference
179 * here being that only one getter and setter (setter is optional for non writable fields) is given
|
124 /** Seed getter for the primitive version of this field (in -Dnashorn.fields.dual=true mode) */
125 private MethodHandle primitiveGetter;
126
127 /** Seed setter for the primitive version of this field (in -Dnashorn.fields.dual=true mode) */
128 private MethodHandle primitiveSetter;
129
130 /** Seed getter for the Object version of this field */
131 private MethodHandle objectGetter;
132
133 /** Seed setter for the Object version of this field */
134 private MethodHandle objectSetter;
135
136 /**
137 * Current type of this object, in object only mode, this is an Object.class. In dual-fields mode
138 * null means undefined, and primitive types are allowed. The reason a special type is used for
139 * undefined, is that are no bits left to represent it in primitive types
140 */
141 private Class<?> currentType;
142
143 /**
144 * Delegate constructor for bound properties. This is used for properties created by
145 * {@link ScriptRuntime#mergeScope} and the Nashorn {@code Object.bindProperties} method.
146 * The former is used to add a script's defined globals to the current global scope while
147 * still storing them in a JO-prefixed ScriptObject class.
148 *
149 * <p>All properties created by this constructor have the {@link #IS_BOUND} flag set.</p>
150 *
151 * @param property accessor property to rebind
152 * @param delegate delegate object to rebind receiver to
153 */
154 AccessorProperty(final AccessorProperty property, final Object delegate) {
155 super(property);
156
157 this.primitiveGetter = bindTo(property.primitiveGetter, delegate);
158 this.primitiveSetter = bindTo(property.primitiveSetter, delegate);
159 this.objectGetter = bindTo(property.ensureObjectGetter(), delegate);
160 this.objectSetter = bindTo(property.ensureObjectSetter(), delegate);
161
162 // Properties created this way are bound to a delegate
163 this.flags |= IS_BOUND;
164 setCurrentType(property.getCurrentType());
165 }
166
167 /**
168 * Constructor for spill properties. Array getters and setters will be created on demand.
169 *
170 * @param key the property key
171 * @param flags the property flags
172 * @param slot spill slot
173 */
174 public AccessorProperty(final String key, final int flags, final int slot) {
175 super(key, flags, slot);
176 assert (flags & IS_SPILL) == IS_SPILL;
177
178 setCurrentType(Object.class);
179 }
180
181 /**
182 * Constructor. Similar to the constructor with both primitive getters and setters, the difference
183 * here being that only one getter and setter (setter is optional for non writable fields) is given
|