Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScriptException: identifier is a reserved word: class #480

Open
sengsational opened this issue Apr 22, 2022 · 11 comments
Open

ScriptException: identifier is a reserved word: class #480

sengsational opened this issue Apr 22, 2022 · 11 comments
Assignees
Labels
js-engine Issues related to the js engine

Comments

@sengsational
Copy link

sengsational commented Apr 22, 2022

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
Copy link
Author

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:

return cx.compileString(sourceCode, sourceName, startLine, null);
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
Copy link
Author

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
Copy link
Member

rbri commented Apr 30, 2022

Will try to have a look....

@jeffcjohnson
Copy link

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
Copy link
Member

rbri commented May 24, 2022

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

@rbri rbri self-assigned this May 24, 2022
@sengsational
Copy link
Author

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

@erg43hergeg
Copy link

hey, any progress?

@rbri
Copy link
Member

rbri commented Dec 22, 2022

sorry, no, far too many other activities

@sengsational
Copy link
Author

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
Copy link

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

@rbri rbri added the js-engine Issues related to the js engine label Mar 27, 2024
@rbri
Copy link
Member

rbri commented Mar 27, 2024

see #755

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js-engine Issues related to the js engine
Projects
None yet
Development

No branches or pull requests

5 participants