Improve errors when validating JSON block definitions. (#1086)

goog.asserts to not run from blockly_compressed.js. User data validation should always run.
This commit is contained in:
Andrew n marshall
2017-05-05 11:14:54 -07:00
committed by GitHub
parent 55096aeb16
commit 8c46d7c798

View File

@@ -1067,10 +1067,14 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
for (var i = 0; i < tokens.length; i++) {
var token = tokens[i];
if (typeof token == 'number') {
goog.asserts.assert(token > 0 && token <= args.length,
'Message index %%s out of range.', token);
goog.asserts.assert(!indexDup[token],
'Message index %%s duplicated.', token);
if (token <= 0 || token > args.length) {
throw new Error('Block \"' + this.type + '\": ' +
'Message index %' + token + ' out of range.');
}
if (indexDup[token]) {
throw new Error('Block \"' + this.type + '\": ' +
'Message index %' + token + ' duplicated.');
}
indexDup[token] = true;
indexCount++;
elements.push(args[token - 1]);
@@ -1081,8 +1085,10 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
}
}
}
goog.asserts.assert(indexCount == args.length,
'block "%s": Message does not reference all %s arg(s).', this.type, args.length);
if(indexCount != args.length) {
throw new Error('Block \"' + this.type + '\": ' +
'Message does not reference all ' + args.length + ' arg(s).');
}
// Add last dummy input if needed.
if (elements.length && (typeof elements[elements.length - 1] == 'string' ||
goog.string.startsWith(elements[elements.length - 1]['type'],