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

const must have an initial value when declared. #1251

Open
naijun0403 opened this issue Jul 28, 2022 · 3 comments
Open

const must have an initial value when declared. #1251

naijun0403 opened this issue Jul 28, 2022 · 3 comments
Labels
bug Issues considered a bug Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec
Milestone

Comments

@naijun0403
Copy link
Contributor

naijun0403 commented Jul 28, 2022

Enviroment

  • rhino version: 1.7.14
  • os: windows

Reproduction

  1. Run Rhino REPL. (java -jar ./rhino-1.7.14.jar -version 200 -debug)
  2. eval this code
const a;
  1. At this time, the code runs normally in Rhino. However, this is not up to the standard.

ref. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const#const_needs_to_be_initialized

Expect Error

SyntaxError: Missing initializer in const declaration

@p-bakker
Copy link
Collaborator

p-bakker commented Sep 4, 2022

This ought to be part of a larger topic of getting the const implementation up to standard, see #939

I see you fixed it in your own branch, which is great, but I think in order to Rhino to accept a PR for this, it would have to be part of a larger PR to fixes a lot more of the issues with the current const implementation in one go and put all the new (or all the old) behavior behind a flag, as to provide existing embedders an option to upgrade Rhino without breaking existing JavaScript logic.

That said: it would be great to improve the const implementation! If you're up for that, please let us know. I for one have some ideas on how to possibly approach it

@p-bakker p-bakker added the bug Issues considered a bug label Sep 4, 2022
@p-bakker p-bakker added this to the ES2015 milestone Sep 4, 2022
@p-bakker p-bakker added the Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec label Sep 4, 2022
@naijun0403
Copy link
Contributor Author

That said: it would be great to improve the const implementation! If you're up for that, please let us know. I for one have some ideas on how to possibly approach it

I ran tests based on that fix, and it seems that many Rhino tests don't adhere to that standard.

When uploading const related modifications to PR, it seems that some tests should be modified together.

@p-bakker
Copy link
Collaborator

I ran tests based on that fix, and it seems that many Rhino tests don't adhere to that standard

When uploading const related modifications to PR, it seems that some tests should be modified together.

Yup, const support in Rhino was added as part of JavaScript 1.5/EcmaScript 3 (around the year 2000) and as such pre-dates support for const being added in EcmaScript 2015 and when it did get added to EcmaScript, the semantics ended up being different to what was already implemented in Rhino (for example function scoped vs. block scoped)

So it's expected that when the const implementation starts adhering to it's ES2015 specification, tests that were created based on the JavaScript 1.5 spec will break.

Since Rhino is out there being used a a ton of projects/apps with the current const implementation, when changes are made to make Rhino adhere to the ES2015 const spec, I think the only way this can be done is by having a flag to toggle between the JS1.5 and ES2015 behavior, otherwise we might break a ton of existing code

Note that in ES2015 besides a better const specification also let was added (which Rhino has good support for). And const and let do follow the exact same scoping rules (to my knowledge). So my thought on getting proper const support in Rhino was to let the handling of both let and const be done by the same code, only differentiating where needed (i.e. const needing to be initialized with a value and then being readOnly basically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues considered a bug Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec
Projects
None yet
Development

No branches or pull requests

2 participants