mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
BlockCached instances are always initialized
This commit is contained in:
parent
5fd749918f
commit
2db2287d12
2 changed files with 114 additions and 126 deletions
|
@ -874,9 +874,10 @@ class Blocks {
|
|||
* reset.
|
||||
* @param {Blocks} blocks Blocks containing the expected blockId
|
||||
* @param {string} blockId blockId for the desired execute cache
|
||||
* @param {function} CacheType constructor for cached block information
|
||||
* @return {object} execute cache object
|
||||
*/
|
||||
BlocksExecuteCache.getCached = function (blocks, blockId, CacheType = Object) {
|
||||
BlocksExecuteCache.getCached = function (blocks, blockId, CacheType) {
|
||||
let cached = blocks._cache._executeCached[blockId];
|
||||
if (typeof cached !== 'undefined') {
|
||||
return cached;
|
||||
|
@ -885,13 +886,22 @@ BlocksExecuteCache.getCached = function (blocks, blockId, CacheType = Object) {
|
|||
const block = blocks.getBlock(blockId);
|
||||
if (typeof block === 'undefined') return null;
|
||||
|
||||
cached = new CacheType({
|
||||
_initialized: false,
|
||||
opcode: blocks.getOpcode(block),
|
||||
fields: blocks.getFields(block),
|
||||
inputs: blocks.getInputs(block),
|
||||
mutation: blocks.getMutation(block)
|
||||
});
|
||||
if (typeof CacheType === 'undefined') {
|
||||
cached = {
|
||||
opcode: blocks.getOpcode(block),
|
||||
fields: blocks.getFields(block),
|
||||
inputs: blocks.getInputs(block),
|
||||
mutation: blocks.getMutation(block)
|
||||
};
|
||||
} else {
|
||||
cached = new CacheType(blocks, {
|
||||
opcode: blocks.getOpcode(block),
|
||||
fields: blocks.getFields(block),
|
||||
inputs: blocks.getInputs(block),
|
||||
mutation: blocks.getMutation(block)
|
||||
});
|
||||
}
|
||||
|
||||
blocks._cache._executeCached[blockId] = cached;
|
||||
return cached;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue