javadelight / delight-nashorn-sandbox

A sandbox for executing JavaScript with Nashorn in Java.
Other
268 stars 81 forks source link

Got an exception on load d3.js library #95

Open dmmax opened 4 years ago

dmmax commented 4 years ago

I have got an exception when try to include d3.js library. Exception:

Caused by: jdk.nashorn.internal.runtime.ParserException: :17:72 Expected ) but found ; for (null == r && (r = 0), null == i && (i = n.length); r < i;if();) {if(); at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:294) at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:279) at jdk.nashorn.internal.parser.AbstractParser.expectDontAdvance(AbstractParser.java:350) at jdk.nashorn.internal.parser.AbstractParser.expect(AbstractParser.java:337) at jdk.nashorn.internal.parser.Parser.forStatement(Parser.java:1322)

I tried to use approach @mxro that he suggested on issue https://github.com/javadelight/delight-nashorn-sandbox/issues/81 but it doesn't help. Could you fix it?

Steps to reproduce: 1) Create a pom file with dependencies:

<dependencies>
...
   <dependency>
      <groupId>org.javadelight</groupId>
      <artifactId>delight-nashorn-sandbox</artifactId>
      <version>0.1.26</version>
    </dependency>

    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.6</version>
    </dependency>
...
</dependencies>

2) Create Main class

public class Main {
   public static void main(String[] args) throws ScriptException, IOException {
        NashornSandbox sandbox = delight.nashornsandbox.NashornSandboxes.create();
        sandbox.eval(IOUtils.toString(ClassLoader.getSystemResourceAsStream("d3.js"), "utf-8"));
   }
}

3) Load content of d3.js library (https://d3js.org/d3.v5.min.js) to d3.js file (that should be exist by path: src/main/resources/d3.js)

mxro commented 4 years ago

Thank you for reporting this issue.

I think it still might have something to do with the poison pill, specifically the one that injects a statement in every for loop.