jalangi2 icon indicating copy to clipboard operation
jalangi2 copied to clipboard

Is async supported?

Open gogo9th opened this issue 5 years ago • 3 comments

This is a different question, but I cannot instrument the following code:

async function demo() {
console.log("Async Log");
}
demo();
console.log("Hi");

analysis.js:515
            throw tmp;
            ^
ReferenceError: regeneratorRuntime is not defined

My understanding is that async is not support in Jalangi, because a single J$ object is shared across all scripts and if they randomly do context-switch due to async, then J$ cannot properly track the sid stack, where each sid is assigned to a single script. Is this correct?

gogo9th avatar Nov 10 '20 19:11 gogo9th

async is not supported and I haven't done any serious thought on how to support it. Is using Babel to translate to ES5.1 an option for you?

msridhar avatar Nov 10 '20 19:11 msridhar

Yes, in esnstrument.js, instead of doing the following:

var newAst = acorn.parse(code, {locations: true, ecmaVersion: 6 });

My code transforms as follows:

    function es6Transform(code) {
      //  console.log('Transforming');
       if (typeof(babel) !== 'undefined' && !process.env['NO_ES7']) {
         console.log("babel.transform()...");
          var res = babel.transform(code, {
            retainLines: true,
            compact: false,
            presets: ['@babel/preset-env'],
            plugins: [
               [ "@babel/plugin-transform-modules-commonjs",
                  { 'strictMode': false },
                  "@babel/transform-runtime"
               ],
            ]
          }).code;
         console.log("babel.transform() Finished");
          if (res && res.indexOf('use strict') != -1) {
             res = res.replace(/.use strict.;\n?/, '');
          }
         //console.log(res);
          return res;
       } else {
            console.log('There is no babel loaded');
          return code;
       }
    }
...
var newAst = acorn.parse(es6Transform(code), {locations: true, allowReturnOutsideFunction: true, ecmaVersion: 6 });

However, I still get an error thrown in this function:

    function Sr(iid) { 
        var tmp, aret, isBacktrack;
        if (sandbox.analysis && sandbox.analysis.scriptExit) {
            aret = sandbox.analysis.scriptExit(iid, wrappedExceptionVal);
            if (aret) {
                wrappedExceptionVal = aret.wrappedExceptionVal;
                isBacktrack = aret.isBacktrack;
            }
        }
        rollBackSid();
        if (wrappedExceptionVal !== undefined) {
            tmp = wrappedExceptionVal.exception;
            wrappedExceptionVal = undefined;
            throw tmp;
        }
        return isBacktrack;
    }

gogo9th avatar Nov 10 '20 20:11 gogo9th

What version are you translating to with Babel? Can you post the code after Babel processing for the above example?

msridhar avatar Nov 10 '20 20:11 msridhar