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

When for loop has a label at beginning, break does not work correctly #275

Open
wch opened this issue Apr 11, 2024 · 4 comments
Open

When for loop has a label at beginning, break does not work correctly #275

wch opened this issue Apr 11, 2024 · 4 comments

Comments

@wch
Copy link

wch commented Apr 11, 2024

Consider the following code

for (var i=0; i<4; i++)
label: {
  console.log(i);
  if (i === 1) {
    console.log("break");
    break;
  }
}

When I run this code in Safari, Firefox, Chrome, or V8's d8 console, they print out:

0
1
break

However, with qjs, it prints:

0
1
break
2
3

For context, I'm encountering this problem with some code generated from compiling Dart Sass to JS: sass/dart-sass#2212

@wch
Copy link
Author

wch commented Apr 11, 2024

An even simpler version:

for (var i=0; i<4; i++)
label: {
  console.log(i);
  break;
}

@chqrlie
Copy link
Collaborator

chqrlie commented Apr 11, 2024

This is certainly a bug.
It is unusual to label some thing that is not a loop statement, which might explain why it went unnoticed until now.
Thank you for reporting this.

wch added a commit to wch/sass-quickjs that referenced this issue Apr 11, 2024
GerHobbelt pushed a commit to GerHobbelt/quickjs that referenced this issue May 6, 2024
* Add method to GetClassID

If you want to extend a built-in class you need it's class ID and there
is no robust way to get that without this accessor.

Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>

* introduce constant for invalid class ID

Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>

---------

Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
@andrjohns
Copy link

andrjohns commented Jun 24, 2024

Just wanted to flag that this bug is affecting more use-cases now that the js_of_ocaml Ocaml->JS compiler has moved to heavy use of labels and break statements for control flow

If it doesn't seem like too tricky a problem, I'd be happy to have a try - would just need to be pointed towards the right place to start. Thanks!

@chqrlie
Copy link
Collaborator

chqrlie commented Jun 24, 2024

@andrjohns: I shall take a look this week.

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

3 participants