Giter VIP home page Giter VIP logo

Comments (3)

no-stack-dub-sack avatar no-stack-dub-sack commented on May 28, 2024

@btruhand Yes... this is a good point, and a decision I had a bit of trouble with.

The problem, is here and here. In order to loop-protect the code, I was stuck in a situation where basically I have to eval the code twice. I also made a note about this here.

You would think that I'd be able to get rid of the surrounding if block add the loop-protect transform directly right here, without having the intermediate function wontTimeout which evals the code first to check for infinite loops (and silences the console), like this:

import wontTimeout, { loopProtect } from './loop-protect'

// ... other code from eval-code-run-tests.js

 // if (wontTimeout(code)) {
    try {
      eval(
        loopProtect(code) +
        tail +
        tests +
        executeTests
      )
    } catch (e) {
      console.log(e.toString())
    }
//  }

However, when I did this (my first try), it would work correctly when an infinite-loop was detected, but when there was no loop in the user's code, it would cause some very strange behavior which I was totally unable to explain (basically the test-runner would think that there was 1000s tests, and it would loop over those tests and log them all as failing, basically creating an infinite loop that didn't exist!).

So... I silenced the console in the first eval to prevent everything from being logged twice. I suppose I could do some kind of regexp test to check for the presence of loops and only transform the code if they exist, but I haven't tested this. I do see how silencing the console could be a disadvantage though.

from cs-playground-react.

no-stack-dub-sack avatar no-stack-dub-sack commented on May 28, 2024

Oh, and this should only be for infinite loops, when other errors are caught, it should still log any messages prior to the error stopping exection of the code

from cs-playground-react.

no-stack-dub-sack avatar no-stack-dub-sack commented on May 28, 2024

☝️@btruhand this PR fixes things, but it's a bit of a hack! Also removes another hack, so I guess it all evens out 😕

from cs-playground-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.