[quickjs-devel] Parser bug

  • From: Alex Protasenko <aprotasenko@xxxxxxxxx>
  • To: quickjs-devel@xxxxxxxxxxxxx
  • Date: Mon, 29 Jun 2020 11:57:05 -0400

Hi All,

This one is not easy to demonstrate, but a syntax exception is erroneously recorded internally for the following snippet:

```

let b={a:`${1}`};

```

The problem is, it's not reported to the user at compile time and the script ends up being compiled just fine. It can only be tripped over (reported) by some random "C" extension function when script evaluates/runs.

Suppose we add an extension module called "test.so" with the following function to re-throw an internally recorded exception, which somehow wasn't returned/retrieved by the runtime:

```

static JSValue js_rethrow(JSContext *ctx, JSValueConst this_val,
                          int argc, JSValueConst *argv)
{
    JSValue error = JS_GetException(ctx);
    if (!JS_IsNull(error) && !JS_IsUndefined(error))
        return JS_Throw(ctx, error); //rethrow
    return JS_UNDEFINED;
}

```

Now, if we run this script:

```

import {rethrow} from "./test.so";

rethrow();

let b={a:`${1}`};

```

we get:

SyntaxError: unexpected end of string
    at /file/path/test.js:5


Thanks

Alex


Other related posts: