-
-
Notifications
You must be signed in to change notification settings - Fork 768
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
WIP: Control flow fork #198
Closed
Closed
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
292b5d7
added control flow commands to autocomplete
corevo b96ed99
indentation
corevo a901f3e
indent the commands in the table
corevo 26dc077
Playback tree class
956aff3
Command left and right options
a1ca4a1
Set monads'ish left/right directions for control flow operators
d16aaeb
Correct direction determination for control flow commands
3348a29
rerenamed executionLoop
556d0b9
Incorporate playback tree to playback execution loop
fed110d
elseIf command
30a4378
do-repeatif commands
db788d6
'times' command from playback tree perspective
570d7de
playbackTree.js adjustments and continue|break dummies
5f50ade
slightly more readable playbackTree.js
cadf453
Adjustments for indents
f18b295
Close end blocks in 'inverseExtCommandSwitcher'
3ac4ba2
'continue' command
b18fab3
Continue warning
5905bb2
Suite Validator added
3d92c0e
Fix issue with validating if-elseif-else blocks. Additional flexibili…
157ea3f
Fix 'continue' and 'break' validation. Add suite validator specs
c695d78
Sandboxing work started
6cfdb61
Eval conditions in the sandbox with variables injected
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
packages/selenium-ide/src/neo/IO/SideeX/playbackTree.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
|
||
// For now it iterates through commands array twice. Not sure how to avoid that for now | ||
|
||
export default class PlaybackTree{ | ||
constructor(commandsArray) { | ||
this.commands = commandsArray; | ||
this.process(); | ||
} | ||
|
||
process() { | ||
// TODO: Make sure to clone commands in order to skip re-renders on UI | ||
let endBlockIndexes = []; | ||
let blocks = []; | ||
for(let i = this.commands.length-1; i>=0; i--) { | ||
if (!this.isControlFlowFunction(this.commands[i].command)) { | ||
this.commands[i].setRight(this.commands[i+1]); | ||
this.commands[i].setLeft(undefined); | ||
// TODO: do not rely on left and right to be undefined on closing execution | ||
} else { | ||
this.inverseControlFlowSwitcher(i, endBlockIndexes); | ||
} | ||
} | ||
|
||
for(let i = 0; i < this.commands.length; i++) { | ||
if (this.isControlFlowFunction(this.commands[i].command)) { | ||
this.controlFlowSwitcher(i, blocks); | ||
} | ||
} | ||
|
||
this.executionNodes = this.commands; | ||
} | ||
|
||
inverseControlFlowSwitcher(index, endBlockIndexes) { | ||
switch(this.commands[index].command) { | ||
case "if": | ||
case "while": | ||
this.commands[index].setRight(this.commands[index+1]); | ||
this.commands[index].setLeft(this.commands[endBlockIndexes.pop() + 1]); | ||
break; | ||
case "else": | ||
this.commands[index].setRight(this.commands[endBlockIndexes.pop() + 1]); | ||
this.commands[index].setLeft(undefined); | ||
endBlockIndexes.push(index); | ||
break; | ||
case "end": | ||
this.commands[index].setLeft(undefined); | ||
endBlockIndexes.push(index); | ||
break; | ||
default: | ||
window.addLog(`Unknown control flow operator "${this.commands[index].command}"`); | ||
} | ||
} | ||
|
||
controlFlowSwitcher(index, blocks) { | ||
if (["if", "else", "while"].includes(this.commands[index].command)) { | ||
blocks.push(this.commands[index]); | ||
} else if (this.commands[index].command === "end") { | ||
let lastBlock = blocks.pop(); | ||
if(["if", "else"].includes(lastBlock.command)) { | ||
this.commands[index].setRight(this.commands[index+1]); | ||
} else if (lastBlock.command === "while") { | ||
this.commands[index].setRight(lastBlock); | ||
} | ||
} else { | ||
window.addLog(`Unknown control flow operator "${this.commands[index].command}"`); | ||
} | ||
} | ||
|
||
// TODO: avoid duplicates with TestTable | ||
isControlFlowFunction(command) { | ||
return this.isBlock(command) || this.isBlockEnd(command); | ||
} | ||
|
||
// TODO: do, times | ||
isBlock(command) { | ||
switch(command) { | ||
case "if": | ||
case "while": | ||
case "else": | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
// TODO: endDo | ||
isBlockEnd(command) { | ||
switch(command) { | ||
case "end": | ||
case "else": | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
static processCommands(commandsArray) { | ||
new PlaybackTree(commandsArray); | ||
} | ||
|
||
// TODO: maintenance function: remove when possible | ||
maintenance() { | ||
|
||
// runCommand(this.executionNodes[0]); | ||
window.addLog("maintenance"); | ||
this.executionNodes.forEach((node) => { | ||
window.addLog(`[[ Command: ]] ${node.command}`); | ||
if (node.left) { | ||
window.addLog(`[[ Command left direction: ]] ${node.left.command}`); | ||
} else { | ||
window.addLog(`[[ Command left direction: ]] not defined`); | ||
} | ||
if (node.right) { | ||
window.addLog(`[[ Command right direction: ]] ${node.right.command}`); | ||
} else { | ||
window.addLog(`[[ Command right direction: ]] not defined`); | ||
} | ||
window.addLog(`----------------------`); | ||
}); | ||
|
||
// function runCommand(command) { | ||
// window.addLog() | ||
// console.log(command.command); | ||
// if (command.right) { | ||
// runCommand(command.right); | ||
// } | ||
// } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is unnecessary, just add
Selenium.prototype.doConditional
, make it something like,return !!eval(conditional)
.This will give you more control, we just need a new class of commands, I believe.
Currently we have 2:
We also have
type
which is in the middle, because it's both, it has to wait like a content command, but it needs the elevated background script.IMO just create an isFlowCommand (like isExtCommand), and execute them in that place (similarly to how I execute type, after the waiting).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is being reconsidered while I'm working on sandboxing.