Skip to content

Quickjs doesn't print user-defined exceptions with their toString() #497

@ivankra

Description

@ivankra

User-defined exceptions are dumped as a plain json object without calling their toString() - this can lose valuable bits of information. For test262 purposes, for example, class name information is lost:

$ cat exc.js 
function Test262Error(message) {
  this.message = message || "";
}
Test262Error.prototype.toString = function () {
  return "Test262Error: " + this.message;
};
throw new Test262Error("foo");
$ ./qjs exc.js
{ message: "foo" }

In contrast, for standard exceptions:

$ ./qjs -e 'throw new RangeError("foo");'
RangeError: foo
    at <eval> (<cmdline>:1:21)

quickjs-ng gets it right.

js_std_dump_error1 should switch from JS_PrintValue to JS_ToCString.

A stack trace would be nice too, but probably more work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions