From 25429b119265384e96ff06ab140094191a3bd082 Mon Sep 17 00:00:00 2001 From: griffpatch Date: Wed, 22 Mar 2017 08:48:30 +0000 Subject: [PATCH] Tidy up commit and revert direct member access --- src/engine/blocks.js | 8 ++------ src/engine/execute.js | 9 ++------- test/unit/engine_blocks.js | 12 +++++++----- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/engine/blocks.js b/src/engine/blocks.js index a15f865e5..f8dacf93a 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -81,11 +81,10 @@ Blocks.prototype.getBranch = function (id, branchNum) { /** * Get the opcode for a particular block - * @param {?string} id ID of block to query + * @param {?object} block The block to query * @return {?string} the opcode corresponding to that block */ -Blocks.prototype.getOpcode = function (id) { - var block = this._blocks[id]; +Blocks.prototype.getOpcode = function (block) { return (typeof block === 'undefined') ? null : block.opcode; }; @@ -95,7 +94,6 @@ Blocks.prototype.getOpcode = function (id) { * @return {?object} All fields and their values. */ Blocks.prototype.getFields = function (block) { - // var block = this._blocks[id]; return (typeof block === 'undefined') ? null : block.fields; }; @@ -105,7 +103,6 @@ Blocks.prototype.getFields = function (block) { * @return {!object} All non-branch inputs and their associated blocks. */ Blocks.prototype.getInputs = function (block) { - // var block = this._blocks[id]; if (typeof block === 'undefined') return null; var inputs = {}; for (var input in block.inputs) { @@ -124,7 +121,6 @@ Blocks.prototype.getInputs = function (block) { * @return {?object} Mutation for the block. */ Blocks.prototype.getMutation = function (block) { - // var block = this._blocks[id]; return (typeof block === 'undefined') ? null : block.mutation; }; diff --git a/src/engine/execute.js b/src/engine/execute.js index 3a1a7de8e..c91361aae 100644 --- a/src/engine/execute.js +++ b/src/engine/execute.js @@ -44,13 +44,8 @@ var execute = function (sequencer, thread) { } } - // if (eCount++ % 1000==0) { // 603,000 times!! - // console.log('Execute x' + eCount); - // } - - // var block = blockContainer.getBlock(currentBlockId); - var opcode = block.opcode; // blockContainer.getOpcode(currentBlockId); - var fields = block.fields; // blockContainer.getFields(currentBlockId); + var opcode = blockContainer.getOpcode(block); + var fields = blockContainer.getFields(block); var inputs = blockContainer.getInputs(block); var blockFunction = runtime.getOpcodeFunction(opcode); var isHat = runtime.getIsHat(opcode); diff --git a/test/unit/engine_blocks.js b/test/unit/engine_blocks.js index 9cb3ffd4b..cfb3cdd9c 100644 --- a/test/unit/engine_blocks.js +++ b/test/unit/engine_blocks.js @@ -218,18 +218,20 @@ test('getBranch with none', function (t) { test('getOpcode', function (t) { var b = new Blocks(); - b.createBlock({ + var block = { id: 'foo', opcode: 'TEST_BLOCK', next: null, fields: {}, inputs: {}, topLevel: true - }); - var opcode = b.getOpcode('foo'); + }; + b.createBlock(block); + var opcode = b.getOpcode(block); t.equals(opcode, 'TEST_BLOCK'); - var notOpcode = b.getOpcode('?'); - t.equals(notOpcode, null); + var undefinedBlock = b.getBlock('?'); + var undefinedOpcode = b.getOpcode(undefinedBlock); + t.equals(undefinedOpcode, null); t.end(); });