Re: [gwt-contrib] Fwd: jsinterop: @JsFunction .length always 0

2017-06-28 Thread Vassilis Virvilis
Yep I have done it like this exactly but this creates a JSNI dependency. My
reports were assuming that JSNI is a soon to be deprecated thing or at
least further investment on it is should be avoided.

However, thanks for the development insight.


On Wed, Jun 28, 2017 at 7:56 PM, 'Roberto Lublinerman' via GWT Contributors
 wrote:

> Not likely to be implemented in the foreseeable future; your best solution
> is to create two JavaScript methods (or JSNI)
>
> function asAccessor(f) {
>   return function (a) { return f(a); };
> }
>
> function asComparator(f) {
>   return function (a, b) { return f(a, b); };
> }
>
> It would be possible to implement @JsFunction lambdas without a backing
> class and that would result in the function having the same number of
> parameters as the lambda. But as I said this is unlikely to be implemented
> in the foreseeable future as it would require a new Java AST node and thus
> changes throughout the code base.
>
> On Tue, Jun 27, 2017 at 2:28 PM, Vassilis Virvilis 
> wrote:
>
>> Do you want me to report it as issue? If so where?
>>
>> Is it possible for @JsFunction magic to implement it some day? or it is
>> impossible to be implemented with the current design?
>>
>> Thanks again for all the answers so far.
>>
>> Vassilis
>>
>> On Tue, Jun 27, 2017 at 7:40 PM, 'Roberto Lublinerman' via GWT
>> Contributors  wrote:
>>
>>> You can call it a missing feature. Clearly not a bug, not everything
>>> that can be done in JS is available from Java with interop. For these
>>> situations you probably want to have some JS stubs.
>>>
>>> On Tue, Jun 27, 2017 at 1:09 AM, Vassilis Virvilis 
>>> wrote:
>>>
 Ok guys this is the last one - I promise.

 Originally posted in gwt-users.

 Does this count as a bug or at least as a missing feature?

 Thanks

 -- Forwarded message --
 From: Vassilis Virvilis 
 Date: Mon, Mar 6, 2017 at 4:08 PM
 Subject: jsinterop: @JsFunction .length always 0
 To: google-web-tool...@googlegroups.com


 Hi,

 in D3 the bisect function takes a function that can be a comparator or
 an accessor.

 D3 internall figures it out by counting provided function arguments
 length via f.length https://developer.mozilla.org/
 en/docs/Web/JavaScript/Reference/Global_Objects/Function/length

 Trying to pass a java @JsFunction fails because @JsFunction objects are
 lambda with zero arguments that wrap samMethod.apply() call

 Any ideas? Should I file this as a bug?


 --
 Vassilis Virvilis



 --
 Vassilis Virvilis

 --
 You received this message because you are subscribed to the Google
 Groups "GWT Contributors" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to google-web-toolkit-contributor
 s+unsubscr...@googlegroups.com.
 To view this discussion on the web visit https://groups.google.com/d/ms
 gid/google-web-toolkit-contributors/CAKbOjEx1_jOohikJ7nBAfps
 E%3DJHtnD6M31PibMzjvcjLn7G1fw%40mail.gmail.com
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "GWT Contributors" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to google-web-toolkit-contributors+unsubscr...@googlegroups.com
>>> .
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/google-web-toolkit-contributors/CAC7T7g%3D_JcBzZaNnjBosA
>>> mcQ_Bm8Bn9r-_7LfFi%3DDu5r%2BO1h1A%40mail.gmail.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Vassilis Virvilis
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "GWT Contributors" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/google-web-toolkit-contributors/CAKbOjEzKqjBGngrz%3DNES1
>> bEe24ejg48mHzBw3L9fLP3JC11_%2BA%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "GWT Contributors" group.
> To unsubscribe from this gro

Re: [gwt-contrib] Fwd: jsinterop: @JsFunction .length always 0

2017-06-28 Thread Vassilis Virvilis
@thomas

all valid points and interesting links. Thanks for the insight.

To my defense however I want to state again that I have not devised this
API.

It's the official API of D3

   - v3
   https://github.com/d3/d3-3.x-api-reference/blob/master/Arrays.md#d3_bisector
   - v4 https://github.com/d3/d3-array/blob/master/README.md#bisector


so it is not possible to change the API. If I take a step back (not
realistic) and say that I won't use D3 at all because it has such a bad API
(not true. Generally I enjoy the D3 very much.) I am sure I will hit
similar snags in other js libraries.

So... better the devil you know

 Vassilis


On Wed, Jun 28, 2017 at 4:12 PM, Thomas Broyer  wrote:

>
>
> On Wednesday, June 28, 2017 at 2:21:16 PM UTC+2, Vassilis Virvilis wrote:
>>
>> I am not following the implementation details and I cannot judge on the
>> compromises front.
>>
>> But from a user standpoint this should be implemented because a
>> @JsFunction should generate a js function()  and a js function() happens to
>> have a length member by specification (see https://developer.mozilla.org/
>> en/docs/Web/JavaScript/Reference/Global_Objects/Function/length )
>>
>> Otherwise @JsFunction is not a js function() but something callable
>> instead.
>>
>
> GWT generates a function, but a function with an empty formal parameter
> list (and as a result a length of 0), because it simply uses 'arguments':
> https://github.com/gwtproject/gwt/blob/2.8.1/
> dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/
> gwt/lang/Runtime.java#L158-L169
>
>
>> Given the dynamic number of javascript I expect that these kind of checks
>> to be common enough to warrant the effort.
>>
>
> One could argue the reverse: due to the dynamic nature of JS, 'length' of
> a function isn't reliable, and you'd be better off using distinct APIs
> rather than driving behavior by inferring things from inputs, or more
> precisely be explicit with your intent.
> It easily fails you, as soon as you wrap a function to bind, curry,
> memoize it, whatever, using a generic factory (one that uses 'arguments'
> along with Function.prototype.apply or Function.prototype.call; one that
> specifically doesn't use Function.prototype.bind).
> Have a look at the Function.prototype.bind polyfill from the MDN for
> example: https://developer.mozilla.org/en-US/docs/Web/
> JavaScript/Reference/Global_Objects/Function/bind#Polyfill
> Any code targeting IE8 or older (that doesn't necessarily mean new code)
> would need this polyfill, and the returned function (fBound) has a length
> of 0, irrespective of the length of the function to bind.
> There's a polyfill for Function.prototype.bind that returns a function
> with the correct 'length', but it uses new Function() with a string body:
> https://github.com/Raynos/function-bind/blob/
> 83e639ff74e6cd6921285bccec22c1bcf72311bd/implementation.js#L38 so it'd
> break most CSP. While IE8 doesn't support CSP (so it's OK for this
> particular polyfill), that however means you cannot use such a trick for
> other things you'd like to do with a function (such as memoizing it: for
> example, https://github.com/caiogondim/fast-memoize.js returns a function
> with length 0 too).
>
> --
> You received this message because you are subscribed to the Google Groups
> "GWT Contributors" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/google-web-toolkit-contributors/e12e8c02-c6f0-
> 4818-aaee-fb564935e8ec%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Vassilis Virvilis

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAKbOjEwwD-hDNBt8QEE2h0k74yxpFWdCsX5J5Lh3%3DsHeGptDcw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gwt-contrib] Fwd: jsinterop: @JsFunction .length always 0

2017-06-28 Thread 'Roberto Lublinerman' via GWT Contributors
Not likely to be implemented in the foreseeable future; your best solution
is to create two JavaScript methods (or JSNI)

function asAccessor(f) {
  return function (a) { return f(a); };
}

function asComparator(f) {
  return function (a, b) { return f(a, b); };
}

It would be possible to implement @JsFunction lambdas without a backing
class and that would result in the function having the same number of
parameters as the lambda. But as I said this is unlikely to be implemented
in the foreseeable future as it would require a new Java AST node and thus
changes throughout the code base.

On Tue, Jun 27, 2017 at 2:28 PM, Vassilis Virvilis 
wrote:

> Do you want me to report it as issue? If so where?
>
> Is it possible for @JsFunction magic to implement it some day? or it is
> impossible to be implemented with the current design?
>
> Thanks again for all the answers so far.
>
> Vassilis
>
> On Tue, Jun 27, 2017 at 7:40 PM, 'Roberto Lublinerman' via GWT
> Contributors  wrote:
>
>> You can call it a missing feature. Clearly not a bug, not everything that
>> can be done in JS is available from Java with interop. For these situations
>> you probably want to have some JS stubs.
>>
>> On Tue, Jun 27, 2017 at 1:09 AM, Vassilis Virvilis 
>> wrote:
>>
>>> Ok guys this is the last one - I promise.
>>>
>>> Originally posted in gwt-users.
>>>
>>> Does this count as a bug or at least as a missing feature?
>>>
>>> Thanks
>>>
>>> -- Forwarded message --
>>> From: Vassilis Virvilis 
>>> Date: Mon, Mar 6, 2017 at 4:08 PM
>>> Subject: jsinterop: @JsFunction .length always 0
>>> To: google-web-tool...@googlegroups.com
>>>
>>>
>>> Hi,
>>>
>>> in D3 the bisect function takes a function that can be a comparator or
>>> an accessor.
>>>
>>> D3 internall figures it out by counting provided function arguments
>>> length via f.length https://developer.mozilla.org/
>>> en/docs/Web/JavaScript/Reference/Global_Objects/Function/length
>>>
>>> Trying to pass a java @JsFunction fails because @JsFunction objects are
>>> lambda with zero arguments that wrap samMethod.apply() call
>>>
>>> Any ideas? Should I file this as a bug?
>>>
>>>
>>> --
>>> Vassilis Virvilis
>>>
>>>
>>>
>>> --
>>> Vassilis Virvilis
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "GWT Contributors" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to google-web-toolkit-contributors+unsubscr...@googlegroups.com
>>> .
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/google-web-toolkit-contributors/CAKbOjEx1_jOohikJ7nBAfps
>>> E%3DJHtnD6M31PibMzjvcjLn7G1fw%40mail.gmail.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "GWT Contributors" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/google-web-toolkit-contributors/CAC7T7g%3D_JcBzZaNnjBosA
>> mcQ_Bm8Bn9r-_7LfFi%3DDu5r%2BO1h1A%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Vassilis Virvilis
>
> --
> You received this message because you are subscribed to the Google Groups
> "GWT Contributors" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/google-web-toolkit-contributors/CAKbOjEzKqjBGngrz%3DNES1
> bEe24ejg48mHzBw3L9fLP3JC11_%2BA%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAC7T7gnJC5tBdXqwr1B4wYTz4UNLppqxpbp4ydZUe7xx8qYCrg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gwt-contrib] Fwd: jsinterop: @JsFunction .length always 0

2017-06-28 Thread Thomas Broyer


On Wednesday, June 28, 2017 at 2:21:16 PM UTC+2, Vassilis Virvilis wrote:
>
> I am not following the implementation details and I cannot judge on the 
> compromises front.
>
> But from a user standpoint this should be implemented because a 
> @JsFunction should generate a js function()  and a js function() happens to 
> have a length member by specification (see 
> https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Function/length
>  
> )
>
> Otherwise @JsFunction is not a js function() but something callable 
> instead.
>

GWT generates a function, but a function with an empty formal parameter 
list (and as a result a length of 0), because it simply uses 
'arguments': 
https://github.com/gwtproject/gwt/blob/2.8.1/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Runtime.java#L158-L169
 

> Given the dynamic number of javascript I expect that these kind of checks 
> to be common enough to warrant the effort.
>

One could argue the reverse: due to the dynamic nature of JS, 'length' of a 
function isn't reliable, and you'd be better off using distinct APIs rather 
than driving behavior by inferring things from inputs, or more precisely be 
explicit with your intent.
It easily fails you, as soon as you wrap a function to bind, curry, memoize 
it, whatever, using a generic factory (one that uses 'arguments' along with 
Function.prototype.apply or Function.prototype.call; one that specifically 
doesn't use Function.prototype.bind).
Have a look at the Function.prototype.bind polyfill from the MDN for 
example: 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill
Any code targeting IE8 or older (that doesn't necessarily mean new code) 
would need this polyfill, and the returned function (fBound) has a length 
of 0, irrespective of the length of the function to bind.
There's a polyfill for Function.prototype.bind that returns a function with 
the correct 'length', but it uses new Function() with a string 
body: 
https://github.com/Raynos/function-bind/blob/83e639ff74e6cd6921285bccec22c1bcf72311bd/implementation.js#L38
 
so it'd break most CSP. While IE8 doesn't support CSP (so it's OK for this 
particular polyfill), that however means you cannot use such a trick for 
other things you'd like to do with a function (such as memoizing it: for 
example, https://github.com/caiogondim/fast-memoize.js returns a function 
with length 0 too).

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/e12e8c02-c6f0-4818-aaee-fb564935e8ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gwt-contrib] Fwd: jsinterop: @JsFunction .length always 0

2017-06-28 Thread Vassilis Virvilis
I am not following the implementation details and I cannot judge on the
compromises front.

But from a user standpoint this should be implemented because a @JsFunction
should generate a js function()  and a js function() happens to have a
length member by specification (see
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Function/length
)

Otherwise @JsFunction is not a js function() but something callable instead.

Given the dynamic number of javascript I expect that these kind of checks
to be common enough to warrant the effort.

Now if GWT generated script becomes 2x heavier and 4x slower you may forget
the feature. It still needs to be posted as an issue to host the discussion
though.

Vassilis



On Wed, Jun 28, 2017 at 10:51 AM, Thomas Broyer  wrote:

> I suppose makeLambdaFunction could be "inlined" (possibly into a static
> factory, one per class), with the 'lambda' then generated with the proper
> number of formal arguments to "initialize" its 'length' property? Would
> that hurt "optimizability" a lot?
> Or is that not worth it (too much of an edge case) and the static factory
> (of a wrapper function then) should rather be implemented with JSNI? (or
> the equivalent for j2cl)
>
>
> On Tuesday, June 27, 2017 at 6:41:03 PM UTC+2, Roberto Lublinerman wrote:
>>
>> You can call it a missing feature. Clearly not a bug, not everything that
>> can be done in JS is available from Java with interop. For these situations
>> you probably want to have some JS stubs.
>>
>> On Tue, Jun 27, 2017 at 1:09 AM, Vassilis Virvilis 
>> wrote:
>>
>>> Ok guys this is the last one - I promise.
>>>
>>> Originally posted in gwt-users.
>>>
>>> Does this count as a bug or at least as a missing feature?
>>>
>>> Thanks
>>>
>>> -- Forwarded message --
>>> From: Vassilis Virvilis 
>>> Date: Mon, Mar 6, 2017 at 4:08 PM
>>> Subject: jsinterop: @JsFunction .length always 0
>>> To: google-web-tool...@googlegroups.com
>>>
>>>
>>> Hi,
>>>
>>> in D3 the bisect function takes a function that can be a comparator or
>>> an accessor.
>>>
>>> D3 internall figures it out by counting provided function arguments
>>> length via f.length https://developer.mozilla.org/
>>> en/docs/Web/JavaScript/Reference/Global_Objects/Function/length
>>>
>>> Trying to pass a java @JsFunction fails because @JsFunction objects are
>>> lambda with zero arguments that wrap samMethod.apply() call
>>>
>>> Any ideas? Should I file this as a bug?
>>>
>>>
>>> --
>>> Vassilis Virvilis
>>>
>>>
>>>
>>> --
>>> Vassilis Virvilis
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "GWT Contributors" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to google-web-toolkit-contributors+unsubscr...@googlegroups.com
>>> .
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/google-web-toolkit-contributors/CAKbOjEx1_jOohikJ7nBAfps
>>> E%3DJHtnD6M31PibMzjvcjLn7G1fw%40mail.gmail.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "GWT Contributors" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/google-web-toolkit-contributors/a07991bc-7767-
> 46cb-80fd-655e1809f15b%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Vassilis Virvilis

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAKbOjEzdoAN2MadkgMQv%3DSk22nfJ8%2BHHKdDUwQGuRgf%3D4a%3DWUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gwt-contrib] Fwd: jsinterop: @JsFunction .length always 0

2017-06-28 Thread Thomas Broyer
I suppose makeLambdaFunction could be "inlined" (possibly into a static 
factory, one per class), with the 'lambda' then generated with the proper 
number of formal arguments to "initialize" its 'length' property? Would 
that hurt "optimizability" a lot?
Or is that not worth it (too much of an edge case) and the static factory 
(of a wrapper function then) should rather be implemented with JSNI? (or 
the equivalent for j2cl)

On Tuesday, June 27, 2017 at 6:41:03 PM UTC+2, Roberto Lublinerman wrote:
>
> You can call it a missing feature. Clearly not a bug, not everything that 
> can be done in JS is available from Java with interop. For these situations 
> you probably want to have some JS stubs.
>
> On Tue, Jun 27, 2017 at 1:09 AM, Vassilis Virvilis  
> wrote:
>
>> Ok guys this is the last one - I promise.
>>
>> Originally posted in gwt-users.
>>
>> Does this count as a bug or at least as a missing feature?
>>
>> Thanks
>>
>> -- Forwarded message --
>> From: Vassilis Virvilis 
>> Date: Mon, Mar 6, 2017 at 4:08 PM
>> Subject: jsinterop: @JsFunction .length always 0
>> To: google-web-tool...@googlegroups.com
>>
>>
>> Hi,
>>
>> in D3 the bisect function takes a function that can be a comparator or an 
>> accessor.
>>
>> D3 internall figures it out by counting provided function arguments 
>> length via f.length 
>> https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Function/length
>>
>> Trying to pass a java @JsFunction fails because @JsFunction objects are 
>> lambda with zero arguments that wrap samMethod.apply() call
>>
>> Any ideas? Should I file this as a bug?
>>
>>
>> -- 
>> Vassilis Virvilis
>>
>>
>>
>> -- 
>> Vassilis Virvilis
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "GWT Contributors" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAKbOjEx1_jOohikJ7nBAfpsE%3DJHtnD6M31PibMzjvcjLn7G1fw%40mail.gmail.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/a07991bc-7767-46cb-80fd-655e1809f15b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.