Search in sources :

Example 1 with ArrayBuffer

use of com.github.anba.es6draft.runtime.objects.binary.ArrayBuffer in project es6draft by anba.

the class AtomicsObject method ValidateSharedIntegerTypedArray.

/**
     * Runtime semantics: ValidateSharedIntegerTypedArray( typedArray [, onlyInt32] )
     * 
     * @param cx
     *            the execution context
     * @param typedArray
     *            the typed array object
     * @param onlyInt32
     *            if {@code true} only Int32 typed arrays are accepted
     * @return the typed array object
     */
public static TypedArrayObject ValidateSharedIntegerTypedArray(ExecutionContext cx, Object typedArray, boolean onlyInt32) {
    /* step 1, step 5 */
    if (!(typedArray instanceof TypedArrayObject)) {
        throw newTypeError(cx, Messages.Key.IncompatibleObject);
    }
    /* step 2 */
    TypedArrayObject array = (TypedArrayObject) typedArray;
    /* steps 3-4 */
    if (onlyInt32) {
        if (array.getElementType() != ElementType.Int32) {
            throw newTypeError(cx, Messages.Key.AtomicsInt32ArrayType);
        }
    } else {
        switch(array.getElementType()) {
            case Int8:
            case Uint8:
            case Int16:
            case Uint16:
            case Int32:
            case Uint32:
                break;
            default:
                throw newTypeError(cx, Messages.Key.AtomicsInvalidArrayType);
        }
    }
    /* step 6 */
    ArrayBuffer buffer = array.getBuffer();
    /* step 8 */
    if (!(buffer instanceof SharedArrayBufferObject)) {
        throw newTypeError(cx, Messages.Key.AtomicsNotSharedBuffer);
    }
    /* step 9 */
    return array;
}
Also used : TypedArrayObject(com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject) ArrayBuffer(com.github.anba.es6draft.runtime.objects.binary.ArrayBuffer)

Aggregations

ArrayBuffer (com.github.anba.es6draft.runtime.objects.binary.ArrayBuffer)1 TypedArrayObject (com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject)1