From 8c46d7c798bca92dd6c2fca496e64901667e081e Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Fri, 5 May 2017 11:14:54 -0700 Subject: [PATCH] Improve errors when validating JSON block definitions. (#1086) goog.asserts to not run from blockly_compressed.js. User data validation should always run. --- core/block.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/block.js b/core/block.js index fd18d965d..594e95e3c 100644 --- a/core/block.js +++ b/core/block.js @@ -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'],