mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +01:00
Error is a constructor, ‘new’ is not required.
This commit is contained in:
@@ -234,14 +234,14 @@ Blockly.Component.prototype.setElementInternal = function(element) {
|
||||
Blockly.Component.prototype.setParent = function(parent) {
|
||||
if (this == parent) {
|
||||
// Attempting to add a child to itself is an error.
|
||||
throw new Error(Blockly.Component.Error.PARENT_UNABLE_TO_BE_SET);
|
||||
throw Error(Blockly.Component.Error.PARENT_UNABLE_TO_BE_SET);
|
||||
}
|
||||
|
||||
if (parent && this.parent_ && this.id_ && this.parent_.getChild(this.id_) &&
|
||||
this.parent_ != parent) {
|
||||
// This component is already the child of some parent, so it should be
|
||||
// removed using removeChild/removeChildAt first.
|
||||
throw new Error(Blockly.Component.Error.PARENT_UNABLE_TO_BE_SET);
|
||||
throw Error(Blockly.Component.Error.PARENT_UNABLE_TO_BE_SET);
|
||||
}
|
||||
|
||||
this.parent_ = parent;
|
||||
@@ -328,7 +328,7 @@ Blockly.Component.prototype.renderBefore = function(sibling) {
|
||||
Blockly.Component.prototype.render_ = function(
|
||||
opt_parentElement, opt_beforeNode) {
|
||||
if (this.inDocument_) {
|
||||
throw new Error(Blockly.Component.Error.ALREADY_RENDERED);
|
||||
throw Error(Blockly.Component.Error.ALREADY_RENDERED);
|
||||
}
|
||||
|
||||
if (!this.element_) {
|
||||
@@ -526,12 +526,12 @@ Blockly.Component.prototype.addChildAt = function(child, index, opt_render) {
|
||||
if (child.inDocument_ && (opt_render || !this.inDocument_)) {
|
||||
// Adding a child that's already in the document is an error, except if the
|
||||
// parent is also in the document and opt_render is false (e.g. decorate()).
|
||||
throw new Error(Blockly.Component.Error.ALREADY_RENDERED);
|
||||
throw Error(Blockly.Component.Error.ALREADY_RENDERED);
|
||||
}
|
||||
|
||||
if (index < 0 || index > this.getChildCount()) {
|
||||
// Allowing sparse child arrays would lead to strange behavior, so we don't.
|
||||
throw new Error(Blockly.Component.Error.CHILD_INDEX_OUT_OF_BOUNDS);
|
||||
throw Error(Blockly.Component.Error.CHILD_INDEX_OUT_OF_BOUNDS);
|
||||
}
|
||||
|
||||
// Create the index and the child array on first use.
|
||||
@@ -626,7 +626,7 @@ Blockly.Component.prototype.isRightToLeft = function() {
|
||||
*/
|
||||
Blockly.Component.prototype.setRightToLeft = function(rightToLeft) {
|
||||
if (this.inDocument_) {
|
||||
throw new Error(Blockly.Component.Error.ALREADY_RENDERED);
|
||||
throw Error(Blockly.Component.Error.ALREADY_RENDERED);
|
||||
}
|
||||
this.rightToLeft_ = rightToLeft;
|
||||
};
|
||||
@@ -771,7 +771,7 @@ Blockly.Component.prototype.removeChild = function(child, opt_unrender) {
|
||||
}
|
||||
|
||||
if (!child) {
|
||||
throw new Error(Blockly.Component.Error.NOT_OUR_CHILD);
|
||||
throw Error(Blockly.Component.Error.NOT_OUR_CHILD);
|
||||
}
|
||||
|
||||
return /** @type {!Blockly.Component} */ (child);
|
||||
|
||||
@@ -786,7 +786,7 @@ Blockly.tree.BaseNode.prototype.getIconDom = function() {
|
||||
* @protected
|
||||
*/
|
||||
Blockly.tree.BaseNode.prototype.getCalculatedIconClass = function() {
|
||||
throw new Error('unimplemented abstract method');
|
||||
throw Error('unimplemented abstract method');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -668,7 +668,7 @@ Blockly.Field.prototype.getText = function() {
|
||||
* @deprecated 2019 setText should not be used directly. Use setValue instead.
|
||||
*/
|
||||
Blockly.Field.prototype.setText = function(_newText) {
|
||||
throw new Error('setText method is deprecated');
|
||||
throw Error('setText method is deprecated');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -373,6 +373,6 @@ Blockly.blockRendering.ConstantProvider.prototype.shapeFor = function(
|
||||
case Blockly.NEXT_STATEMENT:
|
||||
return this.NOTCH;
|
||||
default:
|
||||
throw new Error('Unknown connection type');
|
||||
throw Error('Unknown connection type');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -165,7 +165,7 @@ Blockly.zelos.ConstantProvider.prototype.shapeFor = function(
|
||||
case Blockly.NEXT_STATEMENT:
|
||||
return this.NOTCH;
|
||||
default:
|
||||
throw new Error('Unknown type');
|
||||
throw Error('Unknown type');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -476,7 +476,7 @@ BlockDefinitionExtractor.buildFieldDropdown_ = function(dropdown) {
|
||||
} else if (Array.isArray(menuGenerator)) {
|
||||
var options = menuGenerator;
|
||||
} else {
|
||||
throw new Error('Unrecognized type of menuGenerator: ' + menuGenerator);
|
||||
throw Error('Unrecognized type of menuGenerator: ' + menuGenerator);
|
||||
}
|
||||
|
||||
var fieldDropdown = BlockDefinitionExtractor.newDomElement_(
|
||||
|
||||
@@ -767,7 +767,7 @@ FactoryUtils.getBlockTypeFromJsDefinition = function(blockDef) {
|
||||
if (indexOfStartBracket != -1 && indexOfEndBracket != -1) {
|
||||
return blockDef.substring(indexOfStartBracket + 2, indexOfEndBracket);
|
||||
} else {
|
||||
throw new Error ('Could not parse block type out of JavaScript block ' +
|
||||
throw Error('Could not parse block type out of JavaScript block ' +
|
||||
'definition. Brackets normally enclosing block type not found.');
|
||||
}
|
||||
};
|
||||
@@ -921,7 +921,7 @@ FactoryUtils.sameBlockXml = function(blockXml1, blockXml2) {
|
||||
// Each XML element should contain a single child element with a 'block' tag
|
||||
if (blockXml1.tagName.toLowerCase() != 'xml' ||
|
||||
blockXml2.tagName.toLowerCase() != 'xml') {
|
||||
throw new Error('Expected two XML elements, received elements with tag ' +
|
||||
throw Error('Expected two XML elements, received elements with tag ' +
|
||||
'names: ' + blockXml1.tagName + ' and ' + blockXml2.tagName + '.');
|
||||
}
|
||||
|
||||
@@ -931,7 +931,7 @@ FactoryUtils.sameBlockXml = function(blockXml1, blockXml2) {
|
||||
var blockElement2 = blockXml2.getElementsByTagName('block')[0];
|
||||
|
||||
if (!(blockElement1 && blockElement2)) {
|
||||
throw new Error('Could not get find block element in XML.');
|
||||
throw Error('Could not get find block element in XML.');
|
||||
}
|
||||
|
||||
var cleanBlockXml1 = FactoryUtils.cleanXml(blockElement1);
|
||||
|
||||
@@ -340,7 +340,7 @@ WorkspaceFactoryController.prototype.exportXmlFile = function(exportMode) {
|
||||
// Unknown mode. Throw error.
|
||||
var msg = 'Unknown export mode: ' + exportMode;
|
||||
BlocklyDevTools.Analytics.onError(msg);
|
||||
throw new Error(msg);
|
||||
throw Error(msg);
|
||||
}
|
||||
|
||||
// Unpack self-closing tags. These tags fail when embedded in HTML.
|
||||
@@ -760,7 +760,7 @@ WorkspaceFactoryController.prototype.importFile = function(file, importMode) {
|
||||
BlocklyDevTools.Analytics.onImport('WorkspaceContents.xml');
|
||||
} else {
|
||||
// Throw error if invalid mode.
|
||||
throw new Error('Unknown import mode: ' + importMode);
|
||||
throw Error('Unknown import mode: ' + importMode);
|
||||
}
|
||||
} catch(e) {
|
||||
var msg = 'Cannot load XML from file.';
|
||||
|
||||
@@ -71,7 +71,7 @@ WorkspaceFactoryGenerator.prototype.generateToolboxXml = function() {
|
||||
// Toolbox has categories.
|
||||
// Assert that selected != null
|
||||
if (!this.model.getSelected()) {
|
||||
throw new Error('Selected is null when the toolbox is empty.');
|
||||
throw Error('Selected is null when the toolbox is empty.');
|
||||
}
|
||||
|
||||
var xml = this.model.getSelectedXml();
|
||||
|
||||
@@ -164,7 +164,7 @@ WorkspaceFactoryModel.prototype.moveElementToIndex = function(element, newIndex,
|
||||
// Check that indexes are in bounds.
|
||||
if (newIndex < 0 || newIndex >= this.toolboxList.length || oldIndex < 0 ||
|
||||
oldIndex >= this.toolboxList.length) {
|
||||
throw new Error('Index out of bounds when moving element in the model.');
|
||||
throw Error('Index out of bounds when moving element in the model.');
|
||||
}
|
||||
this.deleteElementFromList(oldIndex);
|
||||
this.toolboxList.splice(newIndex, 0, element);
|
||||
|
||||
@@ -201,7 +201,7 @@ WorkspaceFactoryView.prototype.moveTabToIndex =
|
||||
// Check that indexes are in bounds.
|
||||
if (newIndex < 0 || newIndex >= table.rows.length || oldIndex < 0 ||
|
||||
oldIndex >= table.rows.length) {
|
||||
throw new Error('Index out of bounds when moving tab in the view.');
|
||||
throw Error('Index out of bounds when moving tab in the view.');
|
||||
}
|
||||
|
||||
if (newIndex < oldIndex) {
|
||||
|
||||
@@ -23,7 +23,7 @@ function _nonCommentArg(desiredNonCommentArgIndex, expectedNumberOfNonCommentArg
|
||||
function _validateArguments(expectedNumberOfNonCommentArgs, args) {
|
||||
if (!( args.length == expectedNumberOfNonCommentArgs ||
|
||||
(args.length == expectedNumberOfNonCommentArgs + 1 && (typeof(args[0]) == 'string') || args[0] == null))) {
|
||||
throw new Error('Incorrect arguments passed to assert function');
|
||||
throw Error('Incorrect arguments passed to assert function');
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -56,7 +56,7 @@ function assertTrue() {
|
||||
var commentArg = _commentArg(1, arguments);
|
||||
var booleanValue = _nonCommentArg(1, 1, arguments);
|
||||
if (typeof(booleanValue) != 'boolean') {
|
||||
throw new Error('Bad argument to assertTrue(boolean)');
|
||||
throw Error('Bad argument to assertTrue(boolean)');
|
||||
}
|
||||
|
||||
chai.assert.isTrue(booleanValue, commentArg);
|
||||
@@ -71,7 +71,7 @@ function assertFalse() {
|
||||
var booleanValue = _nonCommentArg(1, 1, arguments);
|
||||
|
||||
if (typeof(booleanValue) != 'boolean') {
|
||||
throw new Error('Bad argument to assertFalse(boolean)');
|
||||
throw Error('Bad argument to assertFalse(boolean)');
|
||||
}
|
||||
|
||||
chai.assert.isNotTrue(booleanValue, commentArg);
|
||||
@@ -175,4 +175,3 @@ function defineStatementBlock() {
|
||||
"helpUrl": ""
|
||||
}]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user