1

In trying to load the env-js library into nashorn, I'm finding that it chokes on parsing this syntax:

function () { ...
   get x(){ ... },
   get y() { ... },
   ...
}

which seems to be parsed fine in rhino. I can't find any references to the version of javascript currently supported by nashorn. Is this due to nashorn not supporting this syntax?

1
  • 1
    It is EMCAScript 5.1. See openjdk.java.net/jeps/174. How are you loading env-js? Are you loading the rhino script? Commented Jun 4, 2014 at 11:26

3 Answers 3

1

Hannes Wallnoefer did a port of env.js for Nashorn. It's included as an attachment to a feature request for Nashorn. I haven't tried it, but it is relatively recent work and presumably still works.

https://bugs.openjdk.java.net/browse/JDK-8006183

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. I will definitely take a look at this.
This turns out not to work for an unrelated reason - we're doing DOM parsing, envjs relied on e4x. The port referenced above also relies on that, unfortunately e4x doesn't exist in nashorn so DOM parsing fails. (bugs.openjdk.java.net/browse/JDK-8006183). But thanks for the suggestion.
Oh okay. That's too bad. My first thought was that "can't you just find an e4x js lib and include that", but obviously you would have looked into that and it's either not possible or not desirable for some reason. Best of luck. Post a solution if you find one. It's likely I will need to do this one day.
0

get x() and set x() are to be used only within object literals (to define getter and setter for property "x"). I'm not sure if the above code snippet (where get x() and set x() are definied within a function definition) is accepted even by Rhino. Will you please point to the envjs code snippet that uses the above?

Comments

0

I did an initial port of env.js to Nashorn at https://github.com/blipper/env-js on the master branch. This version comments out the event loop because we were primarily using the XHR features. We are going to dust it off for internal reasons at work soon so there should be some more commits on it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.