From dce60fd152e2e695a0ec40e8149b071bfdde3f02 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 29 Jun 2018 16:53:26 -0700 Subject: [PATCH] Replace ReferenceError with Error. Change to 4-space indentation rather than aligning with parent structure. --- core/block.js | 22 +++++++++++----------- core/block_svg.js | 2 +- core/events_abstract.js | 2 +- core/field.js | 2 +- core/field_dropdown.js | 2 +- core/generator.js | 4 ++-- core/gesture.js | 10 +++++----- core/input.js | 4 ++-- core/toolbox.js | 2 +- core/variable_map.js | 4 ++-- core/workspace.js | 2 +- core/workspace_drag_surface_svg.js | 8 ++++---- core/workspace_svg.js | 2 +- core/xml.js | 12 ++++++------ 14 files changed, 39 insertions(+), 39 deletions(-) diff --git a/core/block.js b/core/block.js index 38709e781..f5727690e 100644 --- a/core/block.js +++ b/core/block.js @@ -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); } }; diff --git a/core/block_svg.js b/core/block_svg.js index 526787c06..b95504cba 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -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) { diff --git a/core/events_abstract.js b/core/events_abstract.js index 156353137..4fa10c82c 100644 --- a/core/events_abstract.js +++ b/core/events_abstract.js @@ -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; }; diff --git a/core/field.js b/core/field.js index a3123e38c..5c8744052 100644 --- a/core/field.js +++ b/core/field.js @@ -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; }; diff --git a/core/field_dropdown.js b/core/field_dropdown.js index b7ca8fdc0..6c4908871 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -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) { diff --git a/core/generator.js b/core/generator.js index 8c05e0483..f6f5e7a75 100644 --- a/core/generator.js +++ b/core/generator.js @@ -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') { diff --git a/core/gesture.js b/core/gesture.js index bb2070ce6..2742384f3 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -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; diff --git a/core/input.js b/core/input.js index 9ac772c6d..99c503356 100644 --- a/core/input.js +++ b/core/input.js @@ -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); }; /** diff --git a/core/toolbox.js b/core/toolbox.js index 13d3dcfe8..9a9aeffee 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -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. diff --git a/core/variable_map.js b/core/variable_map.js index 963ad5f8c..5653f3569 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -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; diff --git a/core/workspace.js b/core/workspace.js index 19823189f..2454e2ae9 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -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. diff --git a/core/workspace_drag_surface_svg.js b/core/workspace_drag_surface_svg.js index 6c45a0cba..f91d10876 100644 --- a/core/workspace_drag_surface_svg.js +++ b/core/workspace_drag_surface_svg.js @@ -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. diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 8e32e29a9..cd9e51dff 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -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') { diff --git a/core/xml.js b/core/xml.js index ddb608e7b..8916478d6 100644 --- a/core/xml.js +++ b/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());