mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Use a constructor to create the execute cache objects
This commit is contained in:
parent
a9a23ef589
commit
9b82530f51
2 changed files with 32 additions and 10 deletions
|
@ -876,21 +876,22 @@ class Blocks {
|
|||
* @param {string} blockId blockId for the desired execute cache
|
||||
* @return {object} execute cache object
|
||||
*/
|
||||
BlocksExecuteCache.getCached = function (blocks, blockId) {
|
||||
const block = blocks.getBlock(blockId);
|
||||
if (typeof block === 'undefined') return null;
|
||||
BlocksExecuteCache.getCached = function (blocks, blockId, CacheType = Object) {
|
||||
let cached = blocks._cache._executeCached[blockId];
|
||||
if (typeof cached !== 'undefined') {
|
||||
return cached;
|
||||
}
|
||||
|
||||
cached = {
|
||||
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)
|
||||
};
|
||||
});
|
||||
blocks._cache._executeCached[blockId] = cached;
|
||||
return cached;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue