Skip to content

feat(m4-12): P1 deferred — ToObject + setPrototypeOf + Function.prototype (P2 Tier 6)#64

Merged
send merged 7 commits intomainfrom
feat/m4-12-p2-deferred
Apr 11, 2026
Merged

feat(m4-12): P1 deferred — ToObject + setPrototypeOf + Function.prototype (P2 Tier 6)#64
send merged 7 commits intomainfrom
feat/m4-12-p2-deferred

Conversation

@send
Copy link
Copy Markdown
Owner

@send send commented Apr 11, 2026

Summary

  • ToObject coercion helper in coerce.rs — primitive → wrapper object
  • Object.keys/values/entries/getPrototypeOf: ToObject on argument (primitives wrapped)
  • hasOwnProperty/valueOf: ToObject on this (primitive this works)
  • Object.setPrototypeOf: RequireObjectCoercible (null/undefined → TypeError)
  • Function.prototype: callable NativeFunction (returns undefined per §19.2.3)

Tests: 1445 → 1453 (+8 new)

Test plan

  • cargo test -p elidex-js — 1453 tests pass
  • cargo clippy -p elidex-js -- -D warnings — clean
  • cargo fmt --all — clean
  • CI full pass

Known limitations

  • StringWrapper Object.keys enumeration: collect_own_keys_es_order doesn't enumerate StringWrapper index properties yet
  • Function global not registered (accessible via prototype chain)

🤖 Generated with Claude Code

…ion.prototype callable

P2 Tier 6:
- ToObject helper in coerce.rs (primitive → wrapper object)
- Object.keys/values/entries/getPrototypeOf: call ToObject on arg
  (primitives are wrapped instead of returning empty)
- hasOwnProperty/valueOf: call ToObject on this (primitive this works)
- setPrototypeOf: RequireObjectCoercible (null/undefined → TypeError)
- Function.prototype: NativeFunction that returns undefined (callable)

1445→1453 tests (+8 new).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 11, 2026 05:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements several ES2020 Object/Function compliance fixes in the VM: introducing a shared ToObject coercion helper, applying it to selected Object.*/Object.prototype.* built-ins, and making Function.prototype callable per spec.

Changes:

  • Add coerce::to_object and use it to coerce arguments in Object.keys/values/entries/getOwnProperty* and this in Object.prototype.hasOwnProperty/valueOf.
  • Update Object.setPrototypeOf to use RequireObjectCoercible (throw on null/undefined, no-op for other primitives).
  • Register Function.prototype as a callable native function (returns undefined) and add regression tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
crates/script/elidex-js/src/vm/coerce.rs Adds a VM-level ToObject helper that allocates wrapper objects for primitives.
crates/script/elidex-js/src/vm/natives_object.rs Switches several Object.* and Object.prototype.* methods to use ToObject; tightens setPrototypeOf coercion rules.
crates/script/elidex-js/src/vm/globals.rs Changes Function.prototype registration to be callable (native noop function).
crates/script/elidex-js/src/vm/tests/tests_object_complement.rs Adds tests covering Object.keys null/undefined handling, setPrototypeOf coercion, and callable Function.prototype.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

send and others added 2 commits April 11, 2026 14:49
…oval

- bind_this_global: delegate primitive wrapping to coerce::to_object
  (removes ~30 lines of duplicated alloc_object logic)
- to_object: add BigInt wrapping (BigIntWrapper exists, was erroneously
  throwing TypeError)
- to_object_arg: return ObjectId directly, remove unreachable else-branches
  from 5 callers in natives_object.rs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Object.getPrototypeOf(42) now returns Number.prototype instead of null.
Updated test from P1 known-limitation assertion to correct behavior.
hasOwnProperty on StringWrapper index/length remains a known limitation
(StringWrapper keys enumeration deferred).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 11, 2026 05:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR advances ES2020 compliance for Object/Function built-ins by introducing a centralized ToObject coercion helper and applying it to several Object static/prototype methods, plus making Function.prototype callable as required by the spec.

