Throw errors instead of strings. (#1974)

Blocks and generators
This commit is contained in:
Neil Fraser
2018-07-16 16:33:44 -07:00
committed by GitHub
parent 99ebefa1bf
commit c8bfc888c8
23 changed files with 55 additions and 55 deletions

View File

@@ -255,7 +255,7 @@ Blockly.PHP['lists_getIndex'] = function(block) {
}
break;
}
throw 'Unhandled combination (lists_getIndex).';
throw Error('Unhandled combination (lists_getIndex).');
};
Blockly.PHP['lists_setIndex'] = function(block) {
@@ -355,7 +355,7 @@ Blockly.PHP['lists_setIndex'] = function(block) {
}
break;
}
throw 'Unhandled combination (lists_setIndex).';
throw Error('Unhandled combination (lists_setIndex).');
};
Blockly.PHP['lists_getSublist'] = function(block) {
@@ -383,7 +383,7 @@ Blockly.PHP['lists_getSublist'] = function(block) {
var at1 = '0';
break;
default:
throw 'Unhandled option (lists_getSublist).';
throw Error('Unhandled option (lists_getSublist).');
}
switch (where2) {
case 'FROM_START':
@@ -416,7 +416,7 @@ Blockly.PHP['lists_getSublist'] = function(block) {
}
break;
default:
throw 'Unhandled option (lists_getSublist).';
throw Error('Unhandled option (lists_getSublist).');
}
code = 'array_slice(' + list + ', ' + at1 + ', ' + length + ')';
} else {
@@ -497,7 +497,7 @@ Blockly.PHP['lists_split'] = function(block) {
}
var functionName = 'implode';
} else {
throw 'Unknown mode: ' + mode;
throw Error('Unknown mode: ' + mode);
}
var code = functionName + '(' + value_delim + ', ' + value_input + ')';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];

View File

@@ -160,5 +160,5 @@ Blockly.PHP['controls_flow_statements'] = function(block) {
case 'CONTINUE':
return 'continue;\n';
}
throw 'Unknown flow statement.';
throw Error('Unknown flow statement.');
};

View File

@@ -32,7 +32,7 @@ goog.require('Blockly.PHP');
Blockly.PHP['math_number'] = function(block) {
// Numeric value.
var code = parseFloat(block.getFieldValue('NUM'));
var order = code >= 0 ? Blockly.PHP.ORDER_ATOMIC :
var order = code >= 0 ? Blockly.PHP.ORDER_ATOMIC :
Blockly.PHP.ORDER_UNARY_NEGATION;
if (code == Infinity) {
code = 'INF';
@@ -139,7 +139,7 @@ Blockly.PHP['math_single'] = function(block) {
code = 'atan(' + arg + ') / pi() * 180';
break;
default:
throw 'Unknown math operator: ' + operator;
throw Error('Unknown math operator: ' + operator);
}
return [code, Blockly.PHP.ORDER_DIVISION];
};
@@ -321,7 +321,7 @@ Blockly.PHP['math_on_list'] = function(block) {
code = functionName + '(' + list + ')';
break;
default:
throw 'Unknown operator: ' + func;
throw Error('Unknown operator: ' + func);
}
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
};

View File

@@ -152,7 +152,7 @@ Blockly.PHP['text_charAt'] = function(block) {
code = functionName + '(' + text + ')';
return [code, Blockly.PHP.ORDER_FUNCTION_CALL];
}
throw 'Unhandled option (text_charAt).';
throw Error('Unhandled option (text_charAt).');
};
Blockly.PHP['text_getSubstring'] = function(block) {