Avoid crashing when a procedure input has an empty string (#2182)

Fixes #1958

This will drop the input when it's in the empty string state. This
causes the block to remove the input and re-add it when the text
is reverted, but prevents the breakage. A followup fix should leave
the input alone instead of removing it, but this works for now.
This commit is contained in:
RoboErikG
2018-12-19 10:37:40 -08:00
committed by GitHub
parent b5146036e1
commit a14ff64cf3

View File

@@ -159,7 +159,11 @@ Blockly.Blocks['procedures_defnoreturn'] = {
this.arguments_.push(varName);
var variable = Blockly.Variables.getOrCreateVariablePackage(
this.workspace, varId, varName, '');
this.argumentVarModels_.push(variable);
if (variable != null) {
this.argumentVarModels_.push(variable);
} else {
console.log('Failed to create a variable with name ' + varName + ', ignoring.');
}
}
}
this.updateParams_();
@@ -216,7 +220,12 @@ Blockly.Blocks['procedures_defnoreturn'] = {
var varName = paramBlock.getFieldValue('NAME');
this.arguments_.push(varName);
var variable = this.workspace.getVariable(varName, '');
this.argumentVarModels_.push(variable);
if (variable != null) {
this.argumentVarModels_.push(variable);
} else {
console.log('Failed to get variable named ' + varName + ', ignoring.');
}
this.paramIds_.push(paramBlock.id);
paramBlock = paramBlock.nextConnection &&
paramBlock.nextConnection.targetBlock();