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

[js-core] Support of ECMA6 Javascript modules #1

Open
hadriensz opened this issue Sep 14, 2018 · 6 comments
Open

[js-core] Support of ECMA6 Javascript modules #1

hadriensz opened this issue Sep 14, 2018 · 6 comments
Labels
enhancement New feature or request js-engine Issues related to the js engine

Comments

@hadriensz
Copy link

copy of stackoverflow question:

https://stackoverflow.com/questions/52240645/htmlunit-cannot-process-javascript-module?noredirect=1#comment91433014_52240645

When parsing a complex web page with HTMLUnit, with javascript enabled, it refuses to process type="module" scripts.
Looking at the source code of HtmlScript it looks like scripts of any type other than "text/javascript" || « text/ecmascript » or « application/javascript" || « application/ecmascript" || "application/x-javascript" are rejected
Error is: com.gargoylesoftware.htmlunit.html.HtmlScript isExecutionNeeded WARNING: Script is not JavaScript (type: module, language: ). Skipping execution.
Is there a way to have module scripts also executed ?
Thanks

To this question RBRi suggested :

Please file a bug report for HtmlUnit or even better provide a patch (github.com/HtmlUnit/htmlunit)

Which I'm doing...

Justification (source : https://spring.io/understanding/javascript-modules, 2015)

In JavaScript, the word "modules" refers to small units of independent, reusable code. They are the foundation of many JavaScript design patterns and are critically necessary when building any non-trivial JavaScript-based application.
ECMAScript, the JavaScript standards body, expects to ratify a final specification for modules in ECMAScript version 6 by the end of 2014. ECMAScript 6 modules ("ES6 modules"), however, will likely not be feasible to use in production until 2016 due to the long upgrade cycles of some browsers and operating systems

Complete specification can be found here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

and is discussed here:
https://hacks.mozilla.org/2015/08/es6-in-depth-modules/
http://exploringjs.com/es6/ch_modules.html

additionnal considerations:

(1) it should be considered whether to support only ECMA6 or also previous common module technologies such as Asynchronous Module Definition (AMD), node.js / CommonJS Modules or Universal Module Definition (UMD). All of there could be considered as de facto module standards

(2) maybe this issue / feature should be moved to core-js github community. It looks like support for modules (only AMD probably) is already implemented there but not ported to HTMLUnit

(3) since ECMA6 appeared Oracle developed Nashhorn javascript engine. Is there a plan to support Nashhorn if it provides better ECMA6 support and more frequent updates than Rhino ?

@niloc132
Copy link

(3) since ECMA6 appeared Oracle developed Nashhorn javascript engine. Is there a plan to support Nashhorn if it provides better ECMA6 support and more frequent updates than Rhino ?

Possibly worth updating, Nashhorn has now been removed from the JRE - http://openjdk.java.net/jeps/335.

@OluwoleOyetoke
Copy link

Any clues on possible workaround for this issue or will there be a patch in the near future?

@rbri rbri added the enhancement New feature or request label Jul 23, 2022
@Jaaap
Copy link

Jaaap commented Apr 22, 2023

If i read
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
and more specifically
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#other_differences_between_modules_and_standard_scripts
correctly, it should be pretty straight forward to implement <script type="module"> and import and export.

The main differences will be in the scoping of individual JS files, which i assume is do-able?

I would help our project very much if this feature was added to HtmlUnit.

@scottpettyjohn
Copy link

Any movement on this?

@rbri
Copy link
Member

rbri commented Oct 20, 2023

@scottpettyjohn sorry not really. Have done a lot of work on Rhino during the last months but there is much more to do. And please keep in mind that i'm doing all the stuff in my spare time.

There is a plan to be more independent from core-js and then try to use another more recent js engine. But this is only a plan - maybe i will start on this at the beginning of next year.

@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
enhancement New feature or request js-engine Issues related to the js engine
Projects
None yet
Development

No branches or pull requests

6 participants