fix(runtime): built-ins/Function test262 parity (instanceof Function, fn.constructor, Function.prototype length/name)#4761
Merged
Merged
Conversation
…, fn.constructor, Function.prototype length/name
Root causes fixed (built-ins/Function 285→300, parity 62.4%→65.6%, 0 regressions):
1. `value instanceof Function` always returned false — no callable was ever
recognized as an instance of Function (function declarations, expressions,
arrows, methods, bound functions, native handles, built-in constructors).
Added a reserved class id (CLASS_ID_FUNCTION = 0xFFFF00F0) emitted by the
`instanceof` operator (perry-codegen) and resolved in the runtime
(`js_instanceof` / `js_instanceof_dynamic`) via a new `value_is_callable`
predicate instead of a prototype-chain walk. This is a cross-cutting
language fix (also recovers cases under language/expressions/instanceof,
built-ins/AsyncFunction, Promise, Array).
2. `fn.constructor` returned undefined for ordinary functions. Now resolves to
the global `Function` (generator / async-generator functions keep their own
intrinsic constructors).
3. `Function.prototype` was missing its own `length` (0) and `name` ("") data
properties. Installed both with the spec attributes
`{ writable: false, enumerable: false, configurable: true }`, ordered so
`length` precedes `name` in getOwnPropertyNames (built-in property order).
Files:
- crates/perry-codegen/src/expr/instance_misc1.rs
- crates/perry-runtime/src/object/instanceof.rs
- crates/perry-runtime/src/object/field_get_set.rs
- crates/perry-runtime/src/object/global_this.rs
Regression check: built-ins+language shard 0/12 — 1601→1607 pass, the single
diff (MapIteratorPrototype/next/length) reproduces identically on both builds
(flaky contention timeout, not a real regression).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Drives built-ins/Function test262 parity from 285→300 (+15), 62.4%→65.6%, with zero regressions.
The headline fix is cross-cutting:
value instanceof Functionwas returningfalsefor every callable. That single gap blocked a large swath of the Function suite (which constructs functions and then assertsf instanceof Function) and also showed up underlanguage/expressions/instanceof,built-ins/AsyncFunction,Promise, andArray.Root causes fixed
x instanceof Functionalways false. No callable representation was recognized — function declarations, expressions, arrows, methods, bound functions, native handles, and built-in constructors all returnedfalse.CLASS_ID_FUNCTION = 0xFFFF00F0emitted by theinstanceofoperator (perry-codegen) and resolved in the runtime (js_instanceof/js_instanceof_dynamic) through a newvalue_is_callablepredicate (callability test, not a prototype-chain walk).fn.constructorreturnedundefinedfor ordinary functions. Now resolves to the globalFunction. Generator / async-generator functions keep their existing intrinsic constructors.Function.prototypelacked its ownlength(0) andname("") data properties. Installed both with spec attributes{ writable: false, enumerable: false, configurable: true }, ordered solengthprecedesnameingetOwnPropertyNames(built-in property order). Fixesprototype/length.js,prototype/name.js,prototype/property-order.js.Before → after
Files
crates/perry-codegen/src/expr/instance_misc1.rscrates/perry-runtime/src/object/instanceof.rscrates/perry-runtime/src/object/field_get_set.rscrates/perry-runtime/src/object/global_this.rsZero-regression note
Ran the
built-ins+languageshard0/12on this branch vs anorigin/mainbaseline built from the same corpus: 1601→1607 pass. The only set-difference failure (built-ins/MapIteratorPrototype/next/length.js) reproduces identically on both builds when run in isolation (flaky contention timeout in the parallel runner, not a behavior change). FIXED set on the broad shard includeslanguage/expressions/instanceof/S11.8.6_A7_T3.js,built-ins/AsyncFunction/AsyncFunction.js,built-ins/Promise/prototype/then/..., andbuilt-ins/Array/prototype/reduce/....Out of scope (follow-ups)
Remaining Function failures cluster around larger work: runtime
ToString-coercing dynamicFunction(objArg, …)construction, always-strict-modethis(sloppy-modethis→global tests), classtoStringsource reconstruction + class accessor descriptor reflection, and CJS top-levelthisharness artifacts.