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

Is async supported? #160

Open
gogo9th opened this issue Nov 10, 2020 · 3 comments
Open

Is async supported? #160

gogo9th opened this issue Nov 10, 2020 · 3 comments

Comments

@gogo9th
Copy link

gogo9th commented Nov 10, 2020

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?

@msridhar
Copy link
Contributor

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?

@gogo9th
Copy link
Author

gogo9th commented Nov 10, 2020

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;
    }

@msridhar
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants