JsFunction length is zero

137 views
Skip to first unread message

Vassilis Virvilis

unread,
Nov 26, 2019, 8:49:15 AM11/26/19
to google-we...@googlegroups.com
Hi,

Looks like that some javascript libraries are checking on the argument length of the callbacks that are passed to them.

So for example D3 bisector can take a function with one or two arguments. If it is one then it is an accessor if it is two then it is a comparator.

I searched on github issues. Should I report it?

The following snippet demonstrates the problem. The Function.length should be 1 and not 0.

    @JsFunction
    public static interface SomeFunction {
        public double call(double x);
    }

    /**      * This is the entry point method.      */     @Override     public void onModuleLoad() {         final SomeFunction y = new SomeFunction() {             @Override             public double call(double x) {                 return 2 * x;             }         };         DomGlobal.console.log(y);         return;    }
image.png

Jens

unread,
Nov 27, 2019, 6:57:42 AM11/27/19
to GWT Users
You can see here how GWT compiler creates lambdas: https://github.com/gwtproject/gwt/blob/master/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Runtime.java#L162

In case you also want to try to fix the issue ;-)

-- J.

Vassilis Virvilis

unread,
Nov 27, 2019, 8:23:34 AM11/27/19
to google-we...@googlegroups.com
Hi Jens,

Thanks for the reply and the pointer. Your answers are spot on as always but in this case I had managed to find the specific code fragment by my self.

I was thinking a patch could look like the accepted answer in this Stack Overflow question: https://stackoverflow.com/questions/7316688/how-to-programmatically-set-the-length-of-a-function

assuming arguments and arguments.length carry the necessary information.

Do you think a patch like that has any chance to be accepted? or this is not considered to be an issue?

Thanks



--
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/e6e9e9ea-e921-41c7-9283-9734902e3d41%40googlegroups.com.


--
Vassilis Virvilis

Jens

unread,
Nov 28, 2019, 2:37:57 AM11/28/19
to GWT Users

Do you think a patch like that has any chance to be accepted? or this is not considered to be an issue?

Seems like a valid behavior for JS libraries to check argument count, so I guess it should be accepted. Goktug or Roberto should probably review it.

-- J.

Vassilis Virvilis

unread,
Nov 28, 2019, 8:13:22 AM11/28/19
to google-we...@googlegroups.com
ok then.


I will try to come with a patch in the next few days.

Thanks

  Vassilis

--
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.

Vassilis Virvilis

unread,
Dec 2, 2019, 6:38:55 AM12/2/19
to google-we...@googlegroups.com

Unfortunately GWT does not accept pull request on GitHub.

--
Vassilis Virvilis

Vassilis Virvilis

unread,
Jan 10, 2020, 9:21:56 AM1/10/20
to google-we...@googlegroups.com
I actually added a pull/review request on gerrit at 3 Dec 2019


but no signs of life so far. It certainly takes a lot of time to review...

    Vassilis

--
Vassilis Virvilis

Vassilis Virvilis

unread,
Jan 14, 2020, 3:29:41 AM1/14/20
to google-we...@googlegroups.com
Hi Jens,

Sorry for bothering you again but I am new to this.

I just got my first positive review and I noticed the 'Add Reviewer/ Add CC' buttons and I am wondering if I should manually enter the names you suggested previously in the thread?

Thanks
--
Vassilis Virvilis

Jens

unread,
Jan 14, 2020, 4:11:20 AM1/14/20
to GWT Users

I just got my first positive review and I noticed the 'Add Reviewer/ Add CC' buttons and I am wondering if I should manually enter the names you suggested previously in the thread?

Sure, you would use the Add Reviewer button. The person you add will then receive an email notification (if they haven't deactivated it).


-- J.

Vassilis Virvilis

unread,
Jan 14, 2020, 4:26:13 AM1/14/20
to google-we...@googlegroups.com
I just did it.

Thanks for the help and the patience.

--
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.


--
Vassilis Virvilis
Reply all
Reply to author
Forward
0 new messages