IDBFactory idbf = IndexedDbGlobal.indexedDB;
IDBOpenDBRequest idbr = idbf.open(INDEXEDDB_NAME);
idbr.onsuccess= new OnsuccessFn() {
@Override
public Object.onInvoke(elemental2.dom.Event p0) {
IDBDatabase idb = (IDBDatabase) idbr.result;
return idb;
}
IDBFactory idbf = IndexedDbGlobal.indexedDB;
IDBOpenDBRequest idbr = idbf.open(INDEXEDDB_NAME);
idbr.onsuccess = new OnsuccessFn() {
@Override
public Object onInvoke(elemental2.dom.Event p0) {
//error is next
idb = (IDBDatabase) idbr.result;
DOMStringList dsl = idb.objectStoreNames;
dsl.asList().forEach(s -> {
Log.error("FOUND DB " + s);
});
return idbr.result;
}
};
On Chrome desktop, I find the indexeddb I created in handwritten js code. I don't get why there is a ClassCastException in some browsers. Is elemental2-indexeddb or gxt 2.9 (HEAD) not supported everywhere?
@SuppressWarnings({ "unchecked" }) public static void initIndexedDb() {
IDBFactory idbf = IndexedDbGlobal.indexedDB; IDBOpenDBRequest idbr = idbf.open(INDEXEDDB_NAME); idbr.onsuccess = new OnsuccessFn() { @Override public Object onInvoke(elemental2.dom.Event p0) {
// fails w java.lang.ClassCastException // IDBDatabase idb = (IDBDatabase) idbr.result; // IDBDatabase idb = Js.<IDBDatabase> cast(db); //this works IDBDatabase idb = Js.<IDBDatabase> uncheckedCast(idbr.result);
DOMStringList dsl = idb.objectStoreNames; dsl.asList().forEach(s -> {
Log.info("FOUND DB " + s); }); return idbr.result; } }; idbr.onerror = new OnerrorFn() {
@Override public Object onInvoke(elemental2.dom.Event p0) {
Log.error("OnerrorFn " + p0.type); return null; } }; }
--
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-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/cbc724a1-5b8b-4478-8119-02af3d279c2b%40googlegroups.com.
Probably
--> IDBDatabase idb = Js.uncheckedCast(idbr.result);
would work too.
The point is is uncheckedCast is (AFAIU) considered dangerous.
There are two other casts that perform run-time checks but they have a 1) performance penalty and 2) some times throw exceptions not due to a bug but because the casting is invalid based on the type definitions GWT compiler knows about.
Here is the first type:
a) Java cast --> MyObject x = (MyObject) yourObject;
b) Js checked cast --> MyObject x = Js.cast(yourObject);
and of course
c) Js unchecked cast --> MyObject x = Js.uncheckedCast(yourObject);
I think (not sure) that a) and b) are the same at least on development mode. Not so sure what they are doing in production mode.
My 2 cents of limited understanding...
Vassilis
Hi,I get a ClassCastException under Safari, Safari on IOS and Chrome on IOS but not in Chrome.
Wrt the cast error, it might be that the object in 'result' is not "instanceof $wnd.IDBDatabase". This would be a bug in Safari; and uncheckedCast is indeed the workaround.
Actually I believe it is a bug in closures externs from which elemental2 is generated. Without checking my guess is that IDBDatabase is annotated with a @constructor tag rather than a @interface which is incorrect as the spec defines it as an interface [1]. Unfortunately, this is a common problem with some of the closure compiler externs. It does not impact people using closure compiler. Unfortunately, the jsinterop-generator will generate incorrect code if the extern is incorrectly annotated.
Actually I believe it is a bug in closures externs from which elemental2 is generated. Without checking my guess is that IDBDatabase is annotated with a @constructor tag rather than a @interface which is incorrect as the spec defines it as an interface [1]. Unfortunately, this is a common problem with some of the closure compiler externs. It does not impact people using closure compiler. Unfortunately, the jsinterop-generator will generate incorrect code if the extern is incorrectly annotated.But they do accept fixes for these kind of things?