Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-merge maze loop trap #22970

Merged
merged 7 commits into from Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/src/lib/tools/jsinterpreter/codegen.js
Expand Up @@ -48,7 +48,7 @@ exports.strip = function (code) {
// Strip out serial numbers.
.replace(/(,\s*)?'block_id_\d+'\)/g, ')')
// Remove timeouts.
.replace(INFINITE_LOOP_TRAP, '')
.replace(new RegExp(utils.escapeRegExp(INFINITE_LOOP_TRAP), 'g'), '')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming soon to babel, replaceAll for this exact use case! https://twitter.com/v8js/status/1193917549060280320

// Strip out loop highlight
.replace(LOOP_HIGHLIGHT_RE, '')
// Strip out class namespaces.
Expand Down
4 changes: 2 additions & 2 deletions apps/src/maze/maze.js
Expand Up @@ -140,7 +140,7 @@ module.exports = class Maze {
Blockly.HSV_SATURATION = 0.6;

Blockly.SNAP_RADIUS *= this.scale.snapRadius;
Blockly.JavaScript.INFINITE_LOOP_TRAP = codegen.loopHighlight("Maze");
Blockly.JavaScript.INFINITE_LOOP_TRAP = codegen.loopTrap();
}

const svg = document.getElementById('svgMaze');
Expand Down Expand Up @@ -618,7 +618,7 @@ module.exports = class Maze {
*/
prepareForExecution_() {
this.executionInfo = new ExecutionInfo({
ticks: 100
ticks: 1e4
});
this.resultsHandler.executionInfo = this.executionInfo;
this.result = ResultType.UNSET;
Expand Down
4 changes: 4 additions & 0 deletions apps/src/utils.js
Expand Up @@ -764,3 +764,7 @@ export function calculateOffsetCoordinates(element, clientX, clientY) {
y: Math.round((clientY - rect.top) * element.offsetHeight / rect.height),
};
}

export function escapeRegExp(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, do special characters not need to be escaped when in a character set?

}
2 changes: 2 additions & 0 deletions apps/test/integration/levelSolutions/maze/2_16.js
Expand Up @@ -47,6 +47,8 @@ module.exports = {
testResult: TestResults.MISSING_BLOCK_UNFINISHED
},
customValidator: function () {
// Don't run all 10,000 steps...
Maze.executionInfo.steps_.length = 0;
return Maze.result === 2;
},
xml: '<xml><block type="when_run"><next><block type="maze_forever"><statement name="DO"><block type="maze_moveForward"><next><block type="maze_turn"><title name="DIR">turnLeft</title><next><block type="maze_turn"><title name="DIR">turnLeft</title></block></next></block></next></block></statement></block></next></block></xml>'
Expand Down
2 changes: 2 additions & 0 deletions apps/test/integration/levelSolutions/maze/2_9.js
Expand Up @@ -21,6 +21,8 @@ module.exports = {
testResult: TestResults.LEVEL_INCOMPLETE_FAIL
},
customValidator: function () {
// Don't run all 10,000 steps...
Maze.executionInfo.steps_.length = 0;
return Maze.result === 2;
},
xml: '<xml><block type="when_run"><next><block type="maze_forever"><statement name="DO"><block type="maze_moveForward"><next><block type="maze_turn"><title name="DIR">turnLeft</title><next><block type="maze_turn"><title name="DIR">turnLeft</title></block></next></block></next></block></statement></block></next></block></xml>'
Expand Down
2 changes: 2 additions & 0 deletions apps/test/integration/levelSolutions/maze/harvester.js
Expand Up @@ -27,6 +27,8 @@ module.exports = {
testResult: TestResults.LEVEL_INCOMPLETE_FAIL
},
customValidator: function () {
// Don't run all 10,000 steps...
Maze.executionInfo.steps_.length = 0;
return Maze.executionInfo.terminationValue() === constants.BeeTerminationValue.INFINITE_LOOP;
},
xml: '<xml>' +
Expand Down
2 changes: 2 additions & 0 deletions apps/test/integration/levelSolutions/maze/karel_1_8.js
Expand Up @@ -22,6 +22,8 @@ module.exports = {
testResult: TestResults.MISSING_BLOCK_UNFINISHED,
},
customValidator: function () {
// Don't run all 10,000 steps...
Maze.executionInfo.steps_.length = 0;
return Maze.result === 2;
},
xml: '<xml><block type="when_run"><next><block type="maze_untilBlockedOrNotClear"><title name="DIR">isPathForward</title><statement name="DO"><block type="maze_moveForward"><next><block type="maze_turn"><title name="DIR">turnLeft</title><next><block type="maze_turn"><title name="DIR">turnLeft</title></block></next></block></next></block></statement></block></next></block></xml>'
Expand Down