Elemental2 oddities

68 views
Skip to first unread message

Craig Mitchell

unread,
Jul 28, 2025, 1:39:57 AMJul 28
to GWT Users
I'm switching to use Elemental2, and it's fantastic.  All the bindings I'll ever need.  A big thank you to all that created it!

There are some strange things though.  Like when setting up a WebGLRenderingContext, we need to pass WebGLContextAttributes.

However, doing:
WebGLContextAttributes contextAttributes = new WebGLContextAttributes();

compiles fine, but at runtime throws:
TypeError: $wnd.WebGLContextAttributes is not a constructor

I figured out I can do this instead:
WebGLContextAttributes contextAttributes = Js.uncheckedCast(JsPropertyMap.of());

But why can't I just use its constructor?  Am I doing something wrong?

Jens

unread,
Jul 28, 2025, 4:55:23 AMJul 28
to GWT Users
Because it is only a dictionary (= a plain JS object)


In JS you simply do:

var canvas = document.getElementById('canvas');
var context = canvas.getContext('webgl', { antialias: false, stencil: true }); // 2nd argument is WebGLContextAttributes
var attributes = context.getContextAttributes();

Looks like it is again defined badly in closure-compiler externs. The generated elemental2 implementation should have a similar structure than for example elemental2 AddEventListenerOption. It is an interface with a static create() method which does exactly what you do in your solution.

See:


I think it should be @interface or @record instead of @constructor.


-- J.

Craig Mitchell

unread,
Jul 28, 2025, 6:20:37 AMJul 28
to GWT Users
Thanks again Jens.  Issue raised:  https://github.com/google/closure-compiler/issues/4250
Reply all
Reply to author
Forward
0 new messages