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

Cannot parse simple js code... #323

Open
Honya2000 opened this issue Jun 25, 2024 · 4 comments
Open

Cannot parse simple js code... #323

Honya2000 opened this issue Jun 25, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@Honya2000
Copy link

Honya2000 commented Jun 25, 2024

Hello,

Today I first tried this JS runtime, but unfortunately cannot parse simple js code:

Code looks like this:

var s_Version = function()
{
    const verSplit = Array(3);
    let vv = 125;
    for (let n = 0; n < 3; n++) {
      verSplit[n] = vv & 65535;
      vv = Math.round((vv - verSplit[n]) / 65536);
    }
    const [v0,v1,v2] = verSplit;

    return EngVersion(v0, v1, v2);
}

class EngVersion
{
  constructor(v0, v1, 2)
  {
    this.v0 = v0;
    this.v1 = v1;
    this.v2 = v2;
  }
}

it throws runtime error here:

               put_lvalue(s, opcode, scope, var_name,
                          label_lvalue, PUT_LVALUE_NOKEEP_DEPTH,
                          (tok == TOK_CONST || tok == TOK_LET));

line 24406 of quickjs.c in function js_parse_destructuring_element. Because label_lvalue is uninitialized.

during parsing of this js line:

    const [v0,v1,v2] = verSplit;

Is this construction is not supported by runtime ?

@Honya2000
Copy link
Author

Honya2000 commented Jun 26, 2024

Hmm, no any comments ?

I made workaround to this code to make it parseable:
instead of

        const [v0,v1,v2] = verSplit;

i made this:

        const v0 = verSplit[0]; 
        const v1 = verSplit[1]; 
        const v2 = verSplit[2];  

But problem is I have lot of such constructions in the code:

for example this code also cannot be parsed:

                for (const [i,child] of original.children.entries()) {
                    updateMappings(child, clone.children[i])
                }

@Honya2000
Copy link
Author

Honya2000 commented Jun 26, 2024

In many situations i even don't know how to make proper workaround:
Here for example it iterates through array of objects:

        for (const [key,val] of Object.entries(inputMap)) {

Don't think this code will work the same way:

        for (const i = 0; i < inputMap.length; i++) {
            const key = inputMap[i][0];
            const val = inputMap[i][1];

@davesnx
Copy link

davesnx commented Jun 26, 2024

@chqrlie
Copy link
Collaborator

chqrlie commented Jun 26, 2024

@davesnx destructuring is supported in quickjs, but there seems to be a bug in the specific case posted by @Honya2000 . I shall take a look shortly. Sorry for the lag.

@chqrlie chqrlie self-assigned this Jun 26, 2024
@chqrlie chqrlie added the bug Something isn't working label Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants