- We design and build extraordinary applications for companies looking to make the next great idea a reality.
- learn more
GWT 1.5: Get Ready to Fix All of Your JSNI that Uses long
I've been humming along with GWT 1.5, reading the release notes and compiling from trunk. Today I had a nasty little surprise. All of my JSNI code that used long as either a parameter or return value stopped working. So, something like the following...
public native long method(long param) /*-{
// do something useful
}-*/;
...would throw a nice little exception in hosted mode:
Return value of type 'long' is an opaque, non-numeric value in JS code Parameter 'value': 'long' is an opaque, non-numeric value in JS code
The reason for this is that internally, GWT stores longs as an array of
two JavaScript numbers (doubles, essentially) -- the high bits and the
low bits -- to retain precision. When you add those two quantities
together to convert to a single number, you may lose precision. The
code for dealing with long's is in com.google.gwt.lang.LongLib.
The
change is that rather than converting long's back and forth with
possible loss of precision, GWT 1.5 now sends and expects that
array of two numbers. I had some longs in JSNI flying around to deal
with some squirrelly browser date logic and had to retool to work
without JSNI. A discussion of the issue can be found here.
Anyhow,
make sure to go through all of your library and other code to search
for use of longs in JSNI, otherwise this may come and bite you. One naive workaround is to pass in and return doubles. Do make sure to write tests so that date logic, for example, doesn't break (you do know about the 2038 Problem, evil cousin of the Y2K problem, don't you?).
Technorati Tags: ajax, gwt, jsni, long, java
Topics: Ajax Frameworks, GWT, Java, Javascript
Leave a comment
About Pathfinder
Recent
- Rails ThreatDown!
- Automated Deployments Rock
- Bandwidth profiling Flex projects and more with Charles
- iPhone SDK: UIViewController Testing & TDD
- Icons are evil; so are menus - unless you do them right
- The Truth About Designing For Security
- GWT, Gadgets and OpenSocial, Part 2
- Has Many has_many: A Refactoring Story
- The Hidden Power of Canvas
- Review of fixture_replacement2 plugin
Archives
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006

