Java Code Examples for jdk.nashorn.internal.runtime.arrays.ArrayIndex#toLongIndex()

The following examples show how to use jdk.nashorn.internal.runtime.arrays.ArrayIndex#toLongIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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);
        setArray(getArray().set(index, value, strict).safeDelete(oldLength, longIndex - 1, strict));
    }
}
 
Example 2
Source File: ScriptObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void doesNotHave(final int index, final int 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));
    }
}
 
Example 3
Source File: ScriptObject.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private void doesNotHave(final int index, final int 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));
    }
}
 
Example 4
Source File: ScriptObject.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void doesNotHave(final int index, final int 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));
    }
}
 
Example 5
Source File: JSONParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayData addArrayElement(final ArrayData arrayData, final int index, final Object value) {
    final long oldLength = arrayData.length();
    final long longIndex = ArrayIndex.toLongIndex(index);
    ArrayData newArrayData = arrayData;
    if (longIndex >= oldLength) {
        newArrayData = newArrayData.ensure(longIndex);
        if (longIndex > oldLength) {
            newArrayData = newArrayData.delete(oldLength, longIndex - 1);
        }
    }
    return newArrayData.set(index, value, false);
}
 
Example 6
Source File: ScriptObject.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void doesNotHave(final int index, final int 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));
        doesNotHaveEnsureDelete(longIndex, oldLength, strict);
    }
}
 
Example 7
Source File: ScriptObject.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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));
        doesNotHaveEnsureDelete(longIndex, oldLength, strict);
    }
}
 
Example 8
Source File: ScriptObject.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
        setArray(getArray().set(index, value, strict));
        doesNotHaveEnsureDelete(longIndex, oldLength, strict);
    }
}
 
Example 9
Source File: ScriptObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void doesNotHave(final int index, final Object 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));
    }
}
 
Example 10
Source File: JSONParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayData addArrayElement(final ArrayData arrayData, final int index, final Object value) {
    final long oldLength = arrayData.length();
    final long longIndex = ArrayIndex.toLongIndex(index);
    ArrayData newArrayData = arrayData;
    if (longIndex >= oldLength) {
        newArrayData = newArrayData.ensure(longIndex);
        if (longIndex > oldLength) {
            newArrayData = newArrayData.delete(oldLength, longIndex - 1);
        }
    }
    return newArrayData.set(index, value, false);
}
 
Example 11
Source File: ScriptObject.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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);
        setArray(getArray().set(index, value, strict).safeDelete(oldLength, longIndex - 1, strict));
    }
}
 
Example 12
Source File: JSONParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static ArrayData addArrayElement(final ArrayData arrayData, final int index, final Object value) {
    final long oldLength = arrayData.length();
    final long longIndex = ArrayIndex.toLongIndex(index);
    ArrayData newArrayData = arrayData;
    if (longIndex >= oldLength) {
        newArrayData = newArrayData.ensure(longIndex);
        if (longIndex > oldLength) {
            newArrayData = newArrayData.delete(oldLength, longIndex - 1);
        }
    }
    return newArrayData.set(index, value, false);
}
 
Example 13
Source File: ScriptObject.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void doesNotHave(final int index, final Object 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));
    }
}
 
Example 14
Source File: ScriptObject.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void doesNotHave(final int index, final Object 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));
    }
}
 
Example 15
Source File: NativeArray.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ECMA 15.4.5.1 [[DefineOwnProperty]] ( P, Desc, Throw )
 */
@Override
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
    final PropertyDescriptor desc = toPropertyDescriptor(Global.instance(), propertyDesc);

    // never be undefined as "length" is always defined and can't be deleted for arrays
    // Step 1
    final PropertyDescriptor oldLenDesc = (PropertyDescriptor) super.getOwnPropertyDescriptor("length");

    // Step 2
    // get old length and convert to long. Always a Long/Uint32 but we take the safe road.
    final long oldLen = JSType.toUint32(oldLenDesc.getValue());

    // Step 3
    if ("length".equals(key)) {
        // check for length being made non-writable
        final boolean result = defineLength(oldLen, oldLenDesc, desc, reject);
        if (desc.has(WRITABLE) && !desc.isWritable()) {
            setIsLengthNotWritable();
        }
        return result;
    }

    // Step 4a
    final int index = ArrayIndex.getArrayIndex(key);
    if (ArrayIndex.isValidArrayIndex(index)) {
        final long longIndex = ArrayIndex.toLongIndex(index);
        // Step 4b
        // setting an element beyond current length, but 'length' is not writable
        if (longIndex >= oldLen && !oldLenDesc.isWritable()) {
            if (reject) {
                throw typeError("property.not.writable", Long.toString(longIndex), ScriptRuntime.safeToString(this));
            }
            return false;
        }

        // Step 4c
        // set the new array element
        final boolean succeeded = super.defineOwnProperty(key, desc, false);

        // Step 4d
        if (!succeeded) {
            if (reject) {
                throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
            }
            return false;
        }

        // Step 4e -- adjust new length based on new element index that is set
        if (longIndex >= oldLen) {
            oldLenDesc.setValue(longIndex + 1);
            super.defineOwnProperty("length", oldLenDesc, false);
        }

        // Step 4f
        return true;
    }

    // not an index property
    return super.defineOwnProperty(key, desc, reject);
}
 
