dodona-edu / universal-judge

Universal judge for educational software testing
https://docs.dodona.be/en/tested
MIT License
9 stars 5 forks source link

Report compilation error upon invalid JavaScript code #354

Closed pdawyndt closed 1 year ago

pdawyndt commented 1 year ago

Example: submission 13892016

Comment by @niknetniko:

Het probleem zit op de lijnen 52-53: daar worden "octal literals" gebruikt, maar die zijn niet toegestaan in "strict mode", en alle code in een klasse is per definitie in "strict mode". De reden dat de oefeningen niet de status "compilatiefout" heeft, is waarschijnlijk een bug in TESTed.

De foutboodschap die verschijnt is omdat we in JavaScript, voor we de oplossing beoordelen, de AST parsen om alle functies en klassen te exporteren uit de oplossing (zodat we later "import ..." kunnen doen). Het parsen van de AST loopt echter fout (want het is geen geldige syntaxis), en dus zijn er geen exports, en dus krijg je "ReferenceError: Qlocktwo is not defined".

Ik kijk na waarom de compilatiefout niet doorgegeven wordt.

niknetniko commented 1 year ago

It seems like Node (and Chrome) don't enforce strict mode in this case, even though they should. For example, the following code violates strict mode:

class Example {
    static test = {
        00: '',
        05: 'VIJF NA',
        10: 'TIEN NA'
    };
}

However, both node --check and the Chrome console accept it without issue: image

However, most libraries do not accept it, and neither does Firefox: image

Some solutions could be:

That last one is annoying, since that step shouldn't fail (so if it does, it should be an internal error instead).

niknetniko commented 1 year ago

Enabling strict mode everywhere is not as simple as it looks, since NodeJS apparently doesn't honour the --use-strict flag (see https://github.com/nodejs/node/issues/30039). It also became clear that the NodeJS people aren't a big fan of the flag.

A more robust way to enforce strict mode would then be to add "use strict" to every submission, but that is more work, although we do have support for this kind of thing.

A check of all the latest submissions from "Scriptingtalen" didn't reveal any instance where enabling strict mode changed the result.

pdawyndt commented 1 year ago

FYI: Here's an example of a submission where the student enabled strict mode himself.