Skip to content

Function.prototype.call/.apply on builtin prototype methods returns undefined ([].slice.call(arguments)) — generalize #1722 #1777

Description

@proggeramlug

Summary

Function.prototype.call/.apply on a builtin prototype method returns undefined — the method isn't a first-class function value. This is the general case of #1722 (which fixed it only for stdlib namespace methods like path.join).

Repro (confirmed, perry 0.5.1028)

function viaProto() { return Array.prototype.slice.call(arguments, 1); }
console.log(typeof Array.prototype.slice);          // Perry: "undefined"   Node: "function"
console.log(Array.prototype.slice.call([9,8,7], 1)); // Perry: TypeError (reading 'call')   Node: [8,7]
[].slice.call(arguments);                            // same: "Cannot read properties of undefined (reading 'call')"

Array.prototype.slice (and array-instance .slice as a value, not a direct call) evaluate to undefined, so .call/.apply on them throws.

Why it matters

[].slice.call(arguments) / Array.prototype.slice.call(arguments) is one of the most common idioms in real-world JS (arguments-to-array, polyfills, every older library). In the #800 node-core radar it's the single largest concentrated runtime-fail cluster — ~117 tests (fs-heavy), because the test harness's mustSucceed/mustCall use it. Likely affects Array.prototype.map/forEach/..., Object.prototype.hasOwnProperty.call, etc. too.

Scope

Extend #1722's fix from stdlib-namespace methods to builtin prototype methods (Array/Object/String/Function prototypes): make Proto.method and instance.method resolve to a real callable so .call/.apply (and passing the method as a callback) dispatch to the native implementation.

Context: discovered clustering the full #800 radar sweep (1300 judged tests).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed defect or regressionparityCompatibility gap with Node.js, ECMAScript, or the supported ecosystem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions