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

@@ -243,7 +243,7 @@ Blockly.Dart['lists_getIndex'] = function(block) {
break;
}
}
throw 'Unhandled combination (lists_getIndex).';
throw Error('Unhandled combination (lists_getIndex).');
};
Blockly.Dart['lists_setIndex'] = function(block) {
@@ -323,7 +323,7 @@ Blockly.Dart['lists_setIndex'] = function(block) {
}
break;
}
throw 'Unhandled combination (lists_setIndex).';
throw Error('Unhandled combination (lists_setIndex).');
};
Blockly.Dart['lists_getSublist'] = function(block) {
@@ -348,7 +348,7 @@ Blockly.Dart['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':
@@ -363,7 +363,7 @@ Blockly.Dart['lists_getSublist'] = function(block) {
// There is no second index if LAST option is chosen.
break;
default:
throw 'Unhandled option (lists_getSublist).';
throw Error('Unhandled option (lists_getSublist).');
}
if (where2 == 'LAST') {
var code = list + '.sublist(' + at1 + ')';
@@ -445,7 +445,7 @@ Blockly.Dart['lists_split'] = function(block) {
}
var functionName = 'join';
} else {
throw 'Unknown mode: ' + mode;
throw Error('Unknown mode: ' + mode);
}
var code = input + '.' + functionName + '(' + delimiter + ')';
return [code, Blockly.Dart.ORDER_UNARY_POSTFIX];

View File

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

View File

@@ -160,7 +160,7 @@ Blockly.Dart['math_single'] = function(block) {
code = 'Math.atan(' + arg + ') / Math.PI * 180';
break;
default:
throw 'Unknown math operator: ' + operator;
throw Error('Unknown math operator: ' + operator);
}
return [code, Blockly.Dart.ORDER_MULTIPLICATIVE];
};
@@ -426,7 +426,7 @@ Blockly.Dart['math_on_list'] = function(block) {
code = functionName + '(' + list + ')';
break;
default:
throw 'Unknown operator: ' + func;
throw Error('Unknown operator: ' + func);
}
return [code, Blockly.Dart.ORDER_UNARY_POSTFIX];
};

View File

