Use null-prototype objects for maps

A {} has a bunch of names already defined on it (like ‘toString’).  When using an object as a map with arbitrary keys, it should not inherit from Object.prototype.
This commit is contained in:
Neil Fraser
2021-06-08 06:03:14 -07:00
committed by Neil Fraser
parent 53d8754ee9
commit 76b5517008
20 changed files with 46 additions and 60 deletions

View File

@@ -887,7 +887,6 @@ WorkspaceFactoryController.prototype.clearAll = function() {
if (!confirm(msg)) {
return;
}
var hasCategories = this.model.hasElements();
this.model.clearToolboxList();
this.view.clearToolboxTabs();
this.model.savePreloadXml(Blockly.utils.xml.createElement('xml'));
@@ -1209,9 +1208,9 @@ WorkspaceFactoryController.prototype.importBlocks = function(file, format) {
// If an imported block type is already defined, check if the user wants
// to override the current block definition.
if (controller.model.hasDefinedBlockTypes(blockTypes)) {
var msg = 'An imported block uses the same name as a block '
+ 'already in your toolbox. Are you sure you want to override the '
+ 'currently defined block?';
var msg = 'An imported block uses the same name as a block ' +
'already in your toolbox. Are you sure you want to override the ' +
'currently defined block?';
var continueAnyway = confirm(msg);
BlocklyDevTools.Analytics.onWarning(msg);
if (!continueAnyway) {

View File

@@ -360,7 +360,7 @@ WorkspaceFactoryModel.prototype.addCustomTag = function(category, tag) {
* @param {!Element} xml The XML to be saved.
*/
WorkspaceFactoryModel.prototype.savePreloadXml = function(xml) {
this.preloadXml = xml
this.preloadXml = xml;
};
/**
@@ -445,8 +445,8 @@ WorkspaceFactoryModel.prototype.updateLibBlockTypes = function(blockTypes) {
* @return {boolean} True if blockType is defined, false otherwise.
*/
WorkspaceFactoryModel.prototype.isDefinedBlockType = function(blockType) {
var isStandardBlock = StandardCategories.coreBlockTypes.indexOf(blockType)
!= -1;
var isStandardBlock =
StandardCategories.coreBlockTypes.indexOf(blockType) != -1;
var isLibBlock = this.libBlockTypes.indexOf(blockType) != -1;
var isImportedBlock = this.importedBlockTypes.indexOf(blockType) != -1;
return (isStandardBlock || isLibBlock || isImportedBlock);