archimatetool / archi-scripting-plugin

jArchi - Scripting for Archi: ArchiMate Modelling Tool
https://www.archimatetool.com
118 stars 33 forks source link

console.log() does not print arrays (GraalVM) #92

Open indeyets opened 3 years ago

indeyets commented 3 years ago

Code I try:

console.log([1,2,3]);

Actual result: {} Expected result: Array(3) [ 1, 2, 3 ] (or something similar)

indeyets commented 3 years ago

It looks like this plugin uses custom console code. Could it reuse https://www.graalvm.org/reference-manual/js/JavaScriptCompatibility/#methods-of-the-console-global-object probably?

Phillipus commented 3 years ago

If you use Nashorn you get:

{0: 1, 1: 2, 2: 3}

The object sent to jArchi's console is not always parsable. Using GraalVM it is a Graal PolyglotMap object which returns an empty set (although internally it has something). This may be a bug or peculiarity of Graal. I know there are some differences in the way Graal handles Map objects.

We have two log methods:

log(Object obj)

and

log(Object... objs)

Graal uses the first one when it should actually use the second one.

It looks like this plugin uses custom console code. Could it reuse https://www.graalvm.org/reference-manual/js/JavaScriptCompatibility/#methods-of-the-console-global-object probably?

Not sure how that is exposed, and also won't work if using Nashorn.

indeyets commented 3 years ago

{0: 1, 1: 2, 2: 3}

This is suboptimal too, as it doesn't provide distinction between Array and generic Object representation

Not sure how that is exposed, and also won't work if using Nashorn.

I'll try to look at it, but no promises here. Might be distracted by different projects. Anyway, it looks like this could easily be conditional code. It doesn't have to work similar between engines

Phillipus commented 3 years ago

For reference: https://github.com/oracle/graaljs/issues/228

To do with handling of PolyglotMap and ScriptObjectMirror objects.