google / blockly

The web-based visual programming editor.
https://developers.google.com/blockly/
Apache License 2.0
12.39k stars 3.7k forks source link

BlockFactory: Replace eval() with JS-Interpreter #1269

Open AnmAtAnm opened 7 years ago

AnmAtAnm commented 7 years ago

BlockFactory supports inputting JavaScript block definitions into the UI via the "Manual JavaScript" setting, but currently the code is eval()ed to realize the preview block. Replace the raw eval() usage with JS-Interpreter to avoid running arbitrary code in the context of the rest of BlockFactory.

PR #1235 only enables the "Manual JavaScript" option when running in a file:// URL context.

starfishmod commented 7 years ago

Would this mean for example you could eventually run the blocks "live" and therefore highlight the current block as you step through the code?

RoboErikG commented 7 years ago

In context of BlockFactory this just means providing a bit of protection if you load someone else's blocks. The JS-Interpreter can be used to do block highlighting in apps that use Blockly, and this is how it's used in Blockly Games.

starfishmod commented 7 years ago

Ah ok missed the block factory part. Got excited with ideas - thanks for clearing that up.

AnmAtAnm commented 7 years ago

@starfishmod Stay excited! Check out this demo of the stepping behavior you suggested: https://blockly-demo.appspot.com/static/demos/interpreter/step-execution.html

starfishmod commented 7 years ago

That's awesome and exactly what I was thinking about - It's like having a built in debugger :) Actually I wonder if you could add breakpoints and then step through the code? :)

Great work! I'm going to have a play with this tonight

On 15 August 2017 at 03:26, Andrew n marshall notifications@github.com wrote:

@starfishmod https://github.com/starfishmod Stay excited. Check out this demo of the stepping behavior you suggested: https://blockly-demo.appspot.com/static/demos/interpreter/ step-execution.html

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/google/blockly/issues/1269#issuecomment-322253604, or mute the thread https://github.com/notifications/unsubscribe-auth/AAs6k6zMzYEYeHjUcpNq6wVy_mFk8KE6ks5sYINHgaJpZM4OxUQH .

-- Regards

Andrew