use of com.github.anba.es6draft.runtime.AbstractOperations.IsConstructor in project es6draft by anba.
the class ArrayBufferConstructor method CloneArrayBuffer.
/**
* 24.1.1.4 CloneArrayBuffer (srcBuffer, srcByteOffset)
*
* @param cx
* the execution context
* @param srcBuffer
* the source buffer
* @param srcByteOffset
* the source offset
* @param cloneConstructor
* the intrinsic constructor function
* @return the new array buffer object
*/
public static ArrayBufferObject CloneArrayBuffer(ExecutionContext cx, ArrayBuffer srcBuffer, long srcByteOffset, Intrinsics cloneConstructor) {
/* step 1 (implicit) */
/* steps 2-3 */
Constructor bufferConstructor;
if (cloneConstructor == null) {
/* steps 2.a-b */
bufferConstructor = SpeciesConstructor(cx, srcBuffer, Intrinsics.ArrayBuffer);
/* step 2.c */
if (IsDetachedBuffer(srcBuffer)) {
throw newTypeError(cx, Messages.Key.BufferDetached);
}
} else {
/* step 3 */
assert IsConstructor(cx.getIntrinsic(cloneConstructor));
bufferConstructor = (Constructor) cx.getIntrinsic(cloneConstructor);
}
/* step 4 */
ByteBuffer srcBlock = srcBuffer.getData();
/* step 5 */
long srcLength = srcBuffer.getByteLength();
/* step 6 */
assert srcByteOffset <= srcLength;
/* step 7 */
long cloneLength = srcLength - srcByteOffset;
/* steps 8-9 */
ArrayBufferObject targetBuffer = AllocateArrayBuffer(cx, bufferConstructor, cloneLength);
/* step 10 */
if (IsDetachedBuffer(srcBuffer)) {
throw newTypeError(cx, Messages.Key.BufferDetached);
}
/* step 11 */
ByteBuffer targetBlock = targetBuffer.getData();
/* step 12 */
CopyDataBlockBytes(targetBlock, 0, srcBlock, srcByteOffset, cloneLength);
/* step 13 */
return targetBuffer;
}
Aggregations