gwtproject / gwt

GWT Open Source Project
http://www.gwtproject.org
1.51k stars 372 forks source link

Overlay type single jso implementation restriction bug #8706

Closed dankurka closed 9 years ago

dankurka commented 9 years ago

Originally reported on Google Code with ID 8741

Found in GWT Release (e.g. 2.4.0, 2.5.1, trunk):
Since 1.5 

Detailed description (please be as specific as possible):
I remember this restriction is described as a bug in google:io 2013,and it do cause
problems in practical design,and many people mentioned it.So,will this bug be fixed
or never? Since it exists for such long time.

Links to relevant posts:
https://code.google.com/p/google-web-toolkit/wiki/OverlayTypes

Reported by Alexander.Luya on 2014-05-31 01:43:46

dankurka commented 9 years ago
I don't think JavaScriptObject will change, but maybe the new JsInterop allows this.

Reported by t.broyer on 2014-06-02 08:47:00

dankurka commented 9 years ago
A Java interface can only be implemented by one JavaScriptObject and this is very unlikely
to change.

The new JsInterop just consists of interfaces and there is no need for any implementation
of the interface for the JavaScript side, however you can have as many Java implementors
of the interface that you want.

I am marking this as FixedNotReleased since we are putting JsInterop out for trial
usage with GWT 2.7

Reported by dankurka@google.com on 2014-10-08 06:50:38

dankurka commented 9 years ago

Reported by dankurka@google.com on 2014-10-08 06:50:50

dankurka commented 9 years ago
JSOs are backed by objects with potentially no runtime type or prototype, and so all
methods have to be effectively non-polymorphic. This is why there can't be two implementors
of an interface.

Consider how you'd write the Javascript for this:

interface Foo {
   void m();
}

class FooImpl extends JavaScriptObject implements Foo {
  native void m() /*-{ this.x(); }-*/;
}

class FooImpl2 extends JavaScriptObject implements Foo {
  native void m() /*-{ this.y(); }-*/;
}

Foo f = ...
f.m();

Now, what JS is to be generated for the call to f.m()? Should it invokve f.x() or f.y()?
By inspecting only the 'f' object, how would the compiler generate a conditional to
invoke one or the other?

The new JsInterop solves this problem (although not all edge cases) because the assumption
is made that if a method m() exists on the interface, it must exist on the underlying
object. The compiler always writes out f.m().

Reported by cromwellian@google.com on 2014-10-08 08:37:23

dankurka commented 9 years ago
Bulk edit: Released since GWT 2.7.0 RC1

Reported by dankurka@google.com on 2014-10-30 10:42:17