Skip to content
4 changes: 4 additions & 0 deletions std/assembly/arraybuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ export class ArrayBuffer {
memory.copy(changetype<usize>(buffer) + HEADER_SIZE, changetype<usize>(this) + HEADER_SIZE + begin, newLen);
return buffer;
}

toString(): string {
return "[object ArrayBuffer]";
}
}
4 changes: 4 additions & 0 deletions std/assembly/dataview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ export class DataView {
HEADER_SIZE
);
}

toString(): string {
return "[object DataView]";
}
}

@inline function checkOffset(byteOffset: i32, n: i32, byteLength: i32): void {
Expand Down
9 changes: 4 additions & 5 deletions std/assembly/error.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
export class Error {

name: string = "Error";
message: string;
stack: string = ""; // TODO
stack: string | null = null; // TODO
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik this is never null in JS

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it could be undefined according to this

Or not?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually Error.prototype.stack is not standard but all browsers support it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial though was that if it's guaranteed to be a string, even if empty, one can simply print it without having to check explicitly, which is about what you'd do in JS because it's effectively always there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll revert this


constructor(message: string = "") {
this.message = message;
}
constructor(
public message: string = ""
) {}

toString(): string {
var message = this.message;
Expand Down
8 changes: 7 additions & 1 deletion std/assembly/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,15 +621,21 @@ declare class Error {
message: string;

/** Stack trace. */
stack: string;
stack: string | null;

/** Constructs a new error, optionally with a message. */
constructor(message?: string);

/** Method returns a string representing the specified Error class. */
toString(): string;
}

/** Class for indicating an error when a value is not in the set or range of allowed values. */
declare class RangeError extends Error { }

/** Class for indicating an error when a value is not of the expected type. */
declare class TypeError extends Error { }

interface Boolean {}
interface Function {}
interface IArguments {}
Expand Down
40 changes: 24 additions & 16 deletions std/portable/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ declare class ArrayBuffer {
constructor(length: i32);
/** Returns a copy of this array buffer's bytes from begin, inclusive, up to end, exclusive. */
slice(begin?: i32, end?: i32): ArrayBuffer;
/** Returns a string representation of ArrayBuffer. */
toString(): string;
}

/** 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. */
Expand All @@ -310,37 +312,39 @@ 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?: 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
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
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?: 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
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
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?: 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
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
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
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
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?: 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
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
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?: 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
setUint32(byteOffset: i32, value: u32, littleEndian?: boolean): void;
/** Returns a string representation of DataView. */
toString(): string;
}

declare class Array<T> {
Expand Down Expand Up @@ -439,8 +443,12 @@ declare class Error {
constructor(message: string);
message: string;
stack: string | null;
toString(): string;
}

declare class RangeError extends Error { }
declare class TypeError extends Error { }

declare class Set<T> {
constructor(entries?: T[]);
readonly size: i32;
Expand Down
30 changes: 15 additions & 15 deletions tests/compiler/std/dataview.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -553,7 +553,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -602,7 +602,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -639,7 +639,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -696,7 +696,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -739,7 +739,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -785,7 +785,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -822,7 +822,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -863,7 +863,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -909,7 +909,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -945,7 +945,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand All @@ -966,7 +966,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -1007,7 +1007,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -1048,7 +1048,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down Expand Up @@ -1080,7 +1080,7 @@
if
i32.const 0
i32.const 136
i32.const 184
i32.const 188
i32.const 73
call $~lib/env/abort
unreachable
Expand Down
Loading