Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top