IPED icon indicating copy to clipboard operation
IPED copied to clipboard

Upgrade JS interpreter to ECMAScript 6

Open robsonware opened this issue 4 years ago • 4 comments

If a try to use javascript validation using new features from ECMAScript 6 will produces:

2020-09-13 11:02:51     [ERROR] [gpinf.indexer.IndexFiles]                      Processing Error:
java.lang.RuntimeException: javax.script.ScriptException: <eval>:21:5 Expected ; but found s
        let s = 0;
            ^ in <eval> at line number 21 at column number 5
        at br.gov.pf.iped.regex.ScriptValidatorService.registerScript(ScriptValidatorService.java:52) ~[iped-engine-3.16.jar:?]
        at br.gov.pf.iped.regex.ScriptValidatorService.init(ScriptValidatorService.java:38) ~[iped-engine-3.16.jar:?]
        at dpf.sp.gpinf.indexer.process.task.regex.RegexValidator.init(RegexValidator.java:37) ~[iped-engine-3.16.jar:?]
        at dpf.sp.gpinf.indexer.process.task.regex.RegexValidator.init(RegexValidator.java:28) ~[iped-engine-3.16.jar:?]
        at dpf.sp.gpinf.indexer.process.task.regex.RegexTask.initValidators(RegexTask.java:189) ~[iped-engine-3.16.jar:?]
        at dpf.sp.gpinf.indexer.process.task.regex.RegexTask.init(RegexTask.java:181) ~[iped-engine-3.16.jar:?]
        at dpf.sp.gpinf.indexer.process.Worker.initTasks(Worker.java:111) ~[iped-engine-3.16.jar:?]
        at dpf.sp.gpinf.indexer.process.Worker.<init>(Worker.java:93) ~[iped-engine-3.16.jar:?]
        at dpf.sp.gpinf.indexer.process.Manager.iniciarIndexacao(Manager.java:313) ~[iped-engine-3.16.jar:?]
        at dpf.sp.gpinf.indexer.process.Manager.process(Manager.java:195) ~[iped-engine-3.16.jar:?]
        at dpf.sp.gpinf.indexer.IndexFiles.doInBackground(IndexFiles.java:208) [iped.jar:?]
        at dpf.sp.gpinf.indexer.IndexFiles.doInBackground(IndexFiles.java:59) [iped.jar:?]
        at javax.swing.SwingWorker$1.call(Unknown Source) [?:1.8.0_152]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_152]
        at javax.swing.SwingWorker.run(Unknown Source) [?:1.8.0_152]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_152]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_152]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_152]
Caused by: javax.script.ScriptException: <eval>:21:5 Expected ; but found s
        let s = 0;
            ^ in <eval> at line number 21 at column number 5
        at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:470) ~[nashorn.jar:?]
        at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:537) ~[nashorn.jar:?]
        at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:524) ~[nashorn.jar:?]
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402) ~[nashorn.jar:?]
        at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:150) ~[nashorn.jar:?]
        at javax.script.AbstractScriptEngine.eval(Unknown Source) ~[?:1.8.0_152]
        at br.gov.pf.iped.regex.ScriptValidatorService.loadScript(ScriptValidatorService.java:74) ~[iped-engine-3.16.jar:?]
        at br.gov.pf.iped.regex.ScriptValidatorService.registerScript(ScriptValidatorService.java:45) ~[iped-engine-3.16.jar:?]
        ... 17 more
