Elemental2 oddities

103 views
Skip to first unread message

Craig Mitchell

unread,
Jul 28, 2025, 1:39:57 AM7/28/25
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 AM7/28/25
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 AM7/28/25
to GWT Users
Thanks again Jens.  Issue raised:  https://github.com/google/closure-compiler/issues/4250

Craig Mitchell

unread,
Jul 7, 2026, 7:57:19 PM (19 hours ago) Jul 7
to GWT Users
With the Elemental2 1.4.0-RC1 release, we now have a new WebGLContextAttributes class that now has a create method.

However, calling it:
WebGLContextAttributes contextAttributes = WebGLContextAttributes.create();

Results in:
com.google.gwt.core.client.JavaScriptException: (ReferenceError) : mOu_g$ is not defined

Which isn't what I expected.

Doing this still works:
WebGLContextAttributes contextAttributes = Js.uncheckedCast(JsPropertyMap.of());

I don't have the closure compiler knowledge to understand what's going on here.  Was the fix ( https://github.com/google/closure-compiler/issues/4250 ) not correct?
Reply all
Reply to author
Forward
Message has been deleted
0 new messages