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

Changes to process integer object as integer and long as long, not as… #398

Merged
merged 4 commits into from Mar 12, 2018
Merged

Changes to process integer object as integer and long as long, not as… #398

merged 4 commits into from Mar 12, 2018

Conversation

ghost
Copy link

@ghost ghost commented Feb 27, 2018

Here is the problem: rhino is used inside handlebars library. When handlebars have to process js, it calls rhino for help. Assume there is a simple piece of js code: "data.lenght". When handlebars ask rhino to process it, it is expected a number without a decimal place (for instance 4) to be returned. In fact 4.0 is returned.
Small changes in this pull request change this behavior.

@ghost ghost closed this Feb 27, 2018
@ghost ghost reopened this Feb 28, 2018
@gbrail
Copy link
Collaborator

gbrail commented Mar 2, 2018

This seems like it's going to break someone, somewhere, who is expecting those properties to return numbers with decimal points in them. If this is important then we should consider whether it should be enabled by a feature flag.

Also, do you have an example of a bit of JavaScript that doesn't work due to the existing behavior?

@ghost
Copy link
Author

ghost commented Mar 5, 2018

It would be great to enable this on demand by feature flag. What is the way to put it under toggle?

Using handlebars I'm adding some js helper, something like this:

Handlebars.registerHelper('bannerLength', function(bannerTotal, options) {
return bannerTotal.length;
});

and to process it Rhino is used inside handlebars. It returns number with decimal place.

@gbrail
Copy link
Collaborator

gbrail commented Mar 5, 2018

Yes, perhaps others don't agree, but I feel that this change has a real chance to break existing code, and to even cause a performance regression. At the same time, I understand that it's important to your project and others may feel the same.

The way to make something optional in Rhino is to use the Context class, and by following the pattern used there.

For instance, you would:

  1. Add a constant to Context.java like "FEATURE_CONVERT_NUMBER_TO_INTEGER" with comments that describes it.
  2. Add a case in ContextFactory.java to set the default value (which I think should be false)
  3. Use it in your code by calling Context.hasFeature when you want to select the behavior. (And if you don't have a Context object in scope, you can call Context.getCurrentContext to get it.)

And again, you can follow the example of existing flags...

And once you do that, I'd like to also see some tests specifically for this behavior that test the behavior with the flag both on and off.

Thanks!

@ghost
Copy link
Author

ghost commented Mar 6, 2018

Thank you for clear explanation, will update pull request soon.

@gbrail
Copy link
Collaborator

gbrail commented Mar 12, 2018

Thanks for doing this -- it looks good, and if others find it useful or doesn't break their code then we can always look at making it the default.

@gbrail gbrail merged commit 1ff7bc0 into mozilla:master Mar 12, 2018
@ghost
Copy link
Author

ghost commented Mar 13, 2018

Thank you for your time.
I'd like to ask a question - what is the approximate time for next release (where this functionality can be used)?

@gbrail
Copy link
Collaborator

gbrail commented Mar 14, 2018 via email

@ghost
Copy link
Author

ghost commented Mar 19, 2018

It really didn't take long and exceeded our expectations, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants