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

Possible missing tests for legacy function properties #4340

Open
gibson042 opened this issue Dec 11, 2024 · 4 comments
Open

Possible missing tests for legacy function properties #4340

gibson042 opened this issue Dec 11, 2024 · 4 comments

Comments

@gibson042
Copy link
Contributor

ECMA-262 specifies presence of "caller" and "arguments" properties on Function.prototype that each use the single realm-global %ThrowTypeError% as both getter and setter, and does not specify such properties on function instances (where their absence is arguably expected). But, as observed at endojs/endo#2655 (comment) , implementations diverge.

  • JSC and SM follow spec by defining them only on Function.prototype (but violate it by having distinct values for the 4 respective getter/setter functions).
  • V8 violates the spec by additionally defining them on Function() and non-strict function(){…} instances (non-writable and non-configurable null-valued data properties).
  • XS violates the spec by additionally defining caller [although correctly omitting arguments] on Function() and non-strict function(){…} instances (writable and configurable undefined-valued data properties).
  • Hermes violates the spec by omitting them from Function.prototype, and additionally by defining them on strict function(){…} instances (non-configurable accessor properties with %ThrowTypeError% getter/setter functions).


And Hermes has an additional bug: in a module context, function(){} is treated differently from function(){ "use strict"; } (cf. Strict Mode Code, "Module code is always strict mode code") for both these function properties and for arguments.callee.

@jdorfman
Copy link

Hey @gibson042, this is a little out of my comfort zone, but I wanted to give it a shot since the help wanted label was on.

I'm not going to create a PR until you give me a 👍

Code: main...jdorfman:test262:jd/issue-4340

Results:

test262-harness test/built-ins/Function/prototype/caller-arguments/*.js
FAIL test/built-ins/Function/prototype/caller-arguments/strict-vs-nonstrict.js (default)
  non-strict function should not have own caller property

FAIL test/built-ins/Function/prototype/caller-arguments/cross-realm-behavior.js (default)
  Expected no error, got TypeError: otherRealm.evaluate is not a function

FAIL test/built-ins/Function/prototype/caller-arguments/cross-realm-behavior.js (strict mode)
  Expected no error, got TypeError: otherRealm.evaluate is not a function

FAIL test/built-ins/Function/prototype/caller-arguments/module-context.js (default)
  normal function should not have caller

Ran 7 tests
3 passed
4 failed

Feel free to close without explanation, I won't take it personally ;)

@gibson042
Copy link
Contributor Author

@jdorfman that's a great start, you should open that PR so it can be formally reviewed.

@jdorfman
Copy link

Thanks @gibson042 done

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

4 participants