Permalink
Cannot retrieve contributors at this time
49 lines (38 sloc)
1.9 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/es-abstract/2021/CloneArrayBuffer.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var GetIntrinsic = require('get-intrinsic'); | |
var $TypeError = GetIntrinsic('%TypeError%'); | |
var GetPrototypeFromConstructor = require('./GetPrototypeFromConstructor'); | |
var IsConstructor = require('./IsConstructor'); | |
var IsDetachedBuffer = require('./IsDetachedBuffer'); | |
var OrdinarySetPrototypeOf = require('./OrdinarySetPrototypeOf'); | |
var isInteger = require('../helpers/isInteger'); | |
var isArrayBuffer = require('is-array-buffer'); | |
var arrayBufferSlice = require('arraybuffer.prototype.slice'); | |
// https://262.ecma-international.org/12.0/#sec-clonearraybuffer | |
module.exports = function CloneArrayBuffer(srcBuffer, srcByteOffset, srcLength, cloneConstructor) { | |
if (!isArrayBuffer(srcBuffer)) { | |
throw new $TypeError('Assertion failed: `srcBuffer` must be an ArrayBuffer instance'); | |
} | |
if (!isInteger(srcByteOffset) || srcByteOffset < 0) { | |
throw new $TypeError('Assertion failed: `srcByteOffset` must be a non-negative integer'); | |
} | |
if (!isInteger(srcLength) || srcLength < 0) { | |
throw new $TypeError('Assertion failed: `srcLength` must be a non-negative integer'); | |
} | |
if (!IsConstructor(cloneConstructor)) { | |
throw new $TypeError('Assertion failed: `cloneConstructor` must be a constructor'); | |
} | |
// 3. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, srcLength). | |
var proto = GetPrototypeFromConstructor(cloneConstructor, '%ArrayBufferPrototype%'); // step 3, kinda | |
if (IsDetachedBuffer(srcBuffer)) { | |
throw new $TypeError('`srcBuffer` must not be a detached ArrayBuffer'); // step 4 | |
} | |
/* | |
5. Let srcBlock be srcBuffer.[[ArrayBufferData]]. | |
6. Let targetBlock be targetBuffer.[[ArrayBufferData]]. | |
7. Perform CopyDataBlockBytes(targetBlock, 0, srcBlock, srcByteOffset, srcLength). | |
*/ | |
var targetBuffer = arrayBufferSlice(srcBuffer, srcByteOffset, srcByteOffset + srcLength); // steps 5-7 | |
OrdinarySetPrototypeOf(targetBuffer, proto); // step 3 | |
return targetBuffer; // step 8 | |
}; |