Skip to content

switch to bool in DataView #1647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions std/assembly/dataview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class DataView {
this.byteLength = byteLength;
}

getFloat32(byteOffset: i32, littleEndian: boolean = false): f32 {
getFloat32(byteOffset: i32, littleEndian: bool = false): f32 {
if (
(byteOffset >>> 31) | i32(byteOffset + 4 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
Expand All @@ -38,7 +38,7 @@ export class DataView {
: reinterpret<f32>(bswap<u32>(load<u32>(this.dataStart + <usize>byteOffset)));
}

getFloat64(byteOffset: i32, littleEndian: boolean = false): f64 {
getFloat64(byteOffset: i32, littleEndian: bool = false): f64 {
if (
(byteOffset >>> 31) | i32(byteOffset + 8 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
Expand All @@ -52,15 +52,15 @@ export class DataView {
return load<i8>(this.dataStart + <usize>byteOffset);
}

getInt16(byteOffset: i32, littleEndian: boolean = false): i16 {
getInt16(byteOffset: i32, littleEndian: bool = false): i16 {
if (
(byteOffset >>> 31) | i32(byteOffset + 2 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
var result: i16 = load<i16>(this.dataStart + <usize>byteOffset);
return littleEndian ? result : bswap<i16>(result);
}

getInt32(byteOffset: i32, littleEndian: boolean = false): i32 {
getInt32(byteOffset: i32, littleEndian: bool = false): i32 {
if (
(byteOffset >>> 31) | i32(byteOffset + 4 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
Expand All @@ -73,31 +73,31 @@ export class DataView {
return load<u8>(this.dataStart + <usize>byteOffset);
}

getUint16(byteOffset: i32, littleEndian: boolean = false): u16 {
getUint16(byteOffset: i32, littleEndian: bool = false): u16 {
if (
(byteOffset >>> 31) | i32(byteOffset + 2 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
var result: u16 = load<u16>(this.dataStart + <usize>byteOffset);
return littleEndian ? result : bswap<u16>(result);
}

getUint32(byteOffset: i32, littleEndian: boolean = false): u32 {
getUint32(byteOffset: i32, littleEndian: bool = false): u32 {
if (
(byteOffset >>> 31) | i32(byteOffset + 4 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
var result: u32 = load<u32>(this.dataStart + <usize>byteOffset);
return littleEndian ? result : bswap<u32>(result);
}

setFloat32(byteOffset: i32, value: f32, littleEndian: boolean = false): void {
setFloat32(byteOffset: i32, value: f32, littleEndian: bool = false): void {
if (
(byteOffset >>> 31) | i32(byteOffset + 4 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
if (littleEndian) store<f32>(this.dataStart + <usize>byteOffset, value);
else store<u32>(this.dataStart + <usize>byteOffset, bswap<u32>(reinterpret<u32>(value)));
}

setFloat64(byteOffset: i32, value: f64, littleEndian: boolean = false): void {
setFloat64(byteOffset: i32, value: f64, littleEndian: bool = false): void {
if (
(byteOffset >>> 31) | i32(byteOffset + 8 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
Expand All @@ -110,14 +110,14 @@ export class DataView {
store<i8>(this.dataStart + <usize>byteOffset, value);
}

setInt16(byteOffset: i32, value: i16, littleEndian: boolean = false): void {
setInt16(byteOffset: i32, value: i16, littleEndian: bool = false): void {
if (
(byteOffset >>> 31) | i32(byteOffset + 2 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
store<i16>(this.dataStart + <usize>byteOffset, littleEndian ? value : bswap<i16>(value));
}

setInt32(byteOffset: i32, value: i32, littleEndian: boolean = false): void {
setInt32(byteOffset: i32, value: i32, littleEndian: bool = false): void {
if (
(byteOffset >>> 31) | i32(byteOffset + 4 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
Expand All @@ -129,14 +129,14 @@ export class DataView {
store<u8>(this.dataStart + <usize>byteOffset, value);
}

setUint16(byteOffset: i32, value: u16, littleEndian: boolean = false): void {
setUint16(byteOffset: i32, value: u16, littleEndian: bool = false): void {
if (
(byteOffset >>> 31) | i32(byteOffset + 2 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
store<u16>(this.dataStart + <usize>byteOffset, littleEndian ? value : bswap<u16>(value));
}

setUint32(byteOffset: i32, value: u32, littleEndian: boolean = false): void {
setUint32(byteOffset: i32, value: u32, littleEndian: bool = false): void {
if (
(byteOffset >>> 31) | i32(byteOffset + 4 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
Expand All @@ -145,30 +145,30 @@ export class DataView {

// Non-standard additions that make sense in WebAssembly, but won't work in JS:

getInt64(byteOffset: i32, littleEndian: boolean = false): i64 {
getInt64(byteOffset: i32, littleEndian: bool = false): i64 {
if (
(byteOffset >>> 31) | i32(byteOffset + 8 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
var result: i64 = load<i64>(this.dataStart + <usize>byteOffset);
return littleEndian ? result : bswap<i64>(result);
}

getUint64(byteOffset: i32, littleEndian: boolean = false): u64 {
getUint64(byteOffset: i32, littleEndian: bool = false): u64 {
if (
(byteOffset >>> 31) | i32(byteOffset + 8 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
var result = load<u64>(this.dataStart + <usize>byteOffset);
return littleEndian ? result : bswap<u64>(result);
}

setInt64(byteOffset: i32, value: i64, littleEndian: boolean = false): void {
setInt64(byteOffset: i32, value: i64, littleEndian: bool = false): void {
if (
(byteOffset >>> 31) | i32(byteOffset + 8 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
store<i64>(this.dataStart + <usize>byteOffset, littleEndian ? value : bswap<i64>(value));
}

setUint64(byteOffset: i32, value: u64, littleEndian: boolean = false): void {
setUint64(byteOffset: i32, value: u64, littleEndian: bool = false): void {
if (
(byteOffset >>> 31) | i32(byteOffset + 8 > this.byteLength)
) throw new RangeError(E_INDEXOUTOFRANGE);
Expand Down
32 changes: 16 additions & 16 deletions std/assembly/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1387,45 +1387,45 @@ declare class DataView {
/** 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;
getFloat32(byteOffset: i32, littleEndian?: bool): 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;
getFloat64(byteOffset: i32, littleEndian?: bool): 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;
getInt16(byteOffset: i32, littleEndian?: bool): 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;
getInt32(byteOffset: i32, littleEndian?: bool): 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;
getInt64(byteOffset: i32, littleEndian?: bool): 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;
getUint16(byteOffset: i32, littleEndian?: bool): 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;
getUint32(byteOffset: i32, littleEndian?: bool): 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;
getUint64(byteOffset: i32, littleEndian?: bool): 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;
setFloat32(byteOffset: i32, value: f32, littleEndian?: bool): 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;
setFloat64(byteOffset: i32, value: f64, littleEndian?: bool): 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;
setInt16(byteOffset: i32, value: i16, littleEndian?: bool): 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;
setInt32(byteOffset: i32, value: i32, littleEndian?: bool): 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;
setInt64(byteOffset: i32, value: i64, littleEndian?: bool): 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;
setUint16(byteOffset: i32, value: u16, littleEndian?: bool): 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;
setUint32(byteOffset: i32, value: u32, littleEndian?: bool): 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;
setUint64(byteOffset: i32, value: u64, littleEndian?: bool): void;
/** Returns a string representation of DataView. */
toString(): string;
}
Expand Down