mirror of
https://github.com/google/blockly.git
synced 2026-01-10 10:27:08 +01:00
Fixing issue 1760: nulls in JSON array for block definitions. (#1768)
JSON array with null or undefined value will now skip the offending item, and proceed to load following items. Added tests for null and undefined array elements. * Testing handling null and undefined id in block definition. * Adding test utility function to capture console warnings. * Test assumption that creating a simple block will not cause a warning. This is assumed when later checking warning counts.
This commit is contained in:
committed by
GitHub
parent
e9d8e00a55
commit
ecc41372d7
@@ -392,21 +392,28 @@ Blockly.jsonInitFactory_ = function(jsonDef) {
|
||||
* @param {!Array.<!Object>} jsonArray An array of JSON block definitions.
|
||||
*/
|
||||
Blockly.defineBlocksWithJsonArray = function(jsonArray) {
|
||||
for (var i = 0, elem; elem = jsonArray[i]; i++) {
|
||||
var typename = elem.type;
|
||||
if (typename == null || typename === '') {
|
||||
for (var i = 0; i < jsonArray.length; i++) {
|
||||
var elem = jsonArray[i];
|
||||
if (!elem) {
|
||||
console.warn(
|
||||
'Block definition #' + i +
|
||||
' in JSON array is missing a type attribute. Skipping.');
|
||||
'Block definition #' + i + ' in JSON array is ' + elem + '. ' +
|
||||
'Skipping.');
|
||||
} else {
|
||||
if (Blockly.Blocks[typename]) {
|
||||
var typename = elem.type;
|
||||
if (typename == null || typename === '') {
|
||||
console.warn(
|
||||
'Block definition #' + i + ' in JSON array' +
|
||||
' overwrites prior definition of "' + typename + '".');
|
||||
'Block definition #' + i +
|
||||
' in JSON array is missing a type attribute. Skipping.');
|
||||
} else {
|
||||
if (Blockly.Blocks[typename]) {
|
||||
console.warn(
|
||||
'Block definition #' + i + ' in JSON array' +
|
||||
' overwrites prior definition of "' + typename + '".');
|
||||
}
|
||||
Blockly.Blocks[typename] = {
|
||||
init: Blockly.jsonInitFactory_(elem)
|
||||
};
|
||||
}
|
||||
Blockly.Blocks[typename] = {
|
||||
init: Blockly.jsonInitFactory_(elem)
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user