Skip to content

Impossible to write a script with async elements #137

Open
@BreizHell

Description

@BreizHell

jArchi Version

1.7

Archi Version

5.4.2

Operating System

Linux Mint Cinnamon 64bit

Description

Async scenarios lead to the following checkmate :

  • Case 1: If a promise is pending, but the synchronous part of the code is finished, the entire script is ended, before the promise can finish
  • Case 2: If a top level await is written, org.graalvm.polyglot.PolyglotException is raised

Steps to reproduce

  • Case 1:

    console.log("starting synchronous part");
    
    new Promise((resolve) => {
      console.log("starting async part");
      setTimeout(resolve, 1000);
    }).then(() => console.log("async part ended"));
    
    console.log("synchronous part ended");

    In this case, the JArchi console only prints:

    • "starting synchronous part"
    • "starting async part"
    • "synchronous part ended"

    => "async part ended" is never printed

  • Case 2:

    console.log("starting synchronous part");
    
    await new Promise((resolve) => {
      console.log("starting async part");
      setTimeout(resolve, 1000);
    })
    console.log("async part ended");

    There, the console displays the following error:

    org.graalvm.polyglot.PolyglotException: SyntaxError: Test.ajs:3:6 Expected ; but found new
    await new Promise((resolve) => {
          ^
    Test.ajs:6:0 Expected eof but found }
    }).then(() => console.log("async part ended"));
    ^
    
      at <js>.:program(<eval>:1)
      at org.graalvm.polyglot.Context.eval(Context.java:399)
      at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:478)
      at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:446)
      at java.scripting/javax.script.AbstractScriptEngine.eval(Unknown Source)
    

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions