mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 07:02:13 +00:00
Add DataView to standard library (#316)
This commit is contained in:
parent
6f3209e6c6
commit
3f9758f35a
129
std/assembly/dataview.ts
Normal file
129
std/assembly/dataview.ts
Normal file
@ -0,0 +1,129 @@
|
||||
import { HEADER_SIZE } from "./internal/arraybuffer";
|
||||
|
||||
export class DataView {
|
||||
constructor(
|
||||
readonly buffer: ArrayBuffer,
|
||||
readonly byteOffset: i32 = 0,
|
||||
readonly byteLength: i32 = i32.MIN_VALUE,
|
||||
) {
|
||||
if (byteLength === i32.MIN_VALUE) byteLength = buffer.byteLength - byteOffset;
|
||||
|
||||
if (byteOffset < 0) throw new RangeError("byteOffset cannot be negative");
|
||||
if (byteLength < 0) throw new RangeError("byteLength cannot be negative");
|
||||
if (byteOffset + byteLength > buffer.byteLength) throw new RangeError("Length out of range of buffer");
|
||||
}
|
||||
|
||||
@inline
|
||||
getFloat32(byteOffset: i32, littleEndian: boolean = false): f32 {
|
||||
var result: u32 = load<u32>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, HEADER_SIZE);
|
||||
return reinterpret<f32>(littleEndian ? result : bswap<u32>(result));
|
||||
}
|
||||
|
||||
@inline
|
||||
getFloat64(byteOffset: i32, littleEndian: boolean = false): f64 {
|
||||
var result: u64 = load<u64>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, HEADER_SIZE);
|
||||
return reinterpret<f64>(littleEndian ? result : bswap<u64>(result));
|
||||
}
|
||||
|
||||
@inline
|
||||
getInt8(byteOffset: i32): i8 {
|
||||
return load<i8>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, HEADER_SIZE);
|
||||
}
|
||||
|
||||
@inline
|
||||
getInt16(byteOffset: i32, littleEndian: boolean = false): i16 {
|
||||
var result: i16 = load<i16>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, HEADER_SIZE);
|
||||
return littleEndian ? result : bswap<i16>(result);
|
||||
}
|
||||
|
||||
@inline
|
||||
getInt32(byteOffset: i32, littleEndian: boolean = false): i32 {
|
||||
var result: i32 = load<i32>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, HEADER_SIZE);
|
||||
return littleEndian ? result : bswap<i32>(result);
|
||||
}
|
||||
|
||||
@inline
|
||||
getUint8(byteOffset: i32): u8 {
|
||||
return load<u8>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, HEADER_SIZE);
|
||||
}
|
||||
|
||||
@inline
|
||||
getUint16(byteOffset: i32, littleEndian: boolean = false): u16 {
|
||||
var result: u16 = load<u16>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, HEADER_SIZE);
|
||||
return littleEndian ? result : bswap<u16>(result);
|
||||
}
|
||||
|
||||
@inline
|
||||
getUint32(byteOffset: i32, littleEndian: boolean = false): u32 {
|
||||
var result: u32 = load<u32>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, HEADER_SIZE);
|
||||
return littleEndian ? result : bswap<u32>(result);
|
||||
}
|
||||
|
||||
@inline
|
||||
setFloat32(byteOffset: i32, value: f32, littleEndian: boolean = false): void {
|
||||
var input: f32 = littleEndian ? value : reinterpret<f32>(bswap<u32>(reinterpret<u32>(value)));
|
||||
store<f32>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, input, HEADER_SIZE);
|
||||
}
|
||||
|
||||
@inline
|
||||
setFloat64(byteOffset: i32, value: f64, littleEndian: boolean = false): void {
|
||||
var input: f64 = littleEndian ? value : reinterpret<f64>(bswap<u64>(reinterpret<u64>(value)));
|
||||
store<f64>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, input, HEADER_SIZE);
|
||||
}
|
||||
|
||||
@inline
|
||||
setInt8(byteOffset: i32, value: i8): void {
|
||||
store<i8>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, value, HEADER_SIZE);
|
||||
}
|
||||
|
||||
@inline
|
||||
setInt16(byteOffset: i32, value: i16, littleEndian: boolean = false): void {
|
||||
store<i16>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, littleEndian ? value : bswap<i16>(value), HEADER_SIZE);
|
||||
}
|
||||
|
||||
@inline
|
||||
setInt32(byteOffset: i32, value: i32, littleEndian: boolean = false): void {
|
||||
store<i32>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, littleEndian ? value : bswap<i32>(value), HEADER_SIZE);
|
||||
}
|
||||
|
||||
@inline
|
||||
setUint8(byteOffset: i32, value: u8): void {
|
||||
store<u8>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, value, HEADER_SIZE);
|
||||
}
|
||||
|
||||
@inline
|
||||
setUint16(byteOffset: i32, value: u16, littleEndian: boolean = false): void {
|
||||
store<u16>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, littleEndian ? value : bswap<u16>(value), HEADER_SIZE);
|
||||
}
|
||||
|
||||
@inline
|
||||
setUint32(byteOffset: i32, value: u32, littleEndian: boolean = false): void {
|
||||
store<u32>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, littleEndian ? value : bswap<u32>(value), HEADER_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Non-standard additions that makes sense in WebAssembly, but won't work in JS
|
||||
*/
|
||||
|
||||
@inline
|
||||
getInt64(byteOffset: i32, littleEndian: boolean = false): i64 {
|
||||
var result: i64 = load<i64>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, HEADER_SIZE);
|
||||
return littleEndian ? result : bswap<i64>(result);
|
||||
}
|
||||
|
||||
@inline
|
||||
getUint64(byteOffset: i32, littleEndian: boolean = false): u64 {
|
||||
var result: u64 = load<u64>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, HEADER_SIZE);
|
||||
return littleEndian ? result : bswap<u64>(result);
|
||||
}
|
||||
|
||||
@inline
|
||||
setInt64(byteOffset: i32, value: i64, littleEndian: boolean = false): void {
|
||||
store<i64>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, littleEndian ? value : bswap<i64>(value), HEADER_SIZE);
|
||||
}
|
||||
|
||||
@inline
|
||||
setUint64(byteOffset: i32, value: u64, littleEndian: boolean = false): void {
|
||||
store<u64>(changetype<usize>(this.buffer) + this.byteOffset + byteOffset, littleEndian ? value : bswap<u64>(value), HEADER_SIZE);
|
||||
}
|
||||
}
|
52
std/assembly/index.d.ts
vendored
52
std/assembly/index.d.ts
vendored
@ -380,6 +380,58 @@ declare class ArrayBuffer {
|
||||
slice(begin?: i32, end?: i32): ArrayBuffer;
|
||||
}
|
||||
|
||||
/** The `DataView` view provides a low-level interface for reading and writing multiple number types in a binary `ArrayBuffer`, without having to care about the platform's endianness. */
|
||||
declare class DataView {
|
||||
/** The `buffer` accessor property represents the `ArrayBuffer` or `SharedArrayBuffer` referenced by the `DataView` at construction time. */
|
||||
readonly buffer: ArrayBuffer;
|
||||
/** The `byteLength` accessor property represents the length (in bytes) of this view from the start of its `ArrayBuffer` or `SharedArrayBuffer`. */
|
||||
readonly byteLength: i32;
|
||||
/** The `byteOffset` accessor property represents the offset (in bytes) of this view from the start of its `ArrayBuffer` or `SharedArrayBuffer`. */
|
||||
readonly byteOffset: i32;
|
||||
/** Constructs a new `DataView` with the given properties */
|
||||
constructor(buffer: ArrayBuffer, byteOffset?: i32, byteLength?: i32);
|
||||
/** The `getFloat32()` method gets a signed 32-bit float (float) at the specified byte offset from the start of the `DataView`. */
|
||||
getFloat32(byteOffset: i32, littleEndian?: boolean): f32
|
||||
/** The `getFloat64()` method gets a signed 64-bit float (double) at the specified byte offset from the start of the `DataView`. */
|
||||
getFloat64(byteOffset: i32, littleEndian?: boolean): f64
|
||||
/** The `getInt8()` method gets a signed 8-bit integer (byte) at the specified byte offset from the start of the `DataView`. */
|
||||
getInt8(byteOffset: i32): i8
|
||||
/** The `getInt16()` method gets a signed 16-bit integer (short) at the specified byte offset from the start of the `DataView`. */
|
||||
getInt16(byteOffset: i32, littleEndian?: boolean): i16
|
||||
/** The `getInt32()` method gets a signed 32-bit integer (long) at the specified byte offset from the start of the `DataView`. */
|
||||
getInt32(byteOffset: i32, littleEndian?: boolean): i32
|
||||
/** The `getInt64()` method gets a signed 64-bit integer (long long) at the specified byte offset from the start of the `DataView`. */
|
||||
getInt64(byteOffset: i32, littleEndian?: boolean): i64
|
||||
/** The `getUint8()` method gets an unsigned 8-bit integer (unsigned byte) at the specified byte offset from the start of the `DataView`. */
|
||||
getUint8(byteOffset: i32): u8
|
||||
/** The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified byte offset from the start of the `DataView`. */
|
||||
getUint16(byteOffset: i32, littleEndian?: boolean): u16
|
||||
/** The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified byte offset from the start of the `DataView`. */
|
||||
getUint32(byteOffset: i32, littleEndian?: boolean): u32
|
||||
/** The `getUint64()` method gets an unsigned 64-bit integer (unsigned long long) at the specified byte offset from the start of the `DataView`. */
|
||||
getUint64(byteOffset: i32, littleEndian?: boolean): u64
|
||||
/** The `setFloat32()` method stores a signed 32-bit float (float) value at the specified byte offset from the start of the `DataView`. */
|
||||
setFloat32(byteOffset: i32, value: f32, littleEndian?: boolean): void
|
||||
/** The `setFloat64()` method stores a signed 64-bit float (double) value at the specified byte offset from the start of the `DataView`. */
|
||||
setFloat64(byteOffset: i32, value: f64, littleEndian?: boolean): void
|
||||
/** The `setInt8()` method stores a signed 8-bit integer (byte) value at the specified byte offset from the start of the `DataView`. */
|
||||
setInt8(byteOffset: i32, value: i8): void
|
||||
/** The `setInt16()` method stores a signed 16-bit integer (short) value at the specified byte offset from the start of the `DataView`. */
|
||||
setInt16(byteOffset: i32, value: i16, littleEndian?: boolean): void
|
||||
/** The `setInt32()` method stores a signed 32-bit integer (long) value at the specified byte offset from the start of the `DataView`. */
|
||||
setInt32(byteOffset: i32, value: i32, littleEndian?: boolean): void
|
||||
/** The `setInt64()` method stores a signed 64-bit integer (long long) value at the specified byte offset from the start of the `DataView`. */
|
||||
setInt64(byteOffset: i32, value: i64, littleEndian?: boolean): void
|
||||
/** The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the specified byte offset from the start of the `DataView`. */
|
||||
setUint8(byteOffset: i32, value: u8): void
|
||||
/** The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the specified byte offset from the start of the `DataView`. */
|
||||
setUint16(byteOffset: i32, value: u16, littleEndian?: boolean): void
|
||||
/** The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the specified byte offset from the start of the `DataView`. */
|
||||
setUint32(byteOffset: i32, value: u32, littleEndian?: boolean): void
|
||||
/** The `setUint64()` method stores an unsigned 64-bit integer (unsigned long long) value at the specified byte offset from the start of the `DataView`. */
|
||||
setUint64(byteOffset: i32, value: u64, littleEndian?: boolean): void
|
||||
}
|
||||
|
||||
/** Interface for a typed view on an array buffer. */
|
||||
interface ArrayBufferView<T> {
|
||||
[key: number]: T;
|
||||
|
44
std/portable/index.d.ts
vendored
44
std/portable/index.d.ts
vendored
@ -243,6 +243,50 @@ declare class ArrayBuffer {
|
||||
slice(begin?: i32, end?: i32): ArrayBuffer;
|
||||
}
|
||||
|
||||
/** The `DataView` view provides a low-level interface for reading and writing multiple number types in a binary `ArrayBuffer`, without having to care about the platform's endianness. */
|
||||
declare class DataView {
|
||||
/** The `buffer` accessor property represents the `ArrayBuffer` or `SharedArrayBuffer` referenced by the `DataView` at construction time. */
|
||||
readonly buffer: ArrayBuffer;
|
||||
/** The `byteLength` accessor property represents the length (in bytes) of this view from the start of its `ArrayBuffer` or `SharedArrayBuffer`. */
|
||||
readonly byteLength: i32;
|
||||
/** The `byteOffset` accessor property represents the offset (in bytes) of this view from the start of its `ArrayBuffer` or `SharedArrayBuffer`. */
|
||||
readonly byteOffset: i32;
|
||||
/** Constructs a new `DataView` with the given properties */
|
||||
constructor(buffer: ArrayBuffer, byteOffset?: i32, byteLength?: i32);
|
||||
/** The `getFloat32()` method gets a signed 32-bit float (float) at the specified byte offset from the start of the `DataView`. */
|
||||
getFloat32(byteOffset: i32, littleEndian?: boolean): f32
|
||||
/** The `getFloat64()` method gets a signed 64-bit float (double) at the specified byte offset from the start of the `DataView`. */
|
||||
getFloat64(byteOffset: i32, littleEndian?: boolean): f64
|
||||
/** The `getInt8()` method gets a signed 8-bit integer (byte) at the specified byte offset from the start of the `DataView`. */
|
||||
getInt8(byteOffset: i32): i8
|
||||
/** The `getInt16()` method gets a signed 16-bit integer (short) at the specified byte offset from the start of the `DataView`. */
|
||||
getInt16(byteOffset: i32, littleEndian?: boolean): i16
|
||||
/** The `getInt32()` method gets a signed 32-bit integer (long) at the specified byte offset from the start of the `DataView`. */
|
||||
getInt32(byteOffset: i32, littleEndian?: boolean): i32
|
||||
/** The `getUint8()` method gets an unsigned 8-bit integer (unsigned byte) at the specified byte offset from the start of the `DataView`. */
|
||||
getUint8(byteOffset: i32): u8
|
||||
/** The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified byte offset from the start of the `DataView`. */
|
||||
getUint16(byteOffset: i32, littleEndian?: boolean): u16
|
||||
/** The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified byte offset from the start of the `DataView`. */
|
||||
getUint32(byteOffset: i32, littleEndian?: boolean): u32
|
||||
/** The `setFloat32()` method stores a signed 32-bit float (float) value at the specified byte offset from the start of the `DataView`. */
|
||||
setFloat32(byteOffset: i32, value: f32, littleEndian?: boolean): void
|
||||
/** The `setFloat64()` method stores a signed 64-bit float (double) value at the specified byte offset from the start of the `DataView`. */
|
||||
setFloat64(byteOffset: i32, value: f64, littleEndian?: boolean): void
|
||||
/** The `setInt8()` method stores a signed 8-bit integer (byte) value at the specified byte offset from the start of the `DataView`. */
|
||||
setInt8(byteOffset: i32, value: i8): void
|
||||
/** The `setInt16()` method stores a signed 16-bit integer (short) value at the specified byte offset from the start of the `DataView`. */
|
||||
setInt16(byteOffset: i32, value: i16, littleEndian?: boolean): void
|
||||
/** The `setInt32()` method stores a signed 32-bit integer (long) value at the specified byte offset from the start of the `DataView`. */
|
||||
setInt32(byteOffset: i32, value: i32, littleEndian?: boolean): void
|
||||
/** The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the specified byte offset from the start of the `DataView`. */
|
||||
setUint8(byteOffset: i32, value: u8): void
|
||||
/** The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the specified byte offset from the start of the `DataView`. */
|
||||
setUint16(byteOffset: i32, value: u16, littleEndian?: boolean): void
|
||||
/** The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the specified byte offset from the start of the `DataView`. */
|
||||
setUint32(byteOffset: i32, value: u32, littleEndian?: boolean): void
|
||||
}
|
||||
|
||||
declare class Array<T> {
|
||||
[key: number]: T;
|
||||
length: i32;
|
||||
|
163
tests/compiler/std/dataview.ts
Normal file
163
tests/compiler/std/dataview.ts
Normal file
@ -0,0 +1,163 @@
|
||||
import "allocator/arena";
|
||||
|
||||
var array = new Uint8Array(8);
|
||||
|
||||
array[0] = 246;
|
||||
array[1] = 224;
|
||||
array[2] = 88;
|
||||
array[3] = 159;
|
||||
array[4] = 130;
|
||||
array[5] = 101;
|
||||
array[6] = 67;
|
||||
array[7] = 95;
|
||||
|
||||
var view = new DataView(array.buffer, array.byteOffset, array.byteLength);
|
||||
|
||||
assert(view.getFloat32(0, true) === -4.592586247781397e-20);
|
||||
assert(view.getFloat32(1, true) === -2.3413961970849473e-37);
|
||||
assert(view.getFloat32(2, true) === 7.710587701863113e+22);
|
||||
assert(view.getFloat32(3, true) === 229.51023864746094);
|
||||
assert(view.getFloat32(4, true) === 14079802746555335000.0);
|
||||
|
||||
assert(view.getFloat32(0, false) === -2.2751405188178955e+33);
|
||||
assert(view.getFloat32(1, false) === -62437351080004160000.0);
|
||||
assert(view.getFloat32(2, false) === 1403059112509440.0);
|
||||
assert(view.getFloat32(3, false) === -5.522466503261712e-20);
|
||||
assert(view.getFloat32(4, false) === -1.6843597451835358e-37);
|
||||
|
||||
assert(view.getFloat64(0, true) === 7.936550095674706e+150);
|
||||
assert(view.getFloat64(0, false) === -4.1177747581885255e+264);
|
||||
|
||||
assert(view.getInt8(0) === -10);
|
||||
assert(view.getInt8(1) === -32);
|
||||
assert(view.getInt8(2) === 88);
|
||||
assert(view.getInt8(3) === -97);
|
||||
assert(view.getInt8(4) === -126);
|
||||
assert(view.getInt8(5) === 101);
|
||||
assert(view.getInt8(6) === 67);
|
||||
assert(view.getInt8(7) === 95);
|
||||
|
||||
assert(view.getInt16(0, true) === -7946);
|
||||
assert(view.getInt16(1, true) === 22752);
|
||||
assert(view.getInt16(2, true) === -24744);
|
||||
assert(view.getInt16(3, true) === -32097);
|
||||
assert(view.getInt16(4, true) === 25986);
|
||||
assert(view.getInt16(5, true) === 17253);
|
||||
assert(view.getInt16(6, true) === 24387);
|
||||
|
||||
assert(view.getInt16(0, false) === -2336);
|
||||
assert(view.getInt16(1, false) === -8104);
|
||||
assert(view.getInt16(2, false) === 22687);
|
||||
assert(view.getInt16(3, false) === -24702);
|
||||
assert(view.getInt16(4, false) === -32155);
|
||||
assert(view.getInt16(5, false) === 25923);
|
||||
assert(view.getInt16(6, false) === 17247);
|
||||
|
||||
assert(view.getInt32(0, true) === -1621565194);
|
||||
assert(view.getInt32(1, true) === -2103486240);
|
||||
assert(view.getInt32(2, true) === 1703059288);
|
||||
assert(view.getInt32(3, true) === 1130726047);
|
||||
assert(view.getInt32(4, true) === 1598252418);
|
||||
|
||||
assert(view.getInt32(0, false) === -153069409);
|
||||
assert(view.getInt32(1, false) === -531062910);
|
||||
assert(view.getInt32(2, false) === 1486848613);
|
||||
assert(view.getInt32(3, false) === -1618844349);
|
||||
assert(view.getInt32(4, false) === -2107292833);
|
||||
|
||||
assert(view.getInt64(0, true) === 6864441868736323830)
|
||||
assert(view.getInt64(0, false) === -657428103485373601)
|
||||
|
||||
assert(view.getUint8(0) === 246);
|
||||
assert(view.getUint8(1) === 224);
|
||||
assert(view.getUint8(2) === 88);
|
||||
assert(view.getUint8(3) === 159);
|
||||
assert(view.getUint8(4) === 130);
|
||||
assert(view.getUint8(5) === 101);
|
||||
assert(view.getUint8(6) === 67);
|
||||
assert(view.getUint8(7) === 95);
|
||||
|
||||
assert(view.getUint16(0, true) === 57590);
|
||||
assert(view.getUint16(1, true) === 22752);
|
||||
assert(view.getUint16(2, true) === 40792);
|
||||
assert(view.getUint16(3, true) === 33439);
|
||||
assert(view.getUint16(4, true) === 25986);
|
||||
assert(view.getUint16(5, true) === 17253);
|
||||
assert(view.getUint16(6, true) === 24387);
|
||||
|
||||
assert(view.getUint16(0, false) === 63200);
|
||||
assert(view.getUint16(1, false) === 57432);
|
||||
assert(view.getUint16(2, false) === 22687);
|
||||
assert(view.getUint16(3, false) === 40834);
|
||||
assert(view.getUint16(4, false) === 33381);
|
||||
assert(view.getUint16(5, false) === 25923);
|
||||
assert(view.getUint16(6, false) === 17247);
|
||||
|
||||
assert(view.getUint32(0, true) === 2673402102);
|
||||
assert(view.getUint32(1, true) === 2191481056);
|
||||
assert(view.getUint32(2, true) === 1703059288);
|
||||
assert(view.getUint32(3, true) === 1130726047);
|
||||
assert(view.getUint32(4, true) === 1598252418);
|
||||
|
||||
assert(view.getUint32(0, false) === 4141897887);
|
||||
assert(view.getUint32(1, false) === 3763904386);
|
||||
assert(view.getUint32(2, false) === 1486848613);
|
||||
assert(view.getUint32(3, false) === 2676122947);
|
||||
assert(view.getUint32(4, false) === 2187674463);
|
||||
|
||||
assert(view.getUint64(0, true) === 6864441868736323830)
|
||||
assert(view.getUint64(0, false) === 17789315970224178015)
|
||||
|
||||
view.setFloat32(0, 1.5976661625240943e-18, true)
|
||||
assert(view.getFloat32(0, true) === 1.5976661625240943e-18)
|
||||
|
||||
view.setFloat32(0, 1.9762819733816963e+21, false)
|
||||
assert(view.getFloat32(0, false) === 1.9762819733816963e+21)
|
||||
|
||||
view.setFloat64(0, -1.094252199637739e+148, true)
|
||||
assert(view.getFloat64(0, true) === -1.094252199637739e+148)
|
||||
|
||||
view.setFloat64(0, 6.022586634778589e-103, false)
|
||||
assert(view.getFloat64(0, false) === 6.022586634778589e-103)
|
||||
|
||||
view.setInt8(0, 108)
|
||||
assert(view.getInt8(0) === 108)
|
||||
|
||||
view.setInt16(0, -13360, true)
|
||||
assert(view.getInt16(0, true) === -13360)
|
||||
|
||||
view.setInt16(0, 14689, false)
|
||||
assert(view.getInt16(0, false) === 14689)
|
||||
|
||||
view.setInt32(0, 1204680201, true)
|
||||
assert(view.getInt32(0, true) === 1204680201)
|
||||
|
||||
view.setInt32(0, 660673230, false)
|
||||
assert(view.getInt32(0, false) === 660673230)
|
||||
|
||||
view.setInt64(0, -3290739641816099749, true)
|
||||
assert(view.getInt64(0, true) === -3290739641816099749)
|
||||
|
||||
view.setInt64(0, 8178932412950708047, false)
|
||||
assert(view.getInt64(0, false) === 8178932412950708047)
|
||||
|
||||
view.setUint8(0, 238)
|
||||
assert(view.getUint8(0) === 238)
|
||||
|
||||
view.setUint16(0, 58856, true)
|
||||
assert(view.getUint16(0, true) === 58856)
|
||||
|
||||
view.setUint16(0, 60400, false)
|
||||
assert(view.getUint16(0, false) === 60400)
|
||||
|
||||
view.setUint32(0, 3448161552, true)
|
||||
assert(view.getUint32(0, true) === 3448161552)
|
||||
|
||||
view.setUint32(0, 2784175665, false)
|
||||
assert(view.getUint32(0, false) === 2784175665)
|
||||
|
||||
view.setUint64(0, 2334704782995986958, true)
|
||||
assert(view.getUint64(0, true) === 2334704782995986958)
|
||||
|
||||
view.setUint64(0, 11323557176419695287, false)
|
||||
assert(view.getUint64(0, false) === 11323557176419695287)
|
4654
tests/compiler/std/dataview.untouched.wat
Normal file
4654
tests/compiler/std/dataview.untouched.wat
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user