mirror of
https://github.com/google/blockly.git
synced 2026-01-10 10:27:08 +01:00
Replace ReferenceError with Error.
Change to 4-space indentation rather than aligning with parent structure.
This commit is contained in:
@@ -153,7 +153,7 @@ Blockly.Block = function(workspace, prototypeName, opt_id) {
|
||||
this.type = prototypeName;
|
||||
var prototype = Blockly.Blocks[prototypeName];
|
||||
if (!prototype || typeof prototype != 'object') {
|
||||
throw Error('Unknown block type: ' + prototypeName);
|
||||
throw TypeError('Unknown block type: ' + prototypeName);
|
||||
}
|
||||
goog.mixin(this, prototype);
|
||||
}
|
||||
@@ -841,7 +841,7 @@ Blockly.Block.prototype.getFieldValue = function(name) {
|
||||
Blockly.Block.prototype.setFieldValue = function(newValue, name) {
|
||||
var field = this.getField(name);
|
||||
if (!field) {
|
||||
throw ReferenceError('Field "' + name + '" not found.');
|
||||
throw Error('Field "' + name + '" not found.');
|
||||
}
|
||||
field.setValue(newValue);
|
||||
};
|
||||
@@ -860,7 +860,7 @@ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) {
|
||||
if (!this.previousConnection) {
|
||||
if (this.outputConnection) {
|
||||
throw Error('Remove output connection prior to adding previous ' +
|
||||
'connection.');
|
||||
'connection.');
|
||||
}
|
||||
this.previousConnection =
|
||||
this.makeConnection_(Blockly.PREVIOUS_STATEMENT);
|
||||
@@ -870,7 +870,7 @@ Blockly.Block.prototype.setPreviousStatement = function(newBoolean, opt_check) {
|
||||
if (this.previousConnection) {
|
||||
if (this.previousConnection.isConnected()) {
|
||||
throw Error('Must disconnect previous statement before removing ' +
|
||||
'connection.');
|
||||
'connection.');
|
||||
}
|
||||
this.previousConnection.dispose();
|
||||
this.previousConnection = null;
|
||||
@@ -897,7 +897,7 @@ Blockly.Block.prototype.setNextStatement = function(newBoolean, opt_check) {
|
||||
if (this.nextConnection) {
|
||||
if (this.nextConnection.isConnected()) {
|
||||
throw Error('Must disconnect next statement before removing ' +
|
||||
'connection.');
|
||||
'connection.');
|
||||
}
|
||||
this.nextConnection.dispose();
|
||||
this.nextConnection = null;
|
||||
@@ -920,7 +920,7 @@ Blockly.Block.prototype.setOutput = function(newBoolean, opt_check) {
|
||||
if (!this.outputConnection) {
|
||||
if (this.previousConnection) {
|
||||
throw Error('Remove previous connection prior to adding output ' +
|
||||
'connection.');
|
||||
'connection.');
|
||||
}
|
||||
this.outputConnection = this.makeConnection_(Blockly.OUTPUT_VALUE);
|
||||
}
|
||||
@@ -1108,7 +1108,7 @@ Blockly.Block.prototype.jsonInit = function(json) {
|
||||
// Validate inputs.
|
||||
if (json['output'] && json['previousStatement']) {
|
||||
throw Error(warningPrefix +
|
||||
'Must not have both an output and a previousStatement.');
|
||||
'Must not have both an output and a previousStatement.');
|
||||
}
|
||||
|
||||
// Set basic properties of block.
|
||||
@@ -1383,10 +1383,10 @@ Blockly.Block.prototype.moveInputBefore = function(name, refName) {
|
||||
}
|
||||
}
|
||||
if (inputIndex == -1) {
|
||||
throw ReferenceError('Named input "' + name + '" not found.');
|
||||
throw Error('Named input "' + name + '" not found.');
|
||||
}
|
||||
if (refIndex == -1) {
|
||||
throw ReferenceError('Reference input "' + refName + '" not found.');
|
||||
throw Error('Reference input "' + refName + '" not found.');
|
||||
}
|
||||
this.moveNumberedInputBefore(inputIndex, refIndex);
|
||||
};
|
||||
@@ -1422,7 +1422,7 @@ Blockly.Block.prototype.moveNumberedInputBefore = function(
|
||||
* Remove an input from this block.
|
||||
* @param {string} name The name of the input.
|
||||
* @param {boolean=} opt_quiet True to prevent error if input is not present.
|
||||
* @throws {ReferenceError} if the input is not present and
|
||||
* @throws {Error} if the input is not present and
|
||||
* opt_quiet is not true.
|
||||
*/
|
||||
Blockly.Block.prototype.removeInput = function(name, opt_quiet) {
|
||||
@@ -1445,7 +1445,7 @@ Blockly.Block.prototype.removeInput = function(name, opt_quiet) {
|
||||
}
|
||||
}
|
||||
if (!opt_quiet) {
|
||||
throw ReferenceError('Input not found: ' + name);
|
||||
throw Error('Input not found: ' + name);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1216,7 +1216,7 @@ Blockly.BlockSvg.prototype.setInputsInline = function(newBoolean) {
|
||||
* Remove an input from this block.
|
||||
* @param {string} name The name of the input.
|
||||
* @param {boolean=} opt_quiet True to prevent error if input is not present.
|
||||
* @throws {ReferenceError} if the input is not present and
|
||||
* @throws {Error} if the input is not present and
|
||||
* opt_quiet is not true.
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.removeInput = function(name, opt_quiet) {
|
||||
|
||||
@@ -103,7 +103,7 @@ Blockly.Events.Abstract.prototype.getEventWorkspace_ = function() {
|
||||
var workspace = Blockly.Workspace.getById(this.workspaceId);
|
||||
if (!workspace) {
|
||||
throw Error('Workspace is null. Event must have been generated from real' +
|
||||
' Blockly events.');
|
||||
' Blockly events.');
|
||||
}
|
||||
return workspace;
|
||||
};
|
||||
|
||||
@@ -171,7 +171,7 @@ Blockly.Field.prototype.EDITABLE = true;
|
||||
*/
|
||||
Blockly.Field.prototype.setSourceBlock = function(block) {
|
||||
if (this.sourceBlock_) {
|
||||
throw TypeError('Field already bound to a block.');
|
||||
throw Error('Field already bound to a block.');
|
||||
}
|
||||
this.sourceBlock_ = block;
|
||||
};
|
||||
|
||||
@@ -541,7 +541,7 @@ Blockly.FieldDropdown.prototype.dispose = function() {
|
||||
*/
|
||||
Blockly.FieldDropdown.validateOptions_ = function(options) {
|
||||
if (!Array.isArray(options)) {
|
||||
throw Error('FieldDropdown options must be an array.');
|
||||
throw TypeError('FieldDropdown options must be an array.');
|
||||
}
|
||||
var foundError = false;
|
||||
for (var i = 0; i < options.length; ++i) {
|
||||
|
||||
@@ -174,7 +174,7 @@ Blockly.Generator.prototype.blockToCode = function(block) {
|
||||
var func = this[block.type];
|
||||
if (typeof func != 'function') {
|
||||
throw Error('Language "' + this.name_ + '" does not know how to generate ' +
|
||||
' code for block type "' + block.type + '".');
|
||||
' code for block type "' + block.type + '".');
|
||||
}
|
||||
// First argument to func.call is the value of 'this' in the generator.
|
||||
// Prior to 24 September 2013 'this' was the only way to access the block.
|
||||
@@ -184,7 +184,7 @@ Blockly.Generator.prototype.blockToCode = function(block) {
|
||||
if (Array.isArray(code)) {
|
||||
// Value blocks return tuples of code and operator order.
|
||||
if (!block.outputConnection) {
|
||||
throw Error('Expecting string from statement block: ' + block.type);
|
||||
throw TypeError('Expecting string from statement block: ' + block.type);
|
||||
}
|
||||
return [this.scrub_(block, code[0]), code[1]];
|
||||
} else if (typeof code == 'string') {
|
||||
|
||||
@@ -652,7 +652,7 @@ Blockly.Gesture.prototype.handleRightClick = function(e) {
|
||||
Blockly.Gesture.prototype.handleWsStart = function(e, ws) {
|
||||
if (this.hasStarted_) {
|
||||
throw Error('Tried to call gesture.handleWsStart, ' +
|
||||
'but the gesture had already been started.');
|
||||
'but the gesture had already been started.');
|
||||
}
|
||||
this.setStartWorkspace_(ws);
|
||||
this.mostRecentEvent_ = e;
|
||||
@@ -668,7 +668,7 @@ Blockly.Gesture.prototype.handleWsStart = function(e, ws) {
|
||||
Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) {
|
||||
if (this.hasStarted_) {
|
||||
throw Error('Tried to call gesture.handleFlyoutStart, ' +
|
||||
'but the gesture had already been started.');
|
||||
'but the gesture had already been started.');
|
||||
}
|
||||
this.setStartFlyout_(flyout);
|
||||
this.handleWsStart(e, flyout.getWorkspace());
|
||||
@@ -683,7 +683,7 @@ Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) {
|
||||
Blockly.Gesture.prototype.handleBlockStart = function(e, block) {
|
||||
if (this.hasStarted_) {
|
||||
throw Error('Tried to call gesture.handleBlockStart, ' +
|
||||
'but the gesture had already been started.');
|
||||
'but the gesture had already been started.');
|
||||
}
|
||||
this.setStartBlock(block);
|
||||
this.mostRecentEvent_ = e;
|
||||
@@ -698,7 +698,7 @@ Blockly.Gesture.prototype.handleBlockStart = function(e, block) {
|
||||
Blockly.Gesture.prototype.handleBubbleStart = function(e, bubble) {
|
||||
if (this.hasStarted_) {
|
||||
throw Error('Tried to call gesture.handleBubbleStart, ' +
|
||||
'but the gesture had already been started.');
|
||||
'but the gesture had already been started.');
|
||||
}
|
||||
this.setStartBubble(bubble);
|
||||
this.mostRecentEvent_ = e;
|
||||
@@ -787,7 +787,7 @@ Blockly.Gesture.prototype.bringBlockToFront_ = function() {
|
||||
Blockly.Gesture.prototype.setStartField = function(field) {
|
||||
if (this.hasStarted_) {
|
||||
throw Error('Tried to call gesture.setStartField, ' +
|
||||
'but the gesture had already been started.');
|
||||
'but the gesture had already been started.');
|
||||
}
|
||||
if (!this.startField_) {
|
||||
this.startField_ = field;
|
||||
|
||||
@@ -135,7 +135,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) {
|
||||
/**
|
||||
* Remove a field from this input.
|
||||
* @param {string} name The name of the field.
|
||||
* @throws {ReferenceError} if the field is not present.
|
||||
* @throws {Error} if the field is not present.
|
||||
*/
|
||||
Blockly.Input.prototype.removeField = function(name) {
|
||||
for (var i = 0, field; field = this.fieldRow[i]; i++) {
|
||||
@@ -150,7 +150,7 @@ Blockly.Input.prototype.removeField = function(name) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw ReferenceError('Field "%s" not found.', name);
|
||||
throw Error('Field "%s" not found.', name);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -287,7 +287,7 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) {
|
||||
|
||||
if (this.tree_.blocks.length) {
|
||||
throw Error('Toolbox cannot have both blocks and categories ' +
|
||||
'in the root level.');
|
||||
'in the root level.');
|
||||
}
|
||||
|
||||
// Fire a resize event since the toolbox may have changed width and height.
|
||||
|
||||
@@ -177,8 +177,8 @@ Blockly.VariableMap.prototype.createVariable = function(name,
|
||||
if (variable) {
|
||||
if (opt_id && variable.getId() != opt_id) {
|
||||
throw Error('Variable "' + name + '" is already in use and its id is "' +
|
||||
variable.getId() + '" which conflicts with the passed in ' +
|
||||
'id, "' + opt_id + '".');
|
||||
variable.getId() + '" which conflicts with the passed in ' +
|
||||
'id, "' + opt_id + '".');
|
||||
}
|
||||
// The variable already exists and has the same ID.
|
||||
return variable;
|
||||
|
||||
@@ -213,7 +213,7 @@ Blockly.Workspace.prototype.addTopComment = function(comment) {
|
||||
Blockly.Workspace.prototype.removeTopComment = function(comment) {
|
||||
if (!Blockly.utils.arrayRemove(this.topComments_, comment)) {
|
||||
throw Error('Comment not present in workspace\'s list of top-most ' +
|
||||
'comments.');
|
||||
'comments.');
|
||||
}
|
||||
// Note: If the comment database starts to hold block comments, this may need
|
||||
// to move to a separate function.
|
||||
|
||||
@@ -136,7 +136,7 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.getSurfaceTranslation = function() {
|
||||
Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) {
|
||||
if (!newSurface) {
|
||||
throw Error('Couldn\'t clear and hide the drag surface: missing ' +
|
||||
'new surface.');
|
||||
'new surface.');
|
||||
}
|
||||
var blockCanvas = this.SVG_.childNodes[0];
|
||||
var bubbleCanvas = this.SVG_.childNodes[1];
|
||||
@@ -144,7 +144,7 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) {
|
||||
!Blockly.utils.hasClass(blockCanvas, 'blocklyBlockCanvas') ||
|
||||
!Blockly.utils.hasClass(bubbleCanvas, 'blocklyBubbleCanvas')) {
|
||||
throw Error('Couldn\'t clear and hide the drag surface. ' +
|
||||
'A node was missing.');
|
||||
'A node was missing.');
|
||||
}
|
||||
|
||||
// If there is a previous sibling, put the blockCanvas back right afterwards,
|
||||
@@ -160,7 +160,7 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) {
|
||||
// Hide the drag surface.
|
||||
this.SVG_.style.display = 'none';
|
||||
if (this.SVG_.childNodes.length) {
|
||||
throw TypeError('Drag surface was not cleared.');
|
||||
throw Error('Drag surface was not cleared.');
|
||||
}
|
||||
Blockly.utils.setCssTransform(this.SVG_, '');
|
||||
this.previousSibling_ = null;
|
||||
@@ -181,7 +181,7 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) {
|
||||
Blockly.WorkspaceDragSurfaceSvg.prototype.setContentsAndShow = function(
|
||||
blockCanvas, bubbleCanvas, previousSibling, width, height, scale) {
|
||||
if (this.SVG_.childNodes.length) {
|
||||
throw TypeError('Already dragging a block.');
|
||||
throw Error('Already dragging a block.');
|
||||
}
|
||||
this.previousSibling_ = previousSibling;
|
||||
// Make sure the blocks and bubble canvas are scaled appropriately.
|
||||
|
||||
@@ -1880,7 +1880,7 @@ Blockly.WorkspaceSvg.getTopLevelWorkspaceMetrics_ = function() {
|
||||
Blockly.WorkspaceSvg.setTopLevelWorkspaceMetrics_ = function(xyRatio) {
|
||||
if (!this.scrollbar) {
|
||||
throw Error('Attempt to set top level workspace scroll without ' +
|
||||
'scrollbars.');
|
||||
'scrollbars.');
|
||||
}
|
||||
var metrics = this.getMetrics();
|
||||
if (typeof xyRatio.x == 'number') {
|
||||
|
||||
12
core/xml.js
12
core/xml.js
@@ -460,8 +460,8 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) {
|
||||
Blockly.Xml.domToVariables(xmlChild, workspace);
|
||||
} else {
|
||||
throw Error('\'variables\' tag must exist once before block and ' +
|
||||
'shadow tag elements in the workspace XML, but it was found in ' +
|
||||
'another location.');
|
||||
'shadow tag elements in the workspace XML, but it was found in ' +
|
||||
'another location.');
|
||||
}
|
||||
variablesFirst = false;
|
||||
}
|
||||
@@ -785,7 +785,7 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
|
||||
}
|
||||
// Ensure this block doesn't have any variable inputs.
|
||||
if (block.getVarModels().length) {
|
||||
throw ReferenceError('Shadow blocks cannot have variable references.');
|
||||
throw TypeError('Shadow blocks cannot have variable references.');
|
||||
}
|
||||
block.setShadow(true);
|
||||
}
|
||||
@@ -815,9 +815,9 @@ Blockly.Xml.domToFieldVariable_ = function(workspace, xml, text, field) {
|
||||
// This should never happen :)
|
||||
if (type != null && type !== variable.type) {
|
||||
throw Error('Serialized variable type with id \'' +
|
||||
variable.getId() + '\' had type ' + variable.type + ', and ' +
|
||||
'does not match variable field that references it: ' +
|
||||
Blockly.Xml.domToText(xml) + '.');
|
||||
variable.getId() + '\' had type ' + variable.type + ', and ' +
|
||||
'does not match variable field that references it: ' +
|
||||
Blockly.Xml.domToText(xml) + '.');
|
||||
}
|
||||
|
||||
field.setValue(variable.getId());
|
||||
|
||||
Reference in New Issue
Block a user