Update to use explicit procedure names and ids

This commit is contained in:
Paul Kaplan 2017-11-29 12:00:00 -05:00
parent 80b4dab104
commit 5a53323715
4 changed files with 12 additions and 11 deletions

View file

@ -27,7 +27,7 @@ class Scratch3ProcedureBlocks {
call (args, util) {
if (!util.stackFrame.executed) {
const procedureCode = args.mutation.proccode;
const paramNames = util.getProcedureParamNames(procedureCode);
const [paramNames, paramIds] = util.getProcedureParamNamesAndIds(procedureCode);
// If null, procedure could not be found, which can happen if custom
// block is dragged between sprites without the definition.
@ -36,9 +36,9 @@ class Scratch3ProcedureBlocks {
return;
}
for (let i = 0; i < paramNames.length; i++) {
if (args.hasOwnProperty(`input${i}`)) {
util.pushParam(paramNames[i], args[`input${i}`]);
for (let i = 0; i < paramIds.length; i++) {
if (args.hasOwnProperty(paramIds[i])) {
util.pushParam(paramNames[i], args[paramIds[i]]);
}
}

View file

@ -97,8 +97,8 @@ class BlockUtility {
* @param {string} procedureCode Procedure code for procedure to query.
* @return {Array.<string>} List of param names for a procedure.
*/
getProcedureParamNames (procedureCode) {
return this.thread.target.blocks.getProcedureParamNames(procedureCode);
getProcedureParamNamesAndIds (procedureCode) {
return this.thread.target.blocks.getProcedureParamNamesAndIds(procedureCode);
}
/**

View file

@ -206,7 +206,7 @@ class Blocks {
* @param {?string} name Name of procedure to query.
* @return {?Array.<string>} List of param names for a procedure.
*/
getProcedureParamNames (name) {
getProcedureParamNamesAndIds (name) {
const cachedNames = this._cache.procedureParamNames[name];
if (typeof cachedNames !== 'undefined') {
return cachedNames;
@ -217,9 +217,10 @@ class Blocks {
const block = this._blocks[id];
if (block.opcode === 'procedures_prototype' &&
block.mutation.proccode === name) {
const paramNames = JSON.parse(block.mutation.argumentnames);
this._cache.procedureParamNames[name] = paramNames;
return paramNames;
const names = JSON.parse(block.mutation.argumentnames);
const ids = JSON.parse(block.mutation.argumentids);
this._cache.procedureParamNames[name] = [names, ids];
return this._cache.procedureParamNames[name];
}
}

View file

@ -16,7 +16,7 @@ test('calling a custom block with no definition does not throw', t => {
}
};
const util = {
getProcedureParamNames: () => null,
getProcedureParamNamesAndIds: () => null,
stackFrame: {
executed: false
}