we (web engine): Experimental web browser project to understand the limits of Claude

JS Built-in: Math, Date, JSON #270

Open pierrelf.com
targeting main
Open opened by and assigned to pierrelf.com
targeting main

Implements issue 3mhn3nq2cgc2g

Changes #

Adds Math, Date, and JSON built-in objects for the JavaScript engine.

Math #

  • Not a constructor (static methods only)
  • Constants: E, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2
  • 29 methods: abs, ceil, floor, round, trunc, max, min, pow, sqrt, cbrt, hypot, sin, cos, tan, asin, acos, atan, atan2, exp, log, log2, log10, expm1, log1p, sign, clz32, fround, random, imul

Date #

  • Constructor: Date(), Date(ms), Date(string), Date(year, month, ...)
  • Static methods: Date.now(), Date.parse(), Date.UTC()
  • Getters/setters for all calendar components (UTC-based)
  • Formatting: toString, toISOString, toUTCString, toLocaleDateString, toJSON
  • Internal calendar ↔ timestamp conversion using civil calendar algorithm

JSON #

  • JSON.parse(text): full JSON tokenizer and recursive descent parser with unicode escape support
  • JSON.stringify(value, replacer?, space?): recursive serialization with pretty-print, circular reference detection, Date toJSON support

VM Changes #

  • Added date_prototype field to Vm for Date constructor prototype chain
  • Added RuntimeError::syntax_error constructor
  • Made js_number_to_string pub(crate) for JSON.stringify

Tests #

  • 41 new tests covering all built-in categories
  • All 369 JS tests pass (328 existing + 41 new)

This pull request has no versions submitted yet.