@@ -136,7 +136,7 @@ Blockly.Dart['text_charAt'] = function(block) {
code = functionName + '(' + text + ')';
return [code, Blockly.Dart.ORDER_UNARY_POSTFIX];
}
throw 'Unhandled option (text_charAt).';
throw Error('Unhandled option (text_charAt).');
};
Blockly.Dart['text_getSubstring'] = function(block) {
@@ -164,7 +164,7 @@ Blockly.Dart['text_getSubstring'] = function(block) {
var at1 = '0';
break;
default:
throw 'Unhandled option (text_getSubstring).';
throw Error('Unhandled option (text_getSubstring).');
}
switch (where2) {
case 'FROM_START':
@@ -178,7 +178,7 @@ Blockly.Dart['text_getSubstring'] = function(block) {
case 'LAST':
break;
default:
throw 'Unhandled option (text_getSubstring).';
throw Error('Unhandled option (text_getSubstring).');
}
if (where2 == 'LAST') {
var code = text + '.substring(' + at1 + ')';

View File

@@ -170,7 +170,7 @@ Blockly.JavaScript['lists_getIndex'] = function(block) {
}
break;
}
throw 'Unhandled combination (lists_getIndex).';
throw Error('Unhandled combination (lists_getIndex).');
};
Blockly.JavaScript['lists_setIndex'] = function(block) {
@@ -247,7 +247,7 @@ Blockly.JavaScript['lists_setIndex'] = function(block) {
}
break;
}
throw 'Unhandled combination (lists_setIndex).';
throw Error('Unhandled combination (lists_setIndex).');
};
/**
@@ -295,7 +295,7 @@ Blockly.JavaScript['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':
@@ -310,7 +310,7 @@ Blockly.JavaScript['lists_getSublist'] = function(block) {
var at2 = list + '.length';
break;
default:
throw 'Unhandled option (lists_getSublist).';
throw Error('Unhandled option (lists_getSublist).');
}
code = list + '.slice(' + at1 + ', ' + at2 + ')';
} else {
@@ -387,7 +387,7 @@ Blockly.JavaScript['lists_split'] = function(block) {
}
var functionName = 'join';
} else {
throw 'Unknown mode: ' + mode;
throw Error('Unknown mode: ' + mode);
}
var code = input + '.' + functionName + '(' + delimiter + ')';
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];

View File

@@ -171,5 +171,5 @@ Blockly.JavaScript['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.JavaScript');
Blockly.JavaScript['math_number'] = function(block) {
// Numeric value.
var code = parseFloat(block.getFieldValue('NUM'));
var order = code >= 0 ? Blockly.JavaScript.ORDER_ATOMIC :
var order = code >= 0 ? Blockly.JavaScript.ORDER_ATOMIC :
Blockly.JavaScript.ORDER_UNARY_NEGATION;
return [code, order];
};
@@ -140,7 +140,7 @@ Blockly.JavaScript['math_single'] = function(block) {
code = 'Math.atan(' + arg + ') / Math.PI * 180';
break;
default:
throw 'Unknown math operator: ' + operator;
throw Error('Unknown math operator: ' + operator);
}
return [code, Blockly.JavaScript.ORDER_DIVISION];
};
@@ -357,7 +357,7 @@ Blockly.JavaScript['math_on_list'] = function(block) {
code = functionName + '(' + list + ')';
break;
default:
throw 'Unknown operator: ' + func;
throw Error('Unknown operator: ' + func);
}
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
};

View File

@@ -137,7 +137,7 @@ Blockly.JavaScript['text_charAt'] = function(block) {
var code = functionName + '(' + text + ')';
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
}
throw 'Unhandled option (text_charAt).';
throw Error('Unhandled option (text_charAt).');
};
/**
@@ -186,7 +186,7 @@ Blockly.JavaScript['text_getSubstring'] = function(block) {
var at1 = '0';
break;
default:
throw 'Unhandled option (text_getSubstring).';
throw Error('Unhandled option (text_getSubstring).');
}
switch (where2) {
case 'FROM_START':
@@ -201,7 +201,7 @@ Blockly.JavaScript['text_getSubstring'] = function(block) {
var at2 = text + '.length';
break;
default:
throw 'Unhandled option (text_getSubstring).';
throw Error('Unhandled option (text_getSubstring).');
}
code = text + '.slice(' + at1 + ', ' + at2 + ')';
} else {

View File

@@ -358,7 +358,7 @@ Blockly.Lua['lists_split'] = function(block) {
}
functionName = 'table.concat';
} else {
throw 'Unknown mode: ' + mode;
throw Error('Unknown mode: ' + mode);
}
var code = functionName + '(' + input + ', ' + delimiter + ')';
return [code, Blockly.Lua.ORDER_HIGH];

View File

@@ -162,5 +162,5 @@ Blockly.Lua['controls_flow_statements'] = function(block) {
case 'CONTINUE':
return Blockly.Lua.CONTINUE_STATEMENT;
}
throw 'Unknown flow statement.';
throw Error('Unknown flow statement.');
};

View File

@@ -123,7 +123,7 @@ Blockly.Lua['math_single'] = function(block) {
code = 'math.deg(math.atan(' + arg + '))';
break;
default:
throw 'Unknown math operator: ' + operator;
throw Error('Unknown math operator: ' + operator);
}
return [code, Blockly.Lua.ORDER_HIGH];
};
@@ -383,7 +383,7 @@ Blockly.Lua['math_on_list'] = function(block) {
break;
default:
throw 'Unknown operator: ' + func;
throw Error('Unknown operator: ' + func);
}
return [functionName + '(' + list + ')', Blockly.Lua.ORDER_HIGH];
};

View File

@@ -149,7 +149,7 @@ Blockly.Lua['text_charAt'] = function(block) {
} else if (where == 'FROM_END') {
var start = '-' + at;
} else {
throw 'Unhandled option (text_charAt).';
throw Error('Unhandled option (text_charAt).');
}
}
if (start.match(/^-?\w*$/)) {
@@ -185,7 +185,7 @@ Blockly.Lua['text_getSubstring'] = function(block) {
} else if (where1 == 'FROM_END') {
var start = '-' + at1;
} else {
throw 'Unhandled option (text_getSubstring)';
throw Error('Unhandled option (text_getSubstring)');
}
// Get end index.
@@ -200,7 +200,7 @@ Blockly.Lua['text_getSubstring'] = function(block) {
} else if (where2 == 'FROM_END') {
var end = '-' + at2;
} else {
throw 'Unhandled option (text_getSubstring)';
throw Error('Unhandled option (text_getSubstring)');
}
var code = 'string.sub(' + text + ', ' + start + ', ' + end + ')';
return [code, Blockly.Lua.ORDER_HIGH];

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) {

View File

@@ -183,7 +183,7 @@ Blockly.Python['lists_getIndex'] = function(block) {
}
break;
}
throw 'Unhandled combination (lists_getIndex).';
throw Error('Unhandled combination (lists_getIndex).');
};
Blockly.Python['lists_setIndex'] = function(block) {
@@ -254,7 +254,7 @@ Blockly.Python['lists_setIndex'] = function(block) {
}
break;
}
throw 'Unhandled combination (lists_setIndex).';
throw Error('Unhandled combination (lists_setIndex).');
};
Blockly.Python['lists_getSublist'] = function(block) {
@@ -277,7 +277,7 @@ Blockly.Python['lists_getSublist'] = function(block) {
var at1 = '';
break;
default:
throw 'Unhandled option (lists_getSublist)';
throw Error('Unhandled option (lists_getSublist)');
}
switch (where2) {
case 'FROM_START':
@@ -298,7 +298,7 @@ Blockly.Python['lists_getSublist'] = function(block) {
var at2 = '';
break;
default:
throw 'Unhandled option (lists_getSublist)';
throw Error('Unhandled option (lists_getSublist)');
}
var code = list + '[' + at1 + ' : ' + at2 + ']';
return [code, Blockly.Python.ORDER_MEMBER];
@@ -349,7 +349,7 @@ Blockly.Python['lists_split'] = function(block) {
Blockly.Python.ORDER_MEMBER) || '\'\'';
var code = value_delim + '.join(' + value_input + ')';
} else {
throw 'Unknown mode: ' + mode;
throw Error('Unknown mode: ' + mode);
}
return [code, Blockly.Python.ORDER_FUNCTION_CALL];
};

View File

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

View File

@@ -147,7 +147,7 @@ Blockly.Python['math_single'] = function(block) {
code = 'math.atan(' + arg + ') / math.pi * 180';
break;
default:
throw 'Unknown math operator: ' + operator;
throw Error('Unknown math operator: ' + operator);
}
return [code, Blockly.Python.ORDER_MULTIPLICATIVE];
};
@@ -342,7 +342,7 @@ Blockly.Python['math_on_list'] = function(block) {
code = 'random.choice(' + list + ')';
break;
default:
throw 'Unknown operator: ' + func;
throw Error('Unknown operator: ' + func);
}
return [code, Blockly.Python.ORDER_FUNCTION_CALL];
};

View File

@@ -140,7 +140,7 @@ Blockly.Python['text_charAt'] = function(block) {
code = functionName + '(' + text + ')';
return [code, Blockly.Python.ORDER_FUNCTION_CALL];
}
throw 'Unhandled option (text_charAt).';
throw Error('Unhandled option (text_charAt).');
};
Blockly.Python['text_getSubstring'] = function(block) {
@@ -163,7 +163,7 @@ Blockly.Python['text_getSubstring'] = function(block) {
var at1 = '';
break;
default:
throw 'Unhandled option (text_getSubstring)';
throw Error('Unhandled option (text_getSubstring)');
}
switch (where2) {
case 'FROM_START':
@@ -184,7 +184,7 @@ Blockly.Python['text_getSubstring'] = function(block) {
var at2 = '';
break;
default:
throw 'Unhandled option (text_getSubstring)';
throw Error('Unhandled option (text_getSubstring)');
}
var code = text + '[' + at1 + ' : ' + at2 + ']';
return [code, Blockly.Python.ORDER_MEMBER];