< prev index next >

src/jdk.scripting.nashorn/share/classes/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 ----
*** 186,196 **** //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 */ --- 185,194 ----
*** 1085,1109 **** } 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()); --- 1083,1092 ----
*** 2802,2823 **** 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)) { --- 2785,2794 ----
*** 2825,2916 **** } return getInt(index, JSType.toString(key), programPoint); } - private long getLong(final int index, final Object 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.toPropertyKey(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 Object key, final int programPoint) { if (isValidArrayIndex(index)) { for (ScriptObject object = this; ; ) { if (object.getMap().containsArrayKeys()) { final FindProperty find = object.findProperty(key, false, this); --- 2796,2805 ----
*** 2966,2987 **** 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)) { --- 2855,2864 ----
*** 3047,3068 **** 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)) { --- 2924,2933 ----
*** 3141,3159 **** 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); --- 3006,3015 ----
*** 3256,3285 **** final Object propName = JSType.toPropertyKey(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 Object propName = JSType.toPropertyKey(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)) { --- 3112,3121 ----
*** 3335,3363 **** 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(); --- 3171,3180 ----
*** 3392,3477 **** 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(); --- 3209,3218 ----
*** 3485,3513 **** 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(); --- 3226,3235 ----
*** 3555,3570 **** 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); } --- 3277,3286 ----
*** 3593,3608 **** 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); } --- 3309,3318 ----
*** 3624,3649 **** } 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)) { --- 3334,3343 ----
< prev index next >