Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions returned by Function.prototype.bind() have non-configurable lengths #4122

Closed
jackhorton opened this issue Nov 2, 2017 · 7 comments

Comments

@jackhorton
Copy link
Contributor

Example:

Object.getOwnPropertyDescriptor(function (a, b) { return 0; }, "length").configurable // true
Object.getOwnPropertyDescriptor(function (a, b) { return 0; }.bind({}), "length").configurable // false

This is blocking tests 10.3.2_1_a_L15.js, 12.3.2_1_a_L15, 11.3.2_1_a_L15, 10.2.2_L15.js, 12.2.2_L15.js, and 11.2.2_L15.js in test262/test/intl402

/cc @bterlson

@jackhorton
Copy link
Contributor Author

There's a whole lot of special casing in BoundFunction.cpp for not allowing things to happen to the length property (its hard-coded to be non-configurable, non-enumerable, non-writable, and non-delete-able).

@dilijev dilijev removed the Intl-ICU label Nov 6, 2017
@dilijev
Copy link
Contributor

dilijev commented Nov 6, 2017

Removing Intl-ICU tag since this applies to non-ICU Intl as well.

@dilijev dilijev added the Intl label Nov 6, 2017
@bterlson
Copy link
Contributor

bterlson commented Nov 7, 2017

Possibly related: #3606.

@akroshg
Copy link
Contributor

akroshg commented Nov 7, 2017

well #3606 didn't address the boundfunction scenario. But it can easily be done by returning true in the IsConfigurable function.

@jackhorton
Copy link
Contributor Author

Removing that if block definitely resolves the test262 failures, but I didn't test how that impacted actually trying to configure it. There's enough special casing about the length property in BoundFunction.cpp that I would imagine it would still fail in relatively interesting ways.

@akroshg
Copy link
Contributor

akroshg commented Nov 7, 2017

even though the length is marked as configurable, we actually don't honor it's configurability.

        function foo() { }
        delete foo.length;
        print(foo.hasOwnProperty("length"));

this should yield false, but it prints true

@rhuanjl
Copy link
Collaborator

rhuanjl commented Jun 30, 2018

Taking a look at this, there seem to be several related problems:

Issue Normal Function Bound Function
Length should be configurable passes fails
Deleting length should succeed fails fails
Deleting length should not throw fails (in strict mode) fails (in strict mode)
value after deletion = 0 fails fails
using defineProperty to redefine length fails fails

These errors appear to relate to the mechanism for handling length:

  • script functions do not have a length property
  • instead traps for length are used within hasProperty, getProperty, delete property etc. to provide the correct answers
  • the traps don't handle deletion or redefinition
  • bizarrely the trap in the delete method has a throwIfStrict mode

I'll look at fixing this by making length into a normal property and getting rid of the trap(s).

chakrabot pushed a commit that referenced this issue Aug 20, 2018
…ndFunction.length

Merge pull request #5405 from rhuanjl:boundFunction

Fix: #4122

This PR addresses several issues with the length property of JavascriptFunctions and BoundFunctions.

Length should be configurable (previously worked for JavascriptFunctions but not BoundFunctions)
Deleting length should succeed (previously failed for both)
Deleting length should not throw in strict mode (previously failed for both)
value after deletion = 0 (previously failed for both)
using defineProperty to redefine length should work (previously failed silently for both)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants