Add more type validation to codec.js

Also fixed array validation to use
instanceof per Hans' request in
https://codereview.chromium.org/798163002/

R=hansmuller@chromium.org
BUG=

Review URL: https://codereview.chromium.org/803173003