mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
retrieve blockInfo from args when isDynamic is set
This commit is contained in:
parent
3b395a10d1
commit
833d33355c
2 changed files with 34 additions and 16 deletions
|
@ -13,6 +13,10 @@ const mutatorTagToObject = function (dom) {
|
||||||
for (const prop in dom.attribs) {
|
for (const prop in dom.attribs) {
|
||||||
if (prop === 'xmlns') continue;
|
if (prop === 'xmlns') continue;
|
||||||
obj[prop] = decodeHtml(dom.attribs[prop]);
|
obj[prop] = decodeHtml(dom.attribs[prop]);
|
||||||
|
if (prop === 'blockinfo') {
|
||||||
|
obj.blockInfo = JSON.parse(obj.blockinfo);
|
||||||
|
delete obj.blockinfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (let i = 0; i < dom.children.length; i++) {
|
for (let i = 0; i < dom.children.length; i++) {
|
||||||
obj.children.push(
|
obj.children.push(
|
||||||
|
|
|
@ -390,26 +390,40 @@ class ExtensionManager {
|
||||||
log.warn(`Ignoring opcode "${blockInfo.opcode}" for button with text: ${blockInfo.text}`);
|
log.warn(`Ignoring opcode "${blockInfo.opcode}" for button with text: ${blockInfo.text}`);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default: {
|
||||||
if (blockInfo.opcode) {
|
if (!blockInfo.opcode) {
|
||||||
|
throw new Error('Missing opcode for block');
|
||||||
|
}
|
||||||
|
|
||||||
const funcName = blockInfo.func ? this._sanitizeID(blockInfo.func) : blockInfo.opcode;
|
const funcName = blockInfo.func ? this._sanitizeID(blockInfo.func) : blockInfo.opcode;
|
||||||
|
|
||||||
// Avoid promise latency unless necessary
|
const getBlockInfo = blockInfo.isDynamic ?
|
||||||
|
args => args && args.mutation && args.mutation.blockInfo :
|
||||||
|
() => blockInfo;
|
||||||
|
const callBlockFunc = (() => {
|
||||||
if (dispatch._isRemoteService(serviceName)) {
|
if (dispatch._isRemoteService(serviceName)) {
|
||||||
blockInfo.func = (args, util) => dispatch.call(serviceName, funcName, args, util, blockInfo);
|
return (args, util, realBlockInfo) =>
|
||||||
} else {
|
dispatch.call(serviceName, funcName, args, util, realBlockInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// avoid promise latency if we can call direct
|
||||||
const serviceObject = dispatch.services[serviceName];
|
const serviceObject = dispatch.services[serviceName];
|
||||||
if (!serviceObject[funcName]) {
|
if (!serviceObject[funcName]) {
|
||||||
// The function might show up later as a dynamic property of the service object
|
// The function might show up later as a dynamic property of the service object
|
||||||
log.warn(`Could not find extension block function called ${funcName}`);
|
log.warn(`Could not find extension block function called ${funcName}`);
|
||||||
}
|
}
|
||||||
blockInfo.func = (args, util) => serviceObject[funcName](args, util, blockInfo);
|
return (args, util, realBlockInfo) =>
|
||||||
}
|
serviceObject[funcName](args, util, realBlockInfo);
|
||||||
} else {
|
})();
|
||||||
throw new Error('Missing opcode for block');
|
|
||||||
}
|
blockInfo.func = (args, util) => {
|
||||||
|
const realBlockInfo = getBlockInfo(args);
|
||||||
|
// TODO: filter args using the keys of realBlockInfo.arguments? maybe only if sandboxed?
|
||||||
|
return callBlockFunc(args, util, realBlockInfo);
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return blockInfo;
|
return blockInfo;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue