Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (DESCRIPTORS) QUnit.test('Uint32 conversions', assert => {
const uint32array = new Uint32Array(1);
const uint8array = new Uint8Array(uint32array.buffer);
const dataview = new DataView(uint32array.buffer);
function viewFrom(it) {
return new DataView(new Uint8Array(it).buffer);
}
function toString(it) {
return it === 0 && 1 / it === -Infinity ? '-0' : it;
}
const data = [
[0, 0, [0, 0, 0, 0]],
[-0, 0, [0, 0, 0, 0]],
[1, 1, [1, 0, 0, 0]],
[-1, 4294967295, [255, 255, 255, 255]],
[1.1, 1, [1, 0, 0, 0]],
[-1.1, 4294967295, [255, 255, 255, 255]],
[1.9, 1, [1, 0, 0, 0]],
QUnit.test('DataView', assert => {
assert.same(DataView, Object(DataView), 'is object');
let dataview = new DataView(new ArrayBuffer(8));
assert.same(dataview.byteOffset, 0, '#byteOffset, passed buffer');
assert.same(dataview.byteLength, 8, '#byteLength, passed buffer');
dataview = new DataView(new ArrayBuffer(16), 8);
assert.same(dataview.byteOffset, 8, '#byteOffset, passed buffer and byteOffset');
assert.same(dataview.byteLength, 8, '#byteLength, passed buffer and byteOffset');
dataview = new DataView(new ArrayBuffer(24), 8, 8);
assert.same(dataview.byteOffset, 8, '#byteOffset, passed buffer, byteOffset and length');
assert.same(dataview.byteLength, 8, '#byteLength, passed buffer, byteOffset and length');
assert.throws(() => new DataView(new ArrayBuffer(8), -1), 'If offset < 0, throw a RangeError exception');
assert.throws(() => new DataView(new ArrayBuffer(8), 16), 'If newByteLength < 0, throw a RangeError exception');
assert.throws(() => new DataView(new ArrayBuffer(24), 8, 24), 'If offset+newByteLength > bufferByteLength, throw a RangeError exception');
dataview = new DataView(new ArrayBuffer(8));
dataview.setUint32(0, 0x12345678);
assert.same(dataview.getUint32(0), 0x12345678, 'big endian/big endian');
dataview.setUint32(0, 0x12345678, true);
assert.same(dataview.getUint32(0, true), 0x12345678, 'little endian/little endian');
if (DESCRIPTORS) QUnit.test('Int8 conversions', assert => {
const int8array = new Int8Array(1);
const uint8array = new Uint8Array(int8array.buffer);
const dataview = new DataView(int8array.buffer);
function viewFrom(it) {
return new DataView(new Uint8Array(it).buffer);
}
function toString(it) {
return it === 0 && 1 / it === -Infinity ? '-0' : it;
}
let data = [
[0, 0, [0]],
[-0, 0, [0]],
[1, 1, [1]],
[-1, -1, [255]],
[1.1, 1, [1]],
[-1.1, -1, [255]],
[1.9, 1, [1]],
QUnit.test('DataView', assert => {
assert.same(DataView, Object(DataView), 'is object');
let dataview = new DataView(new ArrayBuffer(8));
assert.same(dataview.byteOffset, 0, '#byteOffset, passed buffer');
assert.same(dataview.byteLength, 8, '#byteLength, passed buffer');
dataview = new DataView(new ArrayBuffer(16), 8);
assert.same(dataview.byteOffset, 8, '#byteOffset, passed buffer and byteOffset');
assert.same(dataview.byteLength, 8, '#byteLength, passed buffer and byteOffset');
dataview = new DataView(new ArrayBuffer(24), 8, 8);
assert.same(dataview.byteOffset, 8, '#byteOffset, passed buffer, byteOffset and length');
assert.same(dataview.byteLength, 8, '#byteLength, passed buffer, byteOffset and length');
assert.throws(() => new DataView(new ArrayBuffer(8), -1), 'If offset < 0, throw a RangeError exception');
assert.throws(() => new DataView(new ArrayBuffer(8), 16), 'If newByteLength < 0, throw a RangeError exception');
assert.throws(() => new DataView(new ArrayBuffer(24), 8, 24), 'If offset+newByteLength > bufferByteLength, throw a RangeError exception');
dataview = new DataView(new ArrayBuffer(8));
dataview.setUint32(0, 0x12345678);
assert.same(dataview.getUint32(0), 0x12345678, 'big endian/big endian');
dataview.setUint32(0, 0x12345678, true);
assert.same(dataview.getUint32(0, true), 0x12345678, 'little endian/little endian');
dataview.setUint32(0, 0x12345678, true);
assert.same(dataview.getUint32(0), 0x78563412, 'little endian/big endian');
dataview.setUint32(0, 0x12345678);
assert.same(dataview.getUint32(0, true), 0x78563412, 'big endian/little endian');
assert.throws(() => new DataView({}), 'non-ArrayBuffer argument, object');
assert.throws(() => new DataView('foo'), 'non-ArrayBuffer argument, string');
if (DESCRIPTORS) QUnit.test('Uint8 conversions', assert => {
const uint8array = new Uint8Array(1);
const dataview = new DataView(uint8array.buffer);
function viewFrom(it) {
return new DataView(new Uint8Array(it).buffer);
}
function toString(it) {
return it === 0 && 1 / it === -Infinity ? '-0' : it;
}
let data = [
[0, 0, [0]],
[-0, 0, [0]],
[1, 1, [1]],
[-1, 255, [255]],
[1.1, 1, [1]],
[-1.1, 255, [255]],
[1.9, 1, [1]],
if (DESCRIPTORS) QUnit.test('Uint16 conversions', assert => {
const uint16array = new Uint16Array(1);
const uint8array = new Uint8Array(uint16array.buffer);
const dataview = new DataView(uint16array.buffer);
function viewFrom(it) {
return new DataView(new Uint8Array(it).buffer);
}
function toString(it) {
return it === 0 && 1 / it === -Infinity ? '-0' : it;
}
let data = [
[0, 0, [0, 0]],
[-0, 0, [0, 0]],
[1, 1, [1, 0]],
[-1, 65535, [255, 255]],
[1.1, 1, [1, 0]],
[-1.1, 65535, [255, 255]],
[1.9, 1, [1, 0]],
assert.throws(() => new DataView(buffer, 8, 1), 'invalid byteOffset+length');
assert.throws(() => new DataView(buffer, 9, -1), 'invalid byteOffset+length');
assert.throws(() => new DataView(new ArrayBuffer(8), -1), 'If offset < 0, throw a RangeError exception');
assert.throws(() => new DataView(new ArrayBuffer(8), 16), 'If newByteLength < 0, throw a RangeError exception');