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

JS Built-in: Map and Set collections #101

open opened by pierrelf.com

Implement the Map and Set collection built-ins.

Scope#

Map#

  • Map() constructor (optionally from iterable of [key, value] pairs)
  • Map.prototype.set(key, value) — returns the Map (for chaining)
  • Map.prototype.get(key) — returns value or undefined
  • Map.prototype.has(key) — returns boolean
  • Map.prototype.delete(key) — returns boolean
  • Map.prototype.clear()
  • Map.prototype.size (getter)
  • Map.prototype.forEach(callback, thisArg?)
  • Map.prototype.keys(), values(), entries() — return iterators
  • Map.prototype[Symbol.iterator]() — same as entries()
  • Key equality: SameValueZero (like === but NaN === NaN)
  • Keys can be any value type (objects, primitives)
  • Insertion order preserved

WeakMap (basic)#

  • WeakMap() constructor
  • get, set, has, delete
  • Keys must be objects (not primitives)
  • Entries are weakly held (GC can collect if no other references)

Set#

  • Set() constructor (optionally from iterable)
  • Set.prototype.add(value) — returns the Set
  • Set.prototype.has(value) — returns boolean
  • Set.prototype.delete(value) — returns boolean
  • Set.prototype.clear()
  • Set.prototype.size (getter)
  • Set.prototype.forEach(callback, thisArg?)
  • Set.prototype.keys(), values(), entries() — return iterators
  • Set.prototype[Symbol.iterator]() — same as values()
  • Value equality: SameValueZero
  • Insertion order preserved

WeakSet (basic)#

  • WeakSet() constructor
  • add, has, delete
  • Values must be objects

Acceptance Criteria#

  • Map stores and retrieves key-value pairs correctly
  • Map preserves insertion order
  • Map handles object keys and NaN key equality
  • Set stores unique values correctly
  • Set preserves insertion order
  • WeakMap/WeakSet accept only object keys/values
  • Iterators (keys, values, entries) work correctly
  • forEach works with proper this binding
  • Unit tests for all methods and edge cases

Phase 10 — JavaScript Engine (issue 12 of 15). Depends on: JS core built-ins.

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/3mhn3okf7ld2e