HtmlUnit / htmlunit

HtmlUnit is a "GUI-Less browser for Java programs".
https://www.htmlunit.org
Apache License 2.0
842 stars 166 forks source link

ScriptException: identifier is a reserved word: class #480

Open sengsational opened 2 years ago

sengsational commented 2 years ago

This exception is being thrown and I think it might be why I'm unable to progress through testing.

Exception class=[net.sourceforge.htmlunit.corejs.javascript.EvaluatorException]
com.gargoylesoftware.htmlunit.ScriptException: identifier is a reserved word: class (https://member.bcbsnc.com/blueconnect/web/js/chunk-vendors.2f859219.js#3)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:980)

The complete stack trace is attached. EvaluatorException_IdentifierIsAReservedWord.txt

Version: 2.60.0, running on MS Windows

sengsational commented 2 years ago

I have recreated the error in IntelliJ with htmlunit built from source, but it appears that the problem is in either net.sourceforge.htmlunit.cyberneko or net.sourceforge.htmlunit.corejs.javascript (the build has those as jars).

The exception is thrown by this line: https://github.com/HtmlUnit/htmlunit/blob/a7d65d735168f923c636476245b149f7d1eeb444/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java#L816 That's code in net.sourceforge.htmlunit.corejs.javascript.Context

I need to figure out how to do the build so cyberneko and corejs is from source too.

sengsational commented 2 years ago

Looking in htmlunit-rhino-fork, I found the error that's thrown under class decorators in htmlunit-rhino-fork/docs/compat/engines.html. If I'm reading this right, it's saying that mozilla/rhino does not support javascript class decorators.

The following is given as an example:

class A {
  @nonconf
  get B() {}
}
function  nonconf(target, name, descriptor) {
  descriptor.configurable = false;
  return descriptor;
}
return  Object.getOwnPropertyDescriptor(A.prototype, "B").configurable === false;

I'm not sure what about that makes it a class decorator. Is there another way to write that code so it isn't considered a class decorator? I'm thinking about a work-around where I would add a pre-processor like webClient.setScriptPreProcessor(preProcessor); and re-write the unsupported javascript construct.

rbri commented 2 years ago

Will try to have a look....

jeffcjohnson commented 2 years ago

Was just coming to write a ticket for this. If it helps, here's a one-liner to reproduce:

import com.gargoylesoftware.htmlunit.WebClient
import com.gargoylesoftware.htmlunit.html.HtmlPage

fun main() { WebClient().getPage<HtmlPage>("https://www.hcso.org/") }
rbri commented 2 years ago

Have started some work to optionally integrate babel as preprocessor for the scrips to overcome some Rhino limitations. But this will requires some time.

sengsational commented 2 years ago

Sounds like a great idea for how to manage the Rhino limitations.

erg43hergeg commented 1 year ago

hey, any progress?

rbri commented 1 year ago

sorry, no, far too many other activities

sengsational commented 10 months ago

Revisiting this after a long while. As of 3.5.0, the problem still persists. Wow, reading my earlier investigations from April 2022 on this topic, I'm pretty sure I'm dumber now than I used to be, LOL!

JamesLee66 commented 7 months ago

I have also encountered this problem. Do you have any good solutions

rbri commented 3 months ago

see #755