Error is a constructor, ‘new’ is not required.

This commit is contained in:
Neil Fraser
2019-09-12 18:02:59 -07:00
parent bf31b41a4e
commit 23caa12571
12 changed files with 23 additions and 24 deletions

View File

@@ -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_(

View File

@@ -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);

View File

@@ -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.';

View 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();

View File

@@ -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);

View File

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