< prev index next >
src/jdk/nashorn/internal/runtime/ScriptObject.java
Print this page
*** 31,41 ****
import static jdk.nashorn.internal.lookup.Lookup.MH;
import static jdk.nashorn.internal.runtime.ECMAErrors.referenceError;
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
import static jdk.nashorn.internal.runtime.JSType.UNDEFINED_DOUBLE;
import static jdk.nashorn.internal.runtime.JSType.UNDEFINED_INT;
- import static jdk.nashorn.internal.runtime.JSType.UNDEFINED_LONG;
import static jdk.nashorn.internal.runtime.PropertyDescriptor.CONFIGURABLE;
import static jdk.nashorn.internal.runtime.PropertyDescriptor.ENUMERABLE;
import static jdk.nashorn.internal.runtime.PropertyDescriptor.GET;
import static jdk.nashorn.internal.runtime.PropertyDescriptor.SET;
import static jdk.nashorn.internal.runtime.PropertyDescriptor.VALUE;
--- 31,40 ----
*** 184,194 ****
//TODO fastpath this
public static final Call SET_USER_ACCESSORS = virtualCall(MethodHandles.lookup(), ScriptObject.class, "setUserAccessors", void.class, String.class, ScriptFunction.class, ScriptFunction.class);
static final MethodHandle[] SET_SLOW = new MethodHandle[] {
findOwnMH_V("set", void.class, Object.class, int.class, int.class),
- findOwnMH_V("set", void.class, Object.class, long.class, int.class),
findOwnMH_V("set", void.class, Object.class, double.class, int.class),
findOwnMH_V("set", void.class, Object.class, Object.class, int.class)
};
/** Method handle to reset the map of this ScriptObject */
--- 183,192 ----
*** 1084,1108 ****
}
return UNDEFINED_INT;
}
- private static long getLongValue(final FindProperty find, final int programPoint) {
- final MethodHandle getter = find.getGetter(long.class, programPoint, null);
- if (getter != null) {
- try {
- return (long)getter.invokeExact((Object)find.getGetterReceiver());
- } catch (final Error|RuntimeException e) {
- throw e;
- } catch (final Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- return UNDEFINED_LONG;
- }
-
private static double getDoubleValue(final FindProperty find, final int programPoint) {
final MethodHandle getter = find.getGetter(double.class, programPoint, null);
if (getter != null) {
try {
return (double)getter.invokeExact((Object)find.getGetterReceiver());
--- 1082,1091 ----
*** 2766,2787 ****
return getInt(index, JSType.toString(key), programPoint);
}
@Override
- public int getInt(final long key, final int programPoint) {
- final int index = getArrayIndex(key);
- final ArrayData array = getArray();
-
- if (array.has(index)) {
- return isValid(programPoint) ? array.getIntOptimistic(index, programPoint) : array.getInt(index);
- }
-
- return getInt(index, JSType.toString(key), programPoint);
- }
-
- @Override
public int getInt(final int key, final int programPoint) {
final int index = getArrayIndex(key);
final ArrayData array = getArray();
if (array.has(index)) {
--- 2749,2758 ----
*** 2789,2880 ****
}
return getInt(index, JSType.toString(key), programPoint);
}
- private long getLong(final int index, final String key, final int programPoint) {
- if (isValidArrayIndex(index)) {
- for (ScriptObject object = this; ; ) {
- if (object.getMap().containsArrayKeys()) {
- final FindProperty find = object.findProperty(key, false, this);
- if (find != null) {
- return getLongValue(find, programPoint);
- }
- }
-
- if ((object = object.getProto()) == null) {
- break;
- }
-
- final ArrayData array = object.getArray();
-
- if (array.has(index)) {
- return isValid(programPoint) ?
- array.getLongOptimistic(index, programPoint) :
- array.getLong(index);
- }
- }
- } else {
- final FindProperty find = findProperty(key, true);
-
- if (find != null) {
- return getLongValue(find, programPoint);
- }
- }
-
- return JSType.toLong(invokeNoSuchProperty(key, false, programPoint));
- }
-
- @Override
- public long getLong(final Object key, final int programPoint) {
- final Object primitiveKey = JSType.toPrimitive(key, String.class);
- final int index = getArrayIndex(primitiveKey);
- final ArrayData array = getArray();
-
- if (array.has(index)) {
- return isValid(programPoint) ? array.getLongOptimistic(index, programPoint) : array.getLong(index);
- }
-
- return getLong(index, JSType.toString(primitiveKey), programPoint);
- }
-
- @Override
- public long getLong(final double key, final int programPoint) {
- final int index = getArrayIndex(key);
- final ArrayData array = getArray();
-
- if (array.has(index)) {
- return isValid(programPoint) ? array.getLongOptimistic(index, programPoint) : array.getLong(index);
- }
-
- return getLong(index, JSType.toString(key), programPoint);
- }
-
- @Override
- public long getLong(final long key, final int programPoint) {
- final int index = getArrayIndex(key);
- final ArrayData array = getArray();
-
- if (array.has(index)) {
- return isValid(programPoint) ? array.getLongOptimistic(index, programPoint) : array.getLong(index);
- }
-
- return getLong(index, JSType.toString(key), programPoint);
- }
-
- @Override
- public long getLong(final int key, final int programPoint) {
- final int index = getArrayIndex(key);
- final ArrayData array = getArray();
-
- if (array.has(index)) {
- return isValid(programPoint) ? array.getLongOptimistic(key, programPoint) : array.getLong(key);
- }
-
- return getLong(index, JSType.toString(key), programPoint);
- }
-
private double getDouble(final int index, final String key, final int programPoint) {
if (isValidArrayIndex(index)) {
for (ScriptObject object = this; ; ) {
if (object.getMap().containsArrayKeys()) {
final FindProperty find = object.findProperty(key, false, this);
--- 2760,2769 ----
*** 2930,2951 ****
return getDouble(index, JSType.toString(key), programPoint);
}
@Override
- public double getDouble(final long key, final int programPoint) {
- final int index = getArrayIndex(key);
- final ArrayData array = getArray();
-
- if (array.has(index)) {
- return isValid(programPoint) ? array.getDoubleOptimistic(index, programPoint) : array.getDouble(index);
- }
-
- return getDouble(index, JSType.toString(key), programPoint);
- }
-
- @Override
public double getDouble(final int key, final int programPoint) {
final int index = getArrayIndex(key);
final ArrayData array = getArray();
if (array.has(index)) {
--- 2819,2828 ----
*** 3011,3032 ****
return get(index, JSType.toString(key));
}
@Override
- public Object get(final long key) {
- final int index = getArrayIndex(key);
- final ArrayData array = getArray();
-
- if (array.has(index)) {
- return array.getObject(index);
- }
-
- return get(index, JSType.toString(key));
- }
-
- @Override
public Object get(final int key) {
final int index = getArrayIndex(key);
final ArrayData array = getArray();
if (array.has(index)) {
--- 2888,2897 ----
*** 3105,3123 ****
final boolean strict = isStrictFlag(callSiteFlags);
setArray(getArray().set(index, value, strict).safeDelete(oldLength, longIndex - 1, strict));
}
}
- private void doesNotHave(final int index, final long value, final int callSiteFlags) {
- final long oldLength = getArray().length();
- final long longIndex = ArrayIndex.toLongIndex(index);
- if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) {
- final boolean strict = isStrictFlag(callSiteFlags);
- setArray(getArray().set(index, value, strict).safeDelete(oldLength, longIndex - 1, strict));
- }
- }
-
private void doesNotHave(final int index, final double value, final int callSiteFlags) {
final long oldLength = getArray().length();
final long longIndex = ArrayIndex.toLongIndex(index);
if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) {
final boolean strict = isStrictFlag(callSiteFlags);
--- 2970,2979 ----
*** 3220,3249 ****
final String propName = JSType.toString(primitiveKey);
setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value));
}
@Override
- public void set(final Object key, final long value, final int callSiteFlags) {
- final Object primitiveKey = JSType.toPrimitive(key, String.class);
- final int index = getArrayIndex(primitiveKey);
-
- if (isValidArrayIndex(index)) {
- final ArrayData data = getArray();
- if (data.has(index)) {
- setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
- } else {
- doesNotHave(index, value, callSiteFlags);
- }
-
- return;
- }
-
- final String propName = JSType.toString(primitiveKey);
- setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value));
- }
-
- @Override
public void set(final Object key, final double value, final int callSiteFlags) {
final Object primitiveKey = JSType.toPrimitive(key, String.class);
final int index = getArrayIndex(primitiveKey);
if (isValidArrayIndex(index)) {
--- 3076,3085 ----
*** 3299,3327 ****
final String propName = JSType.toString(key);
setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value));
}
@Override
- public void set(final double key, final long value, final int callSiteFlags) {
- final int index = getArrayIndex(key);
-
- if (isValidArrayIndex(index)) {
- final ArrayData data = getArray();
- if (data.has(index)) {
- setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
- } else {
- doesNotHave(index, value, callSiteFlags);
- }
-
- return;
- }
-
- final String propName = JSType.toString(key);
- setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value));
- }
-
- @Override
public void set(final double key, final double value, final int callSiteFlags) {
final int index = getArrayIndex(key);
if (isValidArrayIndex(index)) {
final ArrayData data = getArray();
--- 3135,3144 ----
*** 3356,3441 ****
final String propName = JSType.toString(key);
setObject(findProperty(propName, true), callSiteFlags, propName, value);
}
@Override
- public void set(final long key, final int value, final int callSiteFlags) {
- final int index = getArrayIndex(key);
-
- if (isValidArrayIndex(index)) {
- final ArrayData data = getArray();
- if (data.has(index)) {
- setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
- } else {
- doesNotHave(index, value, callSiteFlags);
- }
-
- return;
- }
-
- final String propName = JSType.toString(key);
- setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value));
- }
-
- @Override
- public void set(final long key, final long value, final int callSiteFlags) {
- final int index = getArrayIndex(key);
-
- if (isValidArrayIndex(index)) {
- final ArrayData data = getArray();
- if (data.has(index)) {
- setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
- } else {
- doesNotHave(index, value, callSiteFlags);
- }
-
- return;
- }
-
- final String propName = JSType.toString(key);
- setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value));
- }
-
- @Override
- public void set(final long key, final double value, final int callSiteFlags) {
- final int index = getArrayIndex(key);
-
- if (isValidArrayIndex(index)) {
- final ArrayData data = getArray();
- if (data.has(index)) {
- setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
- } else {
- doesNotHave(index, value, callSiteFlags);
- }
-
- return;
- }
-
- final String propName = JSType.toString(key);
- setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value));
- }
-
- @Override
- public void set(final long key, final Object value, final int callSiteFlags) {
- final int index = getArrayIndex(key);
-
- if (isValidArrayIndex(index)) {
- final ArrayData data = getArray();
- if (data.has(index)) {
- setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
- } else {
- doesNotHave(index, value, callSiteFlags);
- }
-
- return;
- }
-
- final String propName = JSType.toString(key);
- setObject(findProperty(propName, true), callSiteFlags, propName, value);
- }
-
- @Override
public void set(final int key, final int value, final int callSiteFlags) {
final int index = getArrayIndex(key);
if (isValidArrayIndex(index)) {
if (getArray().has(index)) {
final ArrayData data = getArray();
--- 3173,3182 ----
*** 3449,3477 ****
final String propName = JSType.toString(key);
setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value));
}
@Override
- public void set(final int key, final long value, final int callSiteFlags) {
- final int index = getArrayIndex(key);
-
- if (isValidArrayIndex(index)) {
- final ArrayData data = getArray();
- if (data.has(index)) {
- setArray(data.set(index, value, isStrictFlag(callSiteFlags)));
- } else {
- doesNotHave(index, value, callSiteFlags);
- }
-
- return;
- }
-
- final String propName = JSType.toString(key);
- setObject(findProperty(propName, true), callSiteFlags, propName, JSType.toObject(value));
- }
-
- @Override
public void set(final int key, final double value, final int callSiteFlags) {
final int index = getArrayIndex(key);
if (isValidArrayIndex(index)) {
final ArrayData data = getArray();
--- 3190,3199 ----
*** 3519,3534 ****
final int index = getArrayIndex(key);
return isValidArrayIndex(index) ? hasArrayProperty(index) : hasProperty(JSType.toString(key), true);
}
@Override
- public boolean has(final long key) {
- final int index = getArrayIndex(key);
- return isValidArrayIndex(index) ? hasArrayProperty(index) : hasProperty(JSType.toString(key), true);
- }
-
- @Override
public boolean has(final int key) {
final int index = getArrayIndex(key);
return isValidArrayIndex(index) ? hasArrayProperty(index) : hasProperty(JSType.toString(key), true);
}
--- 3241,3250 ----
*** 3557,3572 ****
final int index = getArrayIndex(key);
return isValidArrayIndex(index) ? hasOwnArrayProperty(index) : hasProperty(JSType.toString(key), false);
}
@Override
- public boolean hasOwnProperty(final long key) {
- final int index = getArrayIndex(key);
- return isValidArrayIndex(index) ? hasOwnArrayProperty(index) : hasProperty(JSType.toString(key), false);
- }
-
- @Override
public boolean hasOwnProperty(final double key) {
final int index = getArrayIndex(key);
return isValidArrayIndex(index) ? hasOwnArrayProperty(index) : hasProperty(JSType.toString(key), false);
}
--- 3273,3282 ----
*** 3588,3613 ****
}
return deleteObject(JSType.toObject(key), strict);
}
@Override
- public boolean delete(final long key, final boolean strict) {
- final int index = getArrayIndex(key);
- final ArrayData array = getArray();
-
- if (array.has(index)) {
- if (array.canDelete(index, strict)) {
- setArray(array.delete(index));
- return true;
- }
- return false;
- }
-
- return deleteObject(JSType.toObject(key), strict);
- }
-
- @Override
public boolean delete(final double key, final boolean strict) {
final int index = getArrayIndex(key);
final ArrayData array = getArray();
if (array.has(index)) {
--- 3298,3307 ----
< prev index next >