So the JSON Schema stuff worked out:
chromium.tabs.createTab = function(tab, callback) {
validate(arguments, arguments.callee.params);
sendRequest(CreateTab, tab, callback);
};
chromium.tabs.createTab.params = [
{
type: "object",
properties: {
windowId: chromium.types.optPInt,
url: chromium.types.optStr,
selected: chromium.types.optBool
},
additionalProperties: false
},
chromium.types.optFun
];
--http://codereview.chromium.org/66006/diff/1087/1101I'm really happy with how this came out because it means that all our APIs will get great error messages for free; it's not something that we'll have to think about (and therefore get wrong) on a case-by-case basis.
I tend to obsess about errors messages because they are basically the first-run experience for any library. No matter how well designed, people are going to typically call your API wrong the first time, especially in a loosely-typed language like JavaScript. What happens in that case? Does the API stare blankly back at them, leaving them to wonder if their code is even running? Or does it helpfully tell them what they did wrong?
Chromium APIs will give errors. Specifically, they will retort something like:
Invalid value for parameter 0. Property windowId: expected integer, got string.