Add a limit to the number of items a list can have. No-op on 'addToList' block if trying to add to a list that is already at the limit.

This commit is contained in:
Karishma Chadha 2018-04-06 10:35:00 -04:00
parent 6c0d257a63
commit b436b5fd82

View file

@ -74,7 +74,7 @@ class Scratch3DataBlocks {
addToList (args, util) {
const list = util.target.lookupOrCreateList(
args.LIST.id, args.LIST.name);
list.value.push(args.ITEM);
if (list.value.length < Scratch3DataBlocks.LIST_ITEM_LIMIT) list.value.push(args.ITEM);
}
deleteOfList (args, util) {
@ -144,6 +144,14 @@ class Scratch3DataBlocks {
}
return false;
}
/**
* Type representation for list variables.
* @const {string}
*/
static get LIST_ITEM_LIMIT () {
return 200000;
}
}
module.exports = Scratch3DataBlocks;