mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-02 07:43:42 +08:00
A write completion callback that a JavaScript module returned reaches the stream lowering as an untyped value. Since the error-argument form of write callbacks, the lowering refused it with SC2020, so tests/corpus/8532-stream-saved-callback-receiver failed to compile. Such a callback is now converted to a function of the error argument. The stream calls it unbound with null after a successful write or with the write's error, and ignores what it returns, as Node does.
12 lines
447 B
JavaScript
12 lines
447 B
JavaScript
// A write completion callback built in JavaScript: it records how it was
|
|
// called. Module code is strict, so an unbound call sees `this` undefined.
|
|
export function makeReporter(lines, label) {
|
|
return function (...args) {
|
|
const error = args[0];
|
|
lines.push(
|
|
`${label} args=${args.length} error=${error === null ? "null" : error === undefined ? "undefined" : error.message} this=${typeof this}`,
|
|
);
|
|
return "ignored";
|
|
};
|
|
}
|