Example 16
Source File: NativeArray.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ECMA 15.4.5.1 [[DefineOwnProperty]] ( P, Desc, Throw )
 */
@Override
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
    final PropertyDescriptor desc = toPropertyDescriptor(Global.instance(), propertyDesc);

    // never be undefined as "length" is always defined and can't be deleted for arrays
    // Step 1
    final PropertyDescriptor oldLenDesc = (PropertyDescriptor) super.getOwnPropertyDescriptor("length");

    // Step 2
    // get old length and convert to long. Always a Long/Uint32 but we take the safe road.
    final long oldLen = JSType.toUint32(oldLenDesc.getValue());

    // Step 3
    if ("length".equals(key)) {
        // check for length being made non-writable
        final boolean result = defineLength(oldLen, oldLenDesc, desc, reject);
        if (desc.has(WRITABLE) && !desc.isWritable()) {
            setIsLengthNotWritable();
        }
        return result;
    }

    // Step 4a
    final int index = ArrayIndex.getArrayIndex(key);
    if (ArrayIndex.isValidArrayIndex(index)) {
        final long longIndex = ArrayIndex.toLongIndex(index);
        // Step 4b
        // setting an element beyond current length, but 'length' is not writable
        if (longIndex >= oldLen && !oldLenDesc.isWritable()) {
            if (reject) {
                throw typeError("property.not.writable", Long.toString(longIndex), ScriptRuntime.safeToString(this));
            }
            return false;
        }

        // Step 4c
        // set the new array element
        final boolean succeeded = super.defineOwnProperty(key, desc, false);

        // Step 4d
        if (!succeeded) {
            if (reject) {
                throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
            }
            return false;
        }

        // Step 4e -- adjust new length based on new element index that is set
        if (longIndex >= oldLen) {
            oldLenDesc.setValue(longIndex + 1);
            super.defineOwnProperty("length", oldLenDesc, false);
        }

        // Step 4f
        return true;
    }

    // not an index property
    return super.defineOwnProperty(key, desc, reject);
}
 
Example 17
Source File: ScriptObject.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Handle when an array doesn't have a slot - possibly grow and/or convert array.
 *
 * @param index  key as index
 * @param value  element value
 * @param strict are we in strict mode
 */
private void doesNotHave(final int index, final Object value, final boolean strict) {
    final long oldLength = getArray().length();
    final long longIndex = ArrayIndex.toLongIndex(index);

    if (getMap().containsArrayKeys()) {
        final String key = JSType.toString(longIndex);
        final FindProperty find = findProperty(key, true);

        if (find != null) {
            setObject(find, strict, key, value);
            return;
        }
    }

    if (longIndex >= oldLength) {
        if (!isExtensible()) {
            if (strict) {
                throw typeError("object.non.extensible", JSType.toString(index), ScriptRuntime.safeToString(this));
            }
            return;
        }
        setArray(getArray().ensure(longIndex));
    }

    if (value instanceof Integer) {
        setArray(getArray().set(index, (int)value, strict));
    } else if (value instanceof Long) {
        setArray(getArray().set(index, (long)value, strict));
    } else if (value instanceof Double) {
        setArray(getArray().set(index, (double)value, strict));
    } else {
        setArray(getArray().set(index, value, strict));
    }

    if (longIndex > oldLength) {
        ArrayData array = getArray();

        if (array.canDelete(oldLength, (longIndex - 1), strict)) {
            array = array.delete(oldLength, (longIndex - 1));
        }

        setArray(array);
    }
}
 
Example 18
Source File: NativeArray.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ECMA 15.4.5.1 [[DefineOwnProperty]] ( P, Desc, Throw )
 */
@Override
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
    final PropertyDescriptor desc = toPropertyDescriptor(Global.instance(), propertyDesc);

    // never be undefined as "length" is always defined and can't be deleted for arrays
    // Step 1
    final PropertyDescriptor oldLenDesc = (PropertyDescriptor) super.getOwnPropertyDescriptor("length");

    // Step 2
    // get old length and convert to long. Always a Long/Uint32 but we take the safe road.
    final long oldLen = JSType.toUint32(oldLenDesc.getValue());

    // Step 3
    if ("length".equals(key)) {
        // check for length being made non-writable
        final boolean result = defineLength(oldLen, oldLenDesc, desc, reject);
        if (desc.has(WRITABLE) && !desc.isWritable()) {
            setIsLengthNotWritable();
        }
        return result;
    }

    // Step 4a
    final int index = ArrayIndex.getArrayIndex(key);
    if (ArrayIndex.isValidArrayIndex(index)) {
        final long longIndex = ArrayIndex.toLongIndex(index);
        // Step 4b
        // setting an element beyond current length, but 'length' is not writable
        if (longIndex >= oldLen && !oldLenDesc.isWritable()) {
            if (reject) {
                throw typeError("property.not.writable", Long.toString(longIndex), ScriptRuntime.safeToString(this));
            }
            return false;
        }

        // Step 4c
        // set the new array element
        final boolean succeeded = super.defineOwnProperty(key, desc, false);

        // Step 4d
        if (!succeeded) {
            if (reject) {
                throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
            }
            return false;
        }

        // Step 4e -- adjust new length based on new element index that is set
        if (longIndex >= oldLen) {
            oldLenDesc.setValue(longIndex + 1);
            super.defineOwnProperty("length", oldLenDesc, false);
        }

        // Step 4f
        return true;
    }

    // not an index property
    return super.defineOwnProperty(key, desc, reject);
}
 
