Tuesday, May 12, 2020

JsInterop - fail to iterate @JsType in List

Hi,

So I don't know if it's a known JsInterop issue but here is my problem (PS: I'm running GWT 2.9.0-RC1):

So in my home page I have the following code:

<script>
class Car {
start() {
return "start";
}
}

var car = new Car();
</script>

I have the following @JsType:

import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;

@JsType(isNative = true)
public class Car {
@JsProperty(namespace = JsPackage.GLOBAL) public static Car car;

public native String start();
}

And I'm just trying the following code:

GWT.log("direct call: " + Car.car.start());
List<Car> cars = Arrays.asList(Car.car);
try {
for (Car car : cars) {
car.start();
}
} catch (Exception exception) {
GWT.log("FAILED to iterate a @JsType in a List", exception);
}

But it fails with the following logs:
direct call: start
ConsoleLogger.java:33 FAILED to iterate a @JsType in a List
ConsoleLogger.java:55 Exception: com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'project' of undefined
ConsoleLogger.java:33 TypeError: Cannot read property 'project' of undefined
at dse_g$ (App.java:75)
at tse_g$.use_g$ [as execute_1_g$] (App.java:66)
at rfb_g$ (SchedulerImpl.java:50)
at Xeb_g$ (SchedulerImpl.java:183)
at Meb_g$.Seb_g$ [as flushPostEventPumpCommands_0_g$] (SchedulerImpl.java:347)
at ifb_g$.jfb_g$ [as execute_2_g$] (SchedulerImpl.java:78)
at Peb_g$ (SchedulerImpl.java:141)
at ydb_g$ (Impl.java:309)
at Bdb_g$ (Impl.java:361)
at Impl.java:78
at callback_0_g$ (SchedulerImpl.java:196)


I have a small demo project to reproduce the issue: https://github.com/freddyboucher/gwt-storage-objectify/commit/e4184b0ccd5bd490b16cbc6bb56b0d33fe6e76d1

Is it a bug or a known limitation of JsType?

Thank you

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/88c54dfb-f071-4fb6-a66e-6f22d0b30f45%40googlegroups.com.

No comments:

Post a Comment