question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ES2015 classes are not supported

See original GitHub issue
[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)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rbricommented, May 19, 2021

have merged back nearly all improvements into rhino and rhino makes some good progress at the moment. Let’s cross our fingers

0reactions
black-snowcommented, Jan 28, 2021

Just stumbled over this again. Here’s a (mostly red) es2015 support chart: https://mozilla.github.io/rhino/compat/engines.html @rbri is there a list of things that work with your improvements upon Rhino?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ES6 classes | Can I use... Support tables for HTML5, CSS3, etc
ES6 classes are syntactical sugar to provide a much simpler and clearer syntax to create ... Non-strict mode support is behind the flag...
Read more >
javascript - Do ES2015 Classes "not autobind"? - Stack Overflow
The reason is that javascript's ES6 classes have no autobinding neither[sic]. React tries to not reinvent stuff that is already in javascript. ES5...
Read more >
Classes - JavaScript - MDN Web Docs
Classes are a template for creating objects. They encapsulate data with code to work on that data. Classes in JS are built on...
Read more >
Extends ES5 classes with ES6 classes is not supported
Extends ES5 classes with ES6 classes is not supported ; Assignee, Konstantin Ulitin ; Subsystem, JavaScript ; Affected, No Affected version ; Tester,...
Read more >
ES6 classes are not supported for grid class · Issue #3437
Uncaught TypeError: Class constructor TimeGrid cannot be invoked without 'new'. ... The same issue likely applies to Babel ES6 classes because ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found