src/jdk/nashorn/internal/runtime/ScriptObject.java
Print this page
@@ -118,13 +118,10 @@
private PropertyMap map;
/** objects proto. */
private ScriptObject proto;
- /** Context of the object, lazily cached. */
- private Context context;
-
/** Object flags. */
private int flags;
/** Area for properties added to object after instantiation, see {@link AccessorProperty} */
public Object[] spill;
@@ -1041,44 +1038,15 @@
public void setArgument(final int key, final Object value) {
set(key, value, false);
}
/**
- * Return true if the script object context is strict
- * @return true if strict context
- */
- public final boolean isStrictContext() {
- return getContext()._strict;
- }
-
- /**
- * Checks if this object belongs to the given context
- * @param ctx context to check against
- * @return true if this object belongs to the given context
- */
- public final boolean isOfContext(final Context ctx) {
- return context == ctx;
- }
-
- /**
* Return the current context from the object's map.
* @return Current context.
*/
- protected final Context getContext() {
- if (context == null) {
- context = Context.fromClass(getClass());
- }
- return context;
- }
-
- /**
- * Set the current context.
- * @param ctx context instance to set
- */
- protected final void setContext(final Context ctx) {
- ctx.getClass();
- this.context = ctx;
+ protected Context getContext() {
+ return Context.fromClass(getClass());
}
/**
* Return the map of an object.
* @return PropertyMap object.
@@ -1480,13 +1448,14 @@
}
/**
* Clears the properties from a ScriptObject
* (java.util.Map-like method to help ScriptObjectMirror implementation)
+ *
+ * @param strict strict mode or not
*/
- public void clear() {
- final boolean strict = isStrictContext();
+ public void clear(final boolean strict) {
final Iterator<String> iter = propertyIterator();
while (iter.hasNext()) {
delete(iter.next(), strict);
}
}
@@ -1566,57 +1535,48 @@
* Put a property in the ScriptObject
* (java.util.Map-like method to help ScriptObjectMirror implementation)
*
* @param key property key
* @param value property value
+ * @param strict strict mode or not
* @return oldValue if property with same key existed already
*/
- public Object put(final Object key, final Object value) {
+ public Object put(final Object key, final Object value, final boolean strict) {
final Object oldValue = get(key);
- set(key, value, isStrictContext());
+ set(key, value, strict);
return oldValue;
}
/**
* Put several properties in the ScriptObject given a mapping
* of their keys to their values
* (java.util.Map-like method to help ScriptObjectMirror implementation)
*
* @param otherMap a {@literal <key,value>} map of properties to add
+ * @param strict strict mode or not
*/
- public void putAll(final Map<?, ?> otherMap) {
- final boolean strict = isStrictContext();
+ public void putAll(final Map<?, ?> otherMap, final boolean strict) {
for (final Map.Entry<?, ?> entry : otherMap.entrySet()) {
set(entry.getKey(), entry.getValue(), strict);
}
}
/**
* Remove a property from the ScriptObject.
* (java.util.Map-like method to help ScriptObjectMirror implementation)
*
* @param key the key of the property
+ * @param strict strict mode or not
* @return the oldValue of the removed property
*/
- public Object remove(final Object key) {
+ public Object remove(final Object key, final boolean strict) {
final Object oldValue = get(key);
- delete(key, isStrictContext());
+ delete(key, strict);
return oldValue;
}
/**
- * Delete a property from the ScriptObject.
- * (to help ScriptObjectMirror implementation)
- *
- * @param key the key of the property
- * @return if the delete was successful or not
- */
- public boolean delete(final Object key) {
- return delete(key, isStrictContext());
- }
-
- /**
* Return the size of the ScriptObject - i.e. the number of properties
* it contains
* (java.util.Map-like method to help ScriptObjectMirror implementation)
*
* @return number of properties in ScriptObject
@@ -2331,15 +2291,13 @@
final long arrayLength = getArray().length();
if (newLength == arrayLength) {
return;
}
- final boolean isStrict = isStrictContext();
-
if (newLength > arrayLength) {
setArray(getArray().ensure(newLength - 1));
- if (getArray().canDelete(arrayLength, (newLength - 1), isStrict)) {
+ if (getArray().canDelete(arrayLength, (newLength - 1), false)) {
setArray(getArray().delete(arrayLength, (newLength - 1)));
}
return;
}