Example 19
Source File: NativeArray.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ECMA 15.4.5.1 [[DefineOwnProperty]] ( P, Desc, Throw )
 */
@Override
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
    final PropertyDescriptor desc = toPropertyDescriptor(Global.instance(), propertyDesc);

    // never be undefined as "length" is always defined and can't be deleted for arrays
    // Step 1
    final PropertyDescriptor oldLenDesc = (PropertyDescriptor) super.getOwnPropertyDescriptor("length");

    // Step 2
    // get old length and convert to long. Always a Long/Uint32 but we take the safe road.
    final long oldLen = JSType.toUint32(oldLenDesc.getValue());

    // Step 3
    if ("length".equals(key)) {
        // check for length being made non-writable
        final boolean result = defineLength(oldLen, oldLenDesc, desc, reject);
        if (desc.has(WRITABLE) && !desc.isWritable()) {
            setIsLengthNotWritable();
        }
        return result;
    }

    // Step 4a
    final int index = ArrayIndex.getArrayIndex(key);
    if (ArrayIndex.isValidArrayIndex(index)) {
        final long longIndex = ArrayIndex.toLongIndex(index);
        // Step 4b
        // setting an element beyond current length, but 'length' is not writable
        if (longIndex >= oldLen && !oldLenDesc.isWritable()) {
            if (reject) {
                throw typeError("property.not.writable", Long.toString(longIndex), ScriptRuntime.safeToString(this));
            }
            return false;
        }

        // Step 4c
        // set the new array element
        final boolean succeeded = super.defineOwnProperty(key, desc, false);

        // Step 4d
        if (!succeeded) {
            if (reject) {
                throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
            }
            return false;
        }

        // Step 4e -- adjust new length based on new element index that is set
        if (longIndex >= oldLen) {
            oldLenDesc.setValue(longIndex + 1);
            super.defineOwnProperty("length", oldLenDesc, false);
        }

        // Step 4f
        return true;
    }

    // not an index property
    return super.defineOwnProperty(key, desc, reject);
}
 
Example 20
Source File: NativeArray.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ECMA 15.4.5.1 [[DefineOwnProperty]] ( P, Desc, Throw )
 */
@Override
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
    final PropertyDescriptor desc = toPropertyDescriptor(Global.instance(), propertyDesc);

    // never be undefined as "length" is always defined and can't be deleted for arrays
    // Step 1
    final PropertyDescriptor oldLenDesc = (PropertyDescriptor) super.getOwnPropertyDescriptor("length");

    // Step 2
    // get old length and convert to long. Always a Long/Uint32 but we take the safe road.
    final long oldLen = JSType.toUint32(oldLenDesc.getValue());

    // Step 3
    if ("length".equals(key)) {
        // check for length being made non-writable
        final boolean result = defineLength(oldLen, oldLenDesc, desc, reject);
        if (desc.has(WRITABLE) && !desc.isWritable()) {
            setIsLengthNotWritable();
        }
        return result;
    }

    // Step 4a
    final int index = ArrayIndex.getArrayIndex(key);
    if (ArrayIndex.isValidArrayIndex(index)) {
        final long longIndex = ArrayIndex.toLongIndex(index);
        // Step 4b
        // setting an element beyond current length, but 'length' is not writable
        if (longIndex >= oldLen && !oldLenDesc.isWritable()) {
            if (reject) {
                throw typeError("property.not.writable", Long.toString(longIndex), ScriptRuntime.safeToString(this));
            }
            return false;
        }

        // Step 4c
        // set the new array element
        final boolean succeeded = super.defineOwnProperty(key, desc, false);

        // Step 4d
        if (!succeeded) {
            if (reject) {
                throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
            }
            return false;
        }

        // Step 4e -- adjust new length based on new element index that is set
        if (longIndex >= oldLen) {
            oldLenDesc.setValue(longIndex + 1);
            super.defineOwnProperty("length", oldLenDesc, false);
        }

        // Step 4f
        return true;
    }

    // not an index property
    return super.defineOwnProperty(key, desc, reject);
}