Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 22, 2025

This PR implements process.stdout, process.stdin, and process.stderr for jstime, providing Node.js-compatible stream interfaces for standard I/O operations.

Features

process.stdout and process.stderr

Implemented as writable stream-like objects with the following capabilities:

  • write(chunk, encoding, callback) - Write strings or Uint8Arrays to stdout/stderr
  • end(chunk, encoding, callback) - Close stream after optional final write
  • isTTY - Property indicating if stream is connected to a TTY (currently returns false)
  • Automatic flushing for immediate output
  • Full UTF-8 encoding support
  • Binary data support via Uint8Array

process.stdin

Implemented as a readable stream-like object with:

  • read() - Read all available data from stdin
  • isTTY - Property indicating if stream is connected to a TTY

Example Usage

// Basic string output
process.stdout.write('Hello, World!\n');
process.stderr.write('Error message\n');

// Binary data with Uint8Array
const encoder = new TextEncoder();
const data = encoder.encode('你好世界\n');
process.stdout.write(data);

// With callbacks
process.stdout.write('Processing... ', (err) => {
  if (!err) process.stdout.write('Done!\n');
});

// Check TTY status
console.log(process.stdout.isTTY); // false

Implementation Details

Rust Layer (core/src/builtins/node/process_impl.rs)

  • Added write_stdout(), write_stderr(), and read_stdin() functions
  • Proper error handling with V8 exception throwing
  • Handles both string and Uint8Array inputs
  • Automatic output flushing for immediate visibility

JavaScript Layer (core/src/builtins/node/process.js)

  • Created ProcessWritableStream class for stdout/stderr
  • Created ProcessReadableStream class for stdin
  • Node.js-compatible API with write(), end(), and stream methods
  • Lazy initialization for better performance

Testing

Added 8 new tests covering:

  • Stream existence and type checking
  • String writing to stdout/stderr
  • Write return values
  • isTTY property access
  • All 18 process tests passing

Documentation

Updated docs/apis/system.md to mark process.stdin/stdout/stderr as implemented with basic stream functionality.

Compatibility

While this implementation provides the core functionality needed for most use cases, it doesn't include the full Node.js Stream API features like event emitters, piping, or backpressure handling. For basic I/O operations (writing output, reading input), the implementation is fully compatible with Node.js patterns.

Closes #[issue_number]

Original prompt

can you implement process.stdout and process.stdin


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Implement process.stdout and process.stdin Implement process.stdout, process.stdin, and process.stderr Oct 22, 2025
Copilot AI requested a review from MylesBorins October 22, 2025 17:28
Copilot finished work on behalf of MylesBorins October 22, 2025 17:28
@MylesBorins MylesBorins marked this pull request as ready for review October 22, 2025 18:49
@MylesBorins MylesBorins merged commit a8eae6b into main Oct 22, 2025
6 checks passed
@MylesBorins MylesBorins deleted the copilot/implement-stdout-and-stdin branch October 22, 2025 18:50
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.

2 participants