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,hypotsin,cos,tan,asin,acos,atan,atan2exp,log,log2,log10,expm1,log1psign,clz32,froundrandom(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,toJSONvalueOfreturns 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).