On 2012/01/07 17:13:19, Steffen Schäfer wrote:
I thought again about shared code using typed arrays.

We'll have the following:
- an interface shared.TypedArray
- an implementation client.TypedArray extends JSO implements
   shared.TypedArray
- the client.TypedArray implements the methods defined in
   shared.TypedArray using JSNI

That's it. I'd probably call the client class JsoTypedArray so it's
harder to mix it up with shared.TypedArray (particularly when you use
facilities provided by your IDE to automatically insert the 'import'
clauses). Also, giving the client class a slightly uglier name is an
incentive to rather code against the interface: the implementation class
is a detail.

Now let's think about shared code that operates on shared.TypedArray
and that code is called on the client.
How does the GWT compiler know to call the native method implemented
in client.TypedArray?

Because you'll use the "client" factory to instantiate the actual
implementations of the interfaces.

I thought the whole JSO stuff is based on calling the native methods
implemented in the JSO type we have a reference for (we get what we
expect). As the compiler doesn't know that it's a JSO in the shared
code, I think that won't work.

Please correct me if I'm wrong.

Don't worry, it'll work (have a look at the Wave code); this is exactly
the same as coding against java.util.List and java.util.Set; JSOs don't
change anything.
Additionally, in this case, the JSO implementations will be the only one
used on the client, so the compiler will type-tighten every reference to
TypedArray in the code and replace it with JsoTypedArray,  then tighten
the method calls from the polymorphic TypedArray#foo() to the
monomorphic (final) JsoTypedArray#foo(), which will later allow it to,
possibly, inline the methods (and it'll also prune the TypedArray
interface, because it won't be needed anymore after the type-tightening
and method-tightening optimizations).

http://gwt-code-reviews.appspot.com/1621803/

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to