feat(m4-12): P1 deferred — ToObject + setPrototypeOf + Function.prototype (P2 Tier 6)#64
feat(m4-12): P1 deferred — ToObject + setPrototypeOf + Function.prototype (P2 Tier 6)#64
Conversation
…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>
There was a problem hiding this comment.
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_objectand use it to coerce arguments inObject.keys/values/entries/getOwnProperty*andthisinObject.prototype.hasOwnProperty/valueOf. - Update
Object.setPrototypeOfto useRequireObjectCoercible(throw onnull/undefined, no-op for other primitives). - Register
Function.prototypeas a callable native function (returnsundefined) 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.
…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>
There was a problem hiding this comment.
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_objectand use it forObject.keys/values/entries/getPrototypeOf/getOwnPropertyDescriptor/getOwnPropertyNames. - Update
Object.setPrototypeOfto applyRequireObjectCoercible(null/undefined throw; other primitives no-op return). - Make
Function.prototypea callableNativeFunctionthat returnsundefined, 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.
…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>
…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>
There was a problem hiding this comment.
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
ToObjecthelper that boxes primitives into wrapper objects (includingSymbol), and use it in keyObject.*/Object.prototype.*built-ins. - Update
Object.getPrototypeOf/Object.keys|values|entries|getOwnProperty*to applyToObject, andObject.setPrototypeOfto applyRequireObjectCoercible. - Make
Function.prototypea callable native function that returnsundefined, 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.
Summary
coerce.rs— primitive → wrapper objectthis(primitivethisworks)Tests: 1445 → 1453 (+8 new)
Test plan
cargo test -p elidex-js— 1453 tests passcargo clippy -p elidex-js -- -D warnings— cleancargo fmt --all— cleanKnown limitations
collect_own_keys_es_orderdoesn't enumerate StringWrapper index properties yetFunctionglobal not registered (accessible via prototype chain)🤖 Generated with Claude Code