-
Couldn't load subscription status.
- Fork 23
Fix Date.toLocaleString() crash with JavaScript polyfill #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…aleString) - Added align-data dependency to embed ICU data file - Copied ICU data file (icudtl.dat) from V8 crate to core/third_party/icu/ - Initialize ICU data before V8 initialization in init() function - Set default locale to en_US - Increased heap limits to 1GB to support ICU operations - Added tests for Date.now() and Date.toString() - Added ignored test for Date.toLocaleString() documenting current limitation Note: toLocaleString() still has issues with V8 140.2.0 ICU implementation. The smaller ICU data file (flutter_desktop) causes crashes, while the larger one (chromecast_video) causes hangs. This appears to be a V8 crate limitation that needs further investigation or an upstream fix. Co-authored-by: MylesBorins <[email protected]>
Co-authored-by: MylesBorins <[email protected]>
|
@copilot is there another icu library we can use to improve coverage? |
…ethods Instead of relying on V8's broken ICU implementation, provide a working JavaScript polyfill that completely replaces the native Date locale methods. Changes: - Created date_locale.js polyfill with implementations of: - Date.prototype.toLocaleString() - Format: MM/DD/YYYY, HH:MM:SS AM/PM - Date.prototype.toLocaleDateString() - Format: MM/DD/YYYY - Date.prototype.toLocaleTimeString() - Format: HH:MM:SS AM/PM - Load polyfill during builtins initialization (after all other builtins) - Updated ICU data to larger chromecast_video version (6.3MB) for better future compatibility, though currently bypassed by polyfill - Updated tests: removed #[ignore] from date_to_locale_string test - Added two new tests: date_to_locale_date_string and date_to_locale_time_string - All tests now pass The polyfill provides basic but working locale formatting without relying on V8's ICU implementation which has issues with the available ICU data files. Co-authored-by: MylesBorins <[email protected]>
Instead of using a different ICU library, I've implemented a JavaScript polyfill that completely replaces the broken native The polyfill now provides working implementations of:
All tests pass and Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot can we add a TODO to make sure we replace this in the future if the V8 method is fixed |
Added TODO comments in both the JavaScript polyfill and the Rust code that loads it, documenting that this polyfill should be removed once V8's native ICU implementation works correctly with proper ICU data. The TODOs remind future maintainers to: - Test if toLocaleString() works without the polyfill in future V8 versions - Remove the polyfill when the native implementation is fixed - Track V8 updates for ICU improvements Co-authored-by: MylesBorins <[email protected]>
Added TODO comments in both the JavaScript polyfill ( |
Fix
new Date().toLocaleString()crash with JavaScript polyfillalign-datadependency to core/Cargo.tomlinit()function before V8 initializationSolution
After extensive investigation, I found that V8 140.2.0's ICU implementation has fundamental issues:
The solution: Implement a JavaScript polyfill that completely replaces the native Date locale methods:
Date.prototype.toLocaleString()- Returns format:MM/DD/YYYY, HH:MM:SS AM/PMDate.prototype.toLocaleDateString()- Returns format:MM/DD/YYYYDate.prototype.toLocaleTimeString()- Returns format:HH:MM:SS AM/PMThe polyfill is loaded during builtins initialization and provides working implementations without relying on V8's ICU layer.
Future work: TODO comments have been added to track when this polyfill can be removed once V8's native ICU implementation is fixed.
What Now Works
✅
Date.toLocaleString()- Returns formatted date/time string✅
Date.toLocaleDateString()- Returns formatted date string✅
Date.toLocaleTimeString()- Returns formatted time string✅ All other Date methods continue to work as before
✅ All tests pass (5 Date-related tests, 65 total in test_builtins)
Testing
All tests pass including comprehensive tests for the locale methods.
Original prompt
Fixes #362
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.