archi-scripting-plugin icon indicating copy to clipboard operation
archi-scripting-plugin copied to clipboard

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

Open indeyets opened this issue 4 years ago • 4 comments
trafficstars

Code I try:

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

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

indeyets avatar Jun 21 '21 10:06 indeyets

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?

indeyets avatar Jun 21 '21 10:06 indeyets

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.

Phillipus avatar Jun 21 '21 10:06 Phillipus

{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

indeyets avatar Jun 21 '21 10:06 indeyets

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

To do with handling of PolyglotMap and ScriptObjectMirror objects.

Phillipus avatar Jun 21 '21 11:06 Phillipus