This is probably rather a nashorn issue.
I stumbled upon these:
ERROR [14:07:20.006] c.g.h.j.b.JavaScriptJobManagerImpl - Job run failed with unexpected RuntimeException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: TypeError: TypeError: redeclaration of const DATA_BV_PRODUCT.
com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: TypeError: TypeError: redeclaration of const DATA_BV_PRODUCT.
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:944)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:619)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:537)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:354)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:873)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:845)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2609)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunction(HtmlPage.java:2602)
at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptFunctionJob.runJavaScript(JavaScriptFunctionJob.java:57)
at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutionJob.run(JavaScriptExecutionJob.java:102)
at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl.runSingleJob(JavaScriptJobManagerImpl.java:429)
at com.gargoylesoftware.htmlunit.javascript.background.DefaultJavaScriptExecutor.run(DefaultJavaScriptExecutor.java:148)
at java.lang.Thread.run(Thread.java:748)
Caused by: net.sourceforge.htmlunit.corejs.javascript.WrappedException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: TypeError: TypeError: redeclaration of const DATA_BV_PRODUCT.
at net.sourceforge.htmlunit.corejs.javascript.Context.throwAsScriptRuntimeEx(Context.java:1964)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:997)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:939)
... 12 common frames omitted
Caused by: com.gargoylesoftware.htmlunit.ScriptException: TypeError: TypeError: redeclaration of const DATA_BV_PRODUCT.
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:944)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:619)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:537)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:354)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:824)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:800)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:108)
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1023)
at com.gargoylesoftware.htmlunit.html.ScriptElementSupport.executeScriptIfNeeded(ScriptElementSupport.java:179)
at com.gargoylesoftware.htmlunit.html.ScriptElementSupport$1.execute(ScriptElementSupport.java:106)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:992)
... 13 common frames omitted
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: TypeError: redeclaration of const DATA_BV_PRODUCT.
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4342)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4320)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:4353)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError1(ScriptRuntime.java:4365)
at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.redefineProperty(ScriptableObject.java:2486)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.initScript(ScriptRuntime.java:3726)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter$CallFrame.initializeArgs(Interpreter.java:138)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.initFrame(Interpreter.java:2961)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:1008)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:111)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:427)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:340)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3640)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:123)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:815)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:929)
... 23 common frames omitted
So I digged a little into this and here's what I found out.
I wondered why FF and Chrome didn't complain about this because actually a script that defines const DATA_BV_PRODUCT
is loaded twice. But it's loaded via jQuery's .load()
method, which seems to wrap the return value in its own scope. The ajax bits of my application return HTML containing script tags:
<!-- ht1.htm -->
<script src="script1.js"></script>
some other content here
<!-- ht2.htm -->
<script src="script2.js"></script>
some other content here
This snippet is loaded twice via $.load()
:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<div id="a"></div>
<div id="b"></div>
<script>
$('#a').load('./ht1.htm', () => console.log('1 loaded'))
$('#b').load('./ht2.htm', () => console.log('2 loaded'))
</script>
</body>
</html>
And script1.js
and 2 just contain:
const ABC = "whatevs";
Now in the browser that's fine, no error and const ABC is not defined in the global scope.
With HtmlUnit however, I get the above exception.
Interestingly, when I skip the extra requests via ht1.htm
and directly load()
scrip1.js
(with script tags around) there's no exception thrown.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too