[ERROR] com.gargoylesoftware.htmlunit.ScriptException: identifier is a reserved word: class
Tested on 2.36.0, 2.37.0 in maven central. Here's a sample HTML file that demonstrates the issue - works in any modern browser, but does not work in htmlunit:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ecmascript 2015 class example</title>
</head>
<body>
<script>
class Foo {
constructor(bar) {
this.bar = bar;
}
baz() {
return "hello " + this.bar;
}
}
console.log(new Foo("world").baz());
</script>
</body>
</html>
Output in chrome, ff: hello world
.
Is this something that needs to be explicitly done upstream in rhino? I didn't find a bug report or PR on their github repo, but I could well have missed it.
Full stack trace of the failure when it occurred:
net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: identifier is a reserved word: class (script in http://localhost:39421/sample.html from (7, 10) to (18, 11)#8)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$HtmlUnitErrorReporter.error(HtmlUnitContextFactory.java:438)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:258)
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:326)
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:313)
at net.sourceforge.htmlunit.corejs.javascript.Parser.primaryExpr(Parser.java:3186)
at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2743)
at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2637)
at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2558)
at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2542)
at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2523)
at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2498)
at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2470)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2459)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2448)
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2437)
at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2426)
at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2415)
at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2379)
at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2335)
at net.sourceforge.htmlunit.corejs.javascript.Parser.expr(Parser.java:2314)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1273)
at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1127)
at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:664)
at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:583)
at net.sourceforge.htmlunit.corejs.javascript.Context.parse(Context.java:2637)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileImpl(Context.java:2586)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1590)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$TimeoutContext.compileString(HtmlUnitContextFactory.java:224)
at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1579)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$1.doRun(JavaScriptEngine.java:704)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:867)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:624)
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.compile(JavaScriptEngine.java:713)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:679)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:725)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScript(HtmlPage.java:924)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:305)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:395)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:234)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:256)
at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.endElement(HtmlUnitNekoDOMBuilder.java:559)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.endElement(HtmlUnitNekoDOMBuilder.java:513)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1192)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1132)
at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:219)
at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:312)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3185)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2110)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:937)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:443)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:394)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.parse(HtmlUnitNekoDOMBuilder.java:758)
at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser.parse(HtmlUnitNekoHtmlParser.java:236)
at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser.parseHtml(HtmlUnitNekoHtmlParser.java:179)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:280)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:163)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:553)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:419)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:336)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:715)
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