Changes:

  • Add coerce::to_object and use it for Object.keys/values/entries/getPrototypeOf/getOwnPropertyDescriptor/getOwnPropertyNames.
  • Update Object.setPrototypeOf to apply RequireObjectCoercible (null/undefined throw; other primitives no-op return).
  • Make Function.prototype a callable NativeFunction that returns undefined, and add corresponding tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/script/elidex-js/src/vm/coerce.rs Adds ToObject helper for boxing primitives into wrapper objects.
crates/script/elidex-js/src/vm/natives_object.rs Switches multiple Object built-ins to use ToObject; adjusts setPrototypeOf, hasOwnProperty, valueOf.
crates/script/elidex-js/src/vm/interpreter.rs Refactors global this binding to reuse ToObject for primitive boxing.
crates/script/elidex-js/src/vm/globals.rs Makes Function.prototype callable via a native no-op function.
crates/script/elidex-js/src/vm/tests/tests_object_complement.rs Adds/updates tests covering new ToObject behavior, setPrototypeOf coercion, and callable Function.prototype.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

send and others added 2 commits April 11, 2026 15:00
…alues)

Same-pattern audit: getOwnPropertySymbols was using raw arg access
instead of to_object_arg. Now consistent with keys/values/entries/
getOwnPropertyDescriptor/getOwnPropertyNames.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add ObjectKind::SymbolWrapper(SymbolId). to_object/bind_this_global
now wrap Symbol primitives. ToPrimitive unwraps back to Symbol.
GC handles the new variant.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 11, 2026 06:10
send and others added 2 commits April 11, 2026 15:14
…throws URIError

Rewrite percent_encode/percent_decode to process UTF-16 code units
directly instead of going through lossy get_utf8. Lone surrogates
(high without following low, or unpaired low) now correctly throw
URIError per ES2020 §18.2.6.1. Valid surrogate pairs are encoded
as 4-byte UTF-8 (%F0%XX%XX%XX). Multi-byte percent-decode collects
continuation bytes for proper UTF-8 reconstruction.

1453→1456 tests (+3: lone surrogate throw, surrogate pair encode, multibyte decode).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…nProperty

- collect_own_keys_es_order: emit StringWrapper index keys ("0".."n-1")
  as own enumerable properties. Object.keys('ab') → ["0", "1"].
- hasOwnProperty: check StringWrapper index range + "length" as virtual
  own properties (in addition to storage.has).
- Signature change: collect_own_keys_es_order takes &mut VmInner
  (needed to intern index key strings).

1456→1460 tests (+4: keys enumeration, hasOwnProperty index/length/miss).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements ES2020-compliant object coercion and prototype behavior in the elidex-js VM, addressing previously deferred spec gaps around ToObject/RequireObjectCoercible and making Function.prototype callable.

Changes:

  • Add a VM-level ToObject helper that boxes primitives into wrapper objects (including Symbol), and use it in key Object.* / Object.prototype.* built-ins.
  • Update Object.getPrototypeOf / Object.keys|values|entries|getOwnProperty* to apply ToObject, and Object.setPrototypeOf to apply RequireObjectCoercible.
  • Make Function.prototype a callable native function that returns undefined, matching ES2020 §19.2.3.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/script/elidex-js/src/vm/coerce.rs Introduces to_object abstract op implementation for boxing primitives into wrapper objects.
crates/script/elidex-js/src/vm/value.rs Adds ObjectKind::SymbolWrapper to represent boxed Symbol primitives.
crates/script/elidex-js/src/vm/ops.rs Extends ToPrimitive unboxing to handle SymbolWrapper.
crates/script/elidex-js/src/vm/natives_object.rs Switches various Object.* and Object.prototype.* built-ins to ToObject/RequireObjectCoercible semantics.
crates/script/elidex-js/src/vm/interpreter.rs Uses to_object for global (non-strict) this binding primitive boxing.
crates/script/elidex-js/src/vm/globals.rs Registers Function.prototype as a callable NativeFunction returning undefined.
crates/script/elidex-js/src/vm/gc.rs Updates GC tracing match arms to include SymbolWrapper.
crates/script/elidex-js/src/vm/tests/tests_object_complement.rs Adds/updates tests covering primitive boxing, setPrototypeOf coercibility, and callable Function.prototype.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@send send merged commit bc79a2b into main Apr 11, 2026
9 checks passed
@send send deleted the feat/m4-12-p2-deferred branch April 11, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants