Calling methods on Uint8Array is causing a ReferenceError in Super Dev Mode...

115 views
Skip to first unread message

TimOnGmail

unread,
Nov 8, 2017, 7:45:56 PM11/8/17
to GWT Users
Hey folks...

I have some code that looks like this:

private native void myNativeMethod() /*-{
    ...
    var myArrayBuffer = [something that gets an ArrayBuffer);
    this.@myPackmage::myNonNativeMethod(Lcom/google/gwt/typedarrays/shared/ArrayBuffer;)(myArrayBuffer);
}-*/


 
private void myNonNativeMethod(ArrayBuffer buffer) {
   
Uint8Array uint8Array = TypedArrays.createUint8Array(buffer);
    uint8Array
.byteLength(); // *** HERE ***
}

 At "*** HERE ***", that line runs fine when running compiled GWT code.

However, when run in Super Dev Mode, I get something like this:

Uncaught ReferenceError: $zIb_g$ is not defined
    at
QHcb_g$.wHcb_g$ [as myNonNativeMethod_1_g$] (app-0.js:1350405:3)
    at
FileReader.<anonymous> (app-0.js:1350882:25)

I tried a bunch of other methods, and they all get this error; toString() was successful, but all the others I tried failed like the above.

Anyone know why this might be?  Is there an issue with Super Dev Mode in dealing with these JavaScript wrapper classes?

- Tim

TimOnGmail

unread,
Nov 8, 2017, 8:35:02 PM11/8/17
to GWT Users
I should add, the underlying data is coming from a FileReader object, reading data from the MediaRecorder API.  I suppose this is the actual cause, though I'm not sure.  I would think everything would be fine if it's working in compiled mode...

- Tim

TimOnGmail

unread,
Nov 8, 2017, 8:44:02 PM11/8/17
to GWT Users
Actually, now that I look at it, I am guessing that the underlying buffer used by the FileReader is changing state while I'm trying to access it; I should have made a copy of it before using it.

I shall try that and see if that fixes it.

I don't know why it would work compiled but not in Super Dev Mode, except perhaps there are timing considerations involved here.

TimOnGmail

unread,
Nov 8, 2017, 8:58:09 PM11/8/17
to GWT Users
Hmmm, nope - even if I make a copy of the buffer, I still get the above error in Super Dev mode.

Any ideas, anyone?

- Tim

Colin Alworth

unread,
Nov 11, 2017, 2:11:08 PM11/11/17
to GWT Users
Can you run super dev mode with `-style PRETTY`? The line you are pointing at should only error out like that if createUint8Array returned null, but it would be good to confirm that in PRETTY you see the name of the local variable.

.byteLength() in the native code is just defined as access on the .byteLength field of the view, so that seems sane enough - should only error out of there is no Uint8Array. But createUint8Array should just delegate to Uint8ArrayNative.create(buffer, 0, buffer.byteLength()) anyway, which just calls the JS constructor, so that doesn't make a ton of sense either...

Try PRETTY, and maybe turn off sourcemaps so you can see what is generated - perhaps there is a bug and SDM is making a mistake, or maybe something else will be clear to you once you see the sources (probably in your own JSNI).

Finally, which version of GWT are you using?

tekkyru

unread,
May 30, 2025, 1:34:17 PMMay 30
to GWT Users
I face similar problem, trying to use ArrayBuffer and Uint8Array. JDK 17, GWT 2.12.1, Windows workstation

My original intent was to return bytes of user-selected file from JSNI to GWT code. But now I see even simplest pure GWT java code doesn't work. 
I create ArrayBuffer, then create Uint8Array from it.
Any Uint8Array methods except toString() fail with ReferenceError. I see "devirtual" there, may it give a clue...

I probably do something wrong but I cannot find any example in the internet.

ArrayBuffer arrayBuffer = TypedArrays.createArrayBuffer(20);

GWT.log("ab.length = " + arrayBuffer.byteLength());

Uint8Array uintArray = TypedArrays.createUint8Array(arrayBuffer);

GWT.log("uintArray = " + uintArray);

// ---------- THE CALL BELOW FAILS ---------

GWT.log("uintArray[0] " + uintArray.get(0));


ab.length = 20
uintArray = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
SEVERE ****MYAPP**** Exception: com.google.gwt.core.client.JavaScriptException: (ReferenceError) : com_google_gwt_typedarrays_client_Uint8ArrayNative_get_1I_1S_1_1devirtual$__Lcom_google_gwt_typedarrays_shared_Uint8Array_2IS is not defined
at Unknown. ***MYAPP*** _testArrayBuffer__V(***MYAPP***-0.js@3:260605)
at ....

--------------
JDK 17
GWT 2.12.1
Code server Command line:

Run GWT Code Server: [-launcherDir, C:\home\ws\MYAPP\.metadata\.plugins\org.eclipse.wst.server.core\tmp0/wtpwebapps/MYAPP, -workDir, MYTMPDIR, -logLevel, INFO, -style, DETAILED, -sourceLevel, 17, -port, 9876, -generateJsInteropExports, MYAPPNAME]


tekkyru

unread,
May 30, 2025, 1:53:10 PMMay 30
to GWT Users
Aaaand
After clean SuperDevMode restart (after deletion of GWT temp files in gradle build and in Windows TEMP folder) everything works as expected.
(I'm posting it as advice instead of removing my post so people with similar problems will have an option)

Reply all
Reply to author
Forward
0 new messages