mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +01:00
Fixed Procedure Argument Escaping (#2626)
* Refactored procedure decompose to build XML node by node. Fixed argument name escaping. * Fixed review comments.
This commit is contained in:
committed by
Neil Fraser
parent
0af94c4880
commit
b7e6d3704a
@@ -164,26 +164,44 @@ Blockly.Blocks['procedures_defnoreturn'] = {
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
decompose: function(workspace) {
|
||||
var xml = Blockly.Xml.textToDom(
|
||||
'<block type="procedures_mutatorcontainer">' +
|
||||
' <statement name="STACK"></statement>' +
|
||||
'</block>');
|
||||
var node = xml.getElementsByTagName('statement')[0];
|
||||
/*
|
||||
* Creates the following XML:
|
||||
* <block type="procedures_mutatorcontainer">
|
||||
* <statement name="STACK">
|
||||
* <block type="procedures_mutatorarg">
|
||||
* <field name="NAME">arg1_name</field>
|
||||
* <next>etc...</next>
|
||||
* </block>
|
||||
* </statement>
|
||||
* </block>
|
||||
*/
|
||||
|
||||
var containerBlockNode = Blockly.utils.xml.createElement('block');
|
||||
containerBlockNode.setAttribute('type', 'procedures_mutatorcontainer');
|
||||
var statementNode = Blockly.utils.xml.createElement('statement');
|
||||
statementNode.setAttribute('name', 'STACK');
|
||||
containerBlockNode.appendChild(statementNode);
|
||||
|
||||
var node = statementNode;
|
||||
for (var i = 0; i < this.arguments_.length; i++) {
|
||||
node.appendChild(Blockly.Xml.textToDom(
|
||||
'<block type="procedures_mutatorarg">' +
|
||||
' <field name="NAME">' + this.arguments_[i] + '</field>' +
|
||||
' <next></next>' +
|
||||
'</block>'
|
||||
));
|
||||
node = node.getElementsByTagName('next')[0];
|
||||
var argBlockNode = Blockly.utils.xml.createElement('block');
|
||||
argBlockNode.setAttribute('type', 'procedures_mutatorarg');
|
||||
var fieldNode = Blockly.utils.xml.createElement('field');
|
||||
fieldNode.setAttribute('name', 'NAME');
|
||||
var argumentName = Blockly.utils.xml.createTextNode(this.arguments_[i]);
|
||||
fieldNode.appendChild(argumentName);
|
||||
argBlockNode.appendChild(fieldNode);
|
||||
var nextNode = Blockly.utils.xml.createElement('next');
|
||||
argBlockNode.appendChild(nextNode);
|
||||
|
||||
node.appendChild(argBlockNode);
|
||||
node = nextNode;
|
||||
}
|
||||
|
||||
var containerBlock = Blockly.Xml.domToBlock(xml, workspace);
|
||||
var containerBlock = Blockly.Xml.domToBlock(containerBlockNode, workspace);
|
||||
|
||||
if (this.type == 'procedures_defreturn') {
|
||||
containerBlock.setFieldValue(
|
||||
this.hasStatements_ ? 'TRUE' : 'FALSE', 'STATEMENTS');
|
||||
containerBlock.setFieldValue(this.hasStatements_, 'STATEMENTS');
|
||||
} else {
|
||||
containerBlock.removeInput('STATEMENT_INPUT');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user