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

Support ES2015 function name behavior #1297

Open
p-bakker opened this issue Jan 29, 2023 · 1 comment · Fixed by #1398
Open

Support ES2015 function name behavior #1297

p-bakker opened this issue Jan 29, 2023 · 1 comment · Fixed by #1398
Labels
Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec
Milestone

Comments

@p-bakker
Copy link
Collaborator

p-bakker commented Jan 29, 2023

ES2015 standardized the behavior of the function.name property. Rhino doesn't comply.

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name, https://2ality.com/2015/09/function-names-es6.html for explanations of expected behavior. See https://tc39.es/ecma262/#sec-setfunctionname and everywhere in the spec where the abstract function operation setFunctionName is used to see the how and when

Debugger implementations would benefit from this, as they would be able to display more meaningful names on each entry in the callstack

Known issues:

  • var x = function(){}; x.name // doesn't yield 'x'
  • let f; f = () => {}; f.name // doesn't yield 'f'
  • ({x: function test(){}}).x.name // doesn't yield 'x'
  • ({foo(){}}).foo.name // doesn't yield 'foo'
  • var o = {get foo(){}, set foo(x){}}; var desc = Object.getOwnPropertyDescriptor(o, "foo"); desc.get.name // doesn't yield 'get foo'
  • var o = {get foo(){}, set foo(x){}}; var desc = Object.getOwnPropertyDescriptor(o, "foo"); desc.set.name // doesn't yield 'set foo'

Also see #715 for a related case

Some of the scenarios that we currently cannot cover, as they rely on features Rhino doesn't currently support:

@p-bakker p-bakker added the Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec label Jan 29, 2023
@p-bakker p-bakker added this to the ES2015 milestone Jan 29, 2023
@rbri
Copy link
Collaborator

rbri commented Jan 30, 2023

will provide a patch for bound functions - because this is simple to fix :-)

rbri added a commit to rbri/rhino that referenced this issue Jan 30, 2023
andreabergia added a commit to andreabergia/rhino that referenced this issue Oct 20, 2023
andreabergia added a commit to andreabergia/rhino that referenced this issue Oct 20, 2023
gbrail pushed a commit that referenced this issue Oct 31, 2023
…1398)

Make the attributes of the "name" properties of functions match current ECMAScript specs.

See #1297 for more details
@p-bakker p-bakker reopened this Nov 14, 2023
johnspackman added a commit to johnspackman/rhino that referenced this issue Dec 25, 2023
…0917

* commit '6387bac4281ba1c4a8050cd055071615593d214c': (78 commits)
  More consistent test optimization levels (mozilla#1317)
  ci: set minimal permissions on GitHub Workflows
  Compare all primitive value type wrappers by value
  Fixing formatting issues
  Treat String, ConsString, Boolean, and Double as value types
  setter function (from property descriptor) has to convert the args (see HtmlUnit#7) also
  use try-with-resource
  FIX: Wrap key and value for NativeJavaMap iterator
  Added more tests
  FIX: Wrap result of iterator
  BUG: for X of javaList does not work properly in strict mode
  removed obsolete LineSeparator
  Spotless
  Preserving cause, when a JavaException is rethrown in JavaScript
  fix ScriptException when bound functions are called inside Promise.then()
  test cases from mozilla#1242 fix taken from p-bakker's sugestion
  fix name property for bound functions (see issue mozilla#1297)
  Fix the condition for isResourceChanged
  Code Cleanup (mozilla#1295)
  ignore %c styling but count to not disturb further replacements
  ...

# Conflicts:
#	src/org/mozilla/javascript/NativeObject.java
#	testsrc/org/mozilla/javascript/tests/json/JsonParserTest.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants