0

I read a document and it points out that WebIDL defines IDL unsigned short mapped to JS Number.

The range of unsigned short is from 0 to 65535. JS Number can be -9007199254740992 to 9007199254740992.

This really confuses me since the big gape between these two definition. Can anyone explain this?

Thanks

Sam
  • 4,521
  • 13
  • 46
  • 81
  • Could you link the document you actually read? – Loïc Faure-Lacroix Feb 19 '14 at 14:38
  • yes, please refer to the following link. http://mcc.id.au/2013/lca-webidl/?full#What – Sam Feb 20 '14 at 16:15
  • I'm pretty sure there was a presentation video with it. It doesn't exactly explains everything. My guess is that if you defined an IDL with unsigned short, the point of the IDL is to do the translation from JS Number to Unsigned short in your native code. Internally JS Number are much more complicated than unsigned short. But it doesn't prevent js numbers to be mapped to native types using the IDL... which is the point of the IDL. – Loïc Faure-Lacroix Feb 20 '14 at 16:44

1 Answers1

1

As mentioned by Loïc Faure-Lacroix, JS Numbers are much more complicated than unsigned short.

JS has a few types:

Undefined – undefined
Boolean – false, true
Number – 0, -2.5, Infinity, NaN
String – "", "hello"
Object – { }, { "key": "value" }, [1, 2, 3], function() { }, /^regexp?$/

The point being here, is that when you define in your WebIDL a number, you need take into consideration what you'll need for precision and accuracy. So, if you're expecting to storage something bigger then an unsigned short, declare something like an unsigned int, that holds up to 4,294,967,295.

The idea here is to not rely on JavaScript types, but on the WebIDL (which might be translated to Python, or C, or C++ or something).

Hope I was able to clarify your question. If not, I recommend that you poke @heycam at irc.mozilla.org, he knows it all :).

msaad
  • 599
  • 2
  • 11