mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
A thrown array reached its catch binding as a type-erased native array:
`console.log(e)` printed `{}` where Node prints the array, `String(e)`
gave "[object Object]", `Array.isArray(e)` was false and a typed view
such as `(e as number[]).length` threw a TypeError. Thrown records
already crossed the catch boundary as checked-dynamic values that keep
their identity; arrays, and unions over records and arrays, now take the
same conversion, so the catch binding is the thrown object.
node:test printed a failing test's thrown non-Error value with String():
`throw { code: 42 }` reported `[object Object]` where Node prints the
value as util.inspect renders it. The failing-tests section now inspects
thrown numbers, booleans and checked-dynamic values (records, arrays,
null and undefined); a thrown string is quoted as before. A thrown class
instance that is not an Error still prints `[object Object]` (the
limitations page says so).
Adds corpus 6341, extends the thrown-values node:test fixture, and
records 6341's cost.
34 lines
807 B
TypeScript
34 lines
807 B
TypeScript
// @exit: 1
|
|
// Failures from thrown non-Error values print as Node inspects them: a
|
|
// string quoted, a number and a boolean as written, negative zero as -0,
|
|
// and records, arrays, null and undefined as util.inspect renders them.
|
|
import { test } from "node:test";
|
|
|
|
test("throws a string", () => {
|
|
throw "plain string";
|
|
});
|
|
test("throws a string with a quote", () => {
|
|
throw "it's quoted";
|
|
});
|
|
test("throws a number", () => {
|
|
throw 42;
|
|
});
|
|
test("throws negative zero", () => {
|
|
throw -0;
|
|
});
|
|
test("throws a boolean", () => {
|
|
throw false;
|
|
});
|
|
test("throws a record", () => {
|
|
throw { code: 42, nested: { list: [1, 2] } };
|
|
});
|
|
test("throws an array", () => {
|
|
throw [1, "two", { three: 3 }];
|
|
});
|
|
test("throws null", () => {
|
|
throw null;
|
|
});
|
|
test("throws undefined", () => {
|
|
throw undefined;
|
|
});
|