cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Grieve <>
Subject Type checking in Cordova JS plugins
Date Thu, 15 Nov 2012 20:15:14 GMT
There's very little consistency when it comes to checking params in plugin

checks every args. logs errors and returns without calling errback, does
not allow missing errCB.

Allows missing successCB and errCB. Sanity checks URL has a colon in it.

doesn't check types at all

Throws TypeError if missing successCB, allows missing errCB

Logs and returns if callbacks are of wrong type. success required, error

So, the things to agree upon are:

1. Should we check types or not?
2. Success / error callbacks : optional or not?
3. When type errors happen, log & return, call errBack, or throw TypeError?

For some extra inspiration, I played around with what it would look like to
at least factor out type checking code. Have a look at the
Also, here's<>what
it looks like being used in globalization.js.

Now, here's my thoughts for the three questions
1. Should we check types or not?
  - I think it is useful since incorrect args end up in exec() calls and
are therefore harder to debug when they are wrong.
  - Perhaps instead of checking types, we add a helper for coercing types?
This may only apply to strings / numbers though...
  - I also kind of like the idea of being able to turn off type checking
for release mode. Having a common function to do the type checking would
allow us to turn checking on/off for performance.

2. Success / error callbacks : optional or not?
  - I'm not positive we need to make these all consistent
  - If anything, I'd say we'd want them to be optional.

3. When type errors happen, log & return, call errBack, or throw TypeError?
  - TypeError is my preference here. This matches what browser APIs do when
it doesn't like params.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message