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

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

open opened by pierrelf.com

Implement the Math, Date, and JSON built-in objects.

Scope#

Math#

  • Not a constructor (static methods only)
  • Constants: E, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2
  • 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 (basic PRNG — no crypto requirement)
  • imul

Date#

  • Date() constructor: no args (now), milliseconds, date string, year/month/day/...
  • Date.now(), Date.parse(string), Date.UTC(...)
  • Getters: getFullYear, getMonth, getDate, getDay, getHours, getMinutes, getSeconds, getMilliseconds, getTime, getTimezoneOffset
  • UTC getters: getUTCFullYear, etc.
  • Setters: setFullYear, setMonth, setDate, setHours, etc.
  • toString, toISOString, toUTCString, toLocaleDateString, toJSON
  • valueOf returns milliseconds since epoch
  • Internal: convert between timestamp and calendar components

JSON#

  • JSON.parse(text, reviver?) — parse JSON string to JS value
    • Support all JSON types: object, array, string, number, boolean, null
    • Optional reviver function
    • Throw SyntaxError on invalid JSON
  • JSON.stringify(value, replacer?, space?)
    • Handle all primitive types
    • Handle objects and arrays recursively
    • toJSON() method support
    • Optional replacer (function or array)
    • Optional space for pretty printing
    • Circular reference detection (throw TypeError)

Acceptance Criteria#

  • Math methods return correct values (test against known results)
  • Date construction from various inputs
  • Date getters/setters work correctly
  • Date.now() returns reasonable timestamp
  • JSON.parse handles all valid JSON
  • JSON.parse throws on invalid JSON
  • JSON.stringify handles nested objects/arrays
  • JSON.stringify detects circular references
  • Unit tests for each built-in

Phase 10 — JavaScript Engine (issue 10 of 15). Depends on: JS primitive built-ins (String/Number/Boolean/Symbol).

sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mhn3nq2cgc2g