mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +08:00
- Preserve callable properties, descriptors, and shared module bindings across native JavaScript code. - Add stored process streams with input control, output callbacks, and write interception. - Preserve Error identity and classification through native rethrows and promise rejection.
19 lines
663 B
JavaScript
19 lines
663 B
JavaScript
const output = process.stdout;
|
|
const original = output.write;
|
|
const messages = [];
|
|
output.write = function(chunk, encoding, callback) {
|
|
messages.push(`${this === output}:${typeof chunk}:${String(chunk).trim()}`);
|
|
return false;
|
|
};
|
|
const result = output.write('direct');
|
|
console.log('console', -0, true);
|
|
output.write = original;
|
|
console.log(result, messages.join('|'));
|
|
output.write = function() { throw new Error('write failed'); };
|
|
console.log('swallowed');
|
|
try { output.write('throws'); } catch (error) { messages.push(error.message); }
|
|
output.write = original;
|
|
console.log(messages[messages.length - 1]);
|
|
output.write('6869\n', 'hex');
|
|
output.write('\n');
|