Caused by: jdk.nashorn.internal.runtime.ParserException: <eval>:21:5 Expected ; but found s
        let s = 0;
            ^
        at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:294) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:279) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.AbstractParser.expectDontAdvance(AbstractParser.java:350) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.AbstractParser.expect(AbstractParser.java:337) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.Parser.endOfLine(Parser.java:3372) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.Parser.expressionStatement(Parser.java:1160) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.Parser.statement(Parser.java:967) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.Parser.sourceElements(Parser.java:773) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.Parser.functionBody(Parser.java:2901) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.Parser.functionExpression(Parser.java:2663) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.Parser.statement(Parser.java:875) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.Parser.sourceElements(Parser.java:773) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.Parser.program(Parser.java:709) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.Parser.parse(Parser.java:283) ~[nashorn.jar:?]
        at jdk.nashorn.internal.parser.Parser.parse(Parser.java:249) ~[nashorn.jar:?]
        at jdk.nashorn.internal.runtime.Context.compile(Context.java:1284) ~[nashorn.jar:?]
        at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:1251) ~[nashorn.jar:?]
        at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:627) ~[nashorn.jar:?]
        at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:535) ~[nashorn.jar:?]
        at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:524) ~[nashorn.jar:?]
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402) ~[nashorn.jar:?]
        at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:150) ~[nashorn.jar:?]
        at javax.script.AbstractScriptEngine.eval(Unknown Source) ~[?:1.8.0_152]
        at br.gov.pf.iped.regex.ScriptValidatorService.loadScript(ScriptValidatorService.java:74) ~[iped-engine-3.16.jar:?]
        at br.gov.pf.iped.regex.ScriptValidatorService.registerScript(ScriptValidatorService.java:45) ~[iped-engine-3.16.jar:?]
        ... 17 more

ERROR!!!
Check the log at ***\log\IPED-2020-09-13-11-02-21.log

This is not critical, but would be nice to support ECMAScript6 in future releases. http://es6-features.org

IPED Version: 3.16.3

robsonware avatar Sep 13 '20 14:09 robsonware

The JavasScript engine has been removed from JDK 15 onwards (https://openjdk.java.net/jeps/372). An alternative is using GraalJS that aims at full compatibility with the latest ECMAScript specification and can be run on the JDK: https://github.com/oracle/graaljs/blob/master/docs/user/RunOnJDK.md

bhoelz avatar Feb 19 '21 14:02 bhoelz

Thank you for pointing @bhoelz !

lfcnassif avatar Feb 19 '21 17:02 lfcnassif

I just closed PR #1066 until we decide to upgrade from JDK 11 to JDK 17 (this will probably bring issues with some dependencies not ready for JDK 17 yet), since this adds about 40MB of graal js dependencies. I think we can live without ECMA script 6 for some more time.

lfcnassif avatar Apr 26 '22 13:04 lfcnassif

Let's leave this open, I just said I wouldn't integrate it now, but it could be, and probably will, in the future.

lfcnassif avatar May 04 '22 20:05 lfcnassif

Hi @robsonware, I'm still not very happy to add 50MB of Graal JS dependencies. I just found this JS Nashorn standalone implementation to be used with JDK > 14 with just 2MB size: https://github.com/openjdk/nashorn

It doesn't aim at full compatibility with last ECMAScript specification, but are features below enough for you?

It also implements many new features introduced in ECMAScript 6 including template strings; let, const, and block scope; iterators and for..of loops; Map, Set, WeakMap, and WeakSet data types; symbols; and binary and octal literals.

lfcnassif avatar Oct 23 '23 17:10 lfcnassif

Yes! Thank you so much

robsonware avatar Oct 23 '23 18:10 robsonware

Yes! Thank you so much

Great! The standalone Nashorn project is GPL 2 licensed with the Classpath exception like the JDK:

CLASSPATH EXCEPTION TO THE GPL

Certain source files distributed by Oracle America and/or its affiliates are
subject to the following clarification and special exception to the GPL, but
only where Oracle has expressly included in the particular source file's header
the words "Oracle designates this particular file as subject to the "Classpath"
exception as provided by Oracle in the LICENSE file that accompanied this code."

Linking this library statically or dynamically with other modules is making
a combined work based on this library.  Thus, the terms and conditions of
the GNU General Public License cover the whole combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,
and to copy and distribute the resulting executable under terms of your
choice, provided that you also meet, for each linked independent module,
the terms and conditions of the license of that module.  An independent
module is a module which is not derived from or based on this library.  If
you modify this library, you may extend this exception to your version of
the library, but you are not obligated to do so.  If you do not wish to do
so, delete this exception statement from your version.

So I think it is fine to add it as dependency and I'll proceed.

lfcnassif avatar Oct 23 '23 18:10 lfcnassif