Skip to content

Error has JavaScript's name and toString() - #131

Merged
ASDAlexander77 merged 2 commits into
mainfrom
error-name-tostring
Nov 30, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
error-name-tostring

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Error and its subclasses get JavaScript's name and toString().

  • name is "Error", and each subclass sets its own: RangeError, TypeError, SyntaxError, ReferenceError, SuppressedError. It is a plain field, so a program's subclass may set it (this.name = "ValidationError").
  • toString() gives "Name: message", or the name alone when there is no message.
  • So an Error prints and turns into a string as in JavaScript (${e}, "" + e, print(e), console.log(e)). Before, this was refused because there was no toString, and a caught error held in any printed [object Object].

Layout

message stays the first field after the vtable, because the compiler's uncaught-exception report reads it there (UncaughtException.h). name is declared after the constructor's fields. Checked: throw new RangeError("boom") still reports uncaught exception: RangeError: boom, both under the JIT and from an exe.

Testing

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits November 30, 2026 20:48
- `name` ("Error", and each subclass its own: RangeError, TypeError, SyntaxError, ReferenceError,
  SuppressedError) is a field a subclass may set (`this.name = "ValidationError"`)
- `toString()` is "Name: message", or the name alone without a message
- so an Error prints, and is made a string, as in JavaScript (`${e}`, `"" + e`, print(e), console.log(e)); it
  was refused (no toString), and a caught one held in `any` printed "[object Object]"
- `message` stays the first field after the vtable, where the report of an uncaught exception reads it; `name`
  is declared after the constructor's fields

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h takes as a failure

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 4a97586 into main Nov 30, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant