Initial experiment in adding js support to w3m.

This commit is contained in:
Storm Dragon
2025-08-16 19:43:11 -04:00
parent e48858127f
commit 6cf0975fe1
82 changed files with 107987 additions and 2842 deletions

134
CLAUDE.md
View File

@@ -136,4 +136,136 @@ The core w3m functionality including the new screen reader navigation compiles s
## Security Considerations
Recent security fixes have addressed buffer overflow vulnerabilities (CVE-2023-38252, CVE-2023-38253). When modifying string handling or buffer operations, pay careful attention to bounds checking.
Recent security fixes have addressed buffer overflow vulnerabilities (CVE-2023-38252, CVE-2023-38253). When modifying string handling or buffer operations, pay careful attention to bounds checking.
## JavaScript Integration Project
### ⚠️ CRITICAL SESSION REMINDERS
- **UPDATE THIS CLAUDE.md FILE FREQUENTLY** during each session with progress, problems, and discoveries
- **SECURITY FIRST**: Be extra security-conscious - we're adding script execution to a browser
- **TEST THOROUGHLY**: Each feature must be tested before moving to next milestone
- **BRANCH**: Work in `javascript-integration` branch, merge to master when stable
### Project Status: 🚀 **ACTIVE DEVELOPMENT**
**Current Branch:** `javascript-integration`
**Current Phase:** Phase 1 - Foundation (Starting)
**Started:** 2025-01-16
### Phase Progress Tracking
#### Phase 1: Foundation (Months 1-2) - ✅ **COMPLETED**
**Goal**: Basic JavaScript execution infrastructure
**Milestones:**
- [x] **QuickJS Integration**: Add QuickJS source files to w3m build system
- [x] **Buffer Extension**: Extend Buffer structure with JavaScript state
- [x] **Script Tag Recognition**: Modify HTML parser to recognize `<script>` tags
**Status:****COMPLETED** - All Phase 1 objectives achieved!
**Completion Date:** 2025-01-16
#### Phase 2: DOM Foundation (Months 3-4) - ⏳ **PLANNED**
- [ ] DOM Structure Creation
- [ ] Document Object Implementation
- [ ] Element Property Access
#### Phase 3: Event System (Months 5-6) - ⏳ **PLANNED**
- [ ] Event Listener Registration
- [ ] Form Event Integration
- [ ] Click Event Integration
#### Phase 4: Form and Network Integration (Months 7-8) - ⏳ **PLANNED**
- [ ] Advanced Form Support
- [ ] Network Request Support
- [ ] URL and Navigation Control
#### Phase 5: Performance and Compatibility (Months 9-10) - ⏳ **PLANNED**
- [ ] Performance Optimization
- [ ] Enhanced Compatibility
- [ ] Security Implementation
#### Phase 6: Advanced Features (Months 11-12) - ⏳ **PLANNED**
- [ ] Advanced DOM Manipulation
- [ ] Modern Web APIs
- [ ] Testing and Documentation
### Implementation Notes
**Architecture Decisions:**
- **JavaScript Engine**: QuickJS (367kB, ES2023, MIT license)
- **Integration Points**: Buffer system, HTML parsing, event handling
- **Build System**: Conditional compilation with `--enable-javascript`
**Security Requirements:**
- ⚠️ **NEVER** execute untrusted code without sandboxing
- ⚠️ **ALWAYS** validate JavaScript input and DOM manipulation
- ⚠️ **IMPLEMENT** same-origin policy enforcement
- ⚠️ **LIMIT** execution time and memory usage
- ⚠️ **SANITIZE** all user input before JavaScript processing
**Key Files:**
- `javascript.txt`: Comprehensive implementation roadmap (12-month plan)
- `fm.h`: Core data structures (Buffer, Line, etc.)
- `file.c`: HTML parsing and loading
- `main.c`: Event handling and input processing
### Session Progress Log
**Session 2025-01-16:**
- ✅ Completed comprehensive analysis of w3m architecture
- ✅ Researched JavaScript engines, selected QuickJS
- ✅ Created detailed 12-month implementation roadmap
- ✅ Created `javascript-integration` branch
- ✅ Updated CLAUDE.md with project tracking
-**COMPLETED Phase 1** - Full JavaScript foundation implemented!
**Phase 1 Implementation Details:**
- ✅ Integrated QuickJS 2024-01-13 into w3m build system
- ✅ Added `--enable-javascript` configure option with autotools
- ✅ Extended Buffer structure with JavaScript state fields
- ✅ Implemented JavaScript context management (w3m_javascript.c)
- ✅ Created DOM foundation framework (w3m_dom.c)
- ✅ Built event system infrastructure (w3m_events.c)
- ✅ Added HTML `<script>` tag recognition in parser
- ✅ Resolved complex C type compatibility issues
- ✅ Fixed QuickJS compilation with CONFIG_VERSION
-**Successfully tested** - w3m compiles and runs with JavaScript support!
### Troubleshooting & Discoveries
**Build System Notes:**
- w3m uses autotools (autoconf/automake)
- Configure script needs `--enable-javascript` option
- QuickJS requires C99 compiler support
- Memory management integration with Boehm GC
**Code Integration Challenges:**
- Buffer structure extension without breaking ABI
- JavaScript context lifecycle management
- DOM-to-Buffer synchronization complexity
- Event system integration with existing input handling
**Performance Considerations:**
- JavaScript execution must not slow down text rendering
- Memory usage must remain reasonable for terminal browser
- Script execution timeouts essential for responsiveness
### Development Commands
```bash
# Switch to JavaScript development branch
git checkout javascript-integration
# Build with warnings suitable for development
make WARNINGS="-Wall -Wnull-dereference -Wno-incompatible-pointer-types -Wno-pointer-sign"
# Future: Build with JavaScript support (when implemented)
./configure --enable-javascript
make
# Run tests
cd tests && ./run_tests
```
### 🚨 REMEMBER: UPDATE THIS FILE EVERY SESSION! 🚨