Skip to content

Function.prototype.bind does not preserve the target's prototype #1732

Description

@d01c2

Reproduction

Object.prototype.toString.call((function* () {}).constructor("aa").bind());

Expected

[object GeneratorFunction]. A bound function inherits from whatever its target inherits from.

V8 (15.6.20):

d8> Object.prototype.toString.call((function* () {}).constructor("aa").bind());
"[object GeneratorFunction]"

Actual (QuickJS-ng)

Every bound function gets Function.prototype, whatever the target was.

qjs > Object.prototype.toString.call((function* () {}).constructor("aa").bind());
'[object Function]'

Spec

Function.prototype.bind delegates to BoundFunctionCreate, whose first step reads the target's own prototype and installs it as the bound function's [[Prototype]]. Nothing in either operation mentions Function.prototype.

Here the target is a generator function, so the bound function should inherit from %GeneratorFunction.prototype% and carry its Symbol.toStringTag. The same holds for any target whose prototype is not Function.prototype.

Versions

  • QuickJS-ng: 0.17.0
  • V8: 15.6.20

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions