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

IllegalStateException when for ... of is used #276

Closed
karottenreibe opened this issue Sep 4, 2019 · 2 comments
Closed

IllegalStateException when for ... of is used #276

karottenreibe opened this issue Sep 4, 2019 · 2 comments
Assignees
Labels

Comments

@karottenreibe
Copy link

Run the following modified docs/example/script.js through JSCover v2.0.8. It reproduces the problem.

Expected: JS is instrumented
Actual:

java.lang.IllegalStateException: FOR_OF 9 [length: 50] [source_file: /doc/example/script.js]
	at com.google.common.base.Preconditions.checkState(Preconditions.java:507)
	at com.google.javascript.jscomp.CodeGenerator.add(CodeGenerator.java:717)
	at com.google.javascript.jscomp.CodeGenerator.add(CodeGenerator.java:662)
	at com.google.javascript.jscomp.CodeGenerator.add(CodeGenerator.java:104)
	at com.google.javascript.jscomp.CodeGenerator.addFunction(CodeGenerator.java:1421)
	at com.google.javascript.jscomp.CodeGenerator.add(CodeGenerator.java:403)
	at com.google.javascript.jscomp.CodeGenerator.add(CodeGenerator.java:662)
	at com.google.javascript.jscomp.CodeGenerator.add(CodeGenerator.java:104)
	at com.google.javascript.jscomp.CodePrinter.toSource(CodePrinter.java:878)
	at com.google.javascript.jscomp.CodePrinter.access$300(CodePrinter.java:40)
	at com.google.javascript.jscomp.CodePrinter$Builder.build(CodePrinter.java:813)
	at jscover.instrument.SourceProcessor.instrumentSource(SourceProcessor.java:476)
	at jscover.instrument.SourceProcessor.processSourceWithoutHeader(SourceProcessor.java:435)
	at jscover.instrument.SourceProcessor.processSource(SourceProcessor.java:423)
	at jscover.instrument.SourceProcessor.processSourceForServer(SourceProcessor.java:411)
	at jscover.instrument.InstrumenterService.instrumentJSForProxyServer(InstrumenterService.java:374)
	at jscover.server.InstrumentingRequestHandler.handleGet(InstrumentingRequestHandler.java:466)
	at jscover.server.HttpServer.run(HttpServer.java:416)

It looks like the for ... of statement is not fully supported.

Reproduction JS:

function getMessage(number) {
    return 'You selected the number '+number+'.';
}
function getMessage4() {
    return 'You selected the number 4.';
}
function go(element) {
    var a = [1,2,3,4];
    for (const r of a) {
        console.log(r);
    }

    var m = [[1,2],[3,4]];
    for (const [x, y] of m) {
        console.log(x);
        console.log(y);
    }
  var message;
  if (element.id === 'radio1') {
    message = 'You selected the number 1.';
  }
  else if (element.id === 'radio2') {
    message = getMessage(2);
  }
  else if (element.id === 'radio3') {
    message = getMessage(3);
  }
  else if (element.id === 'radio4') {
    message = getMessage4();
  }
  var div = document.getElementById('request');
  div.className = 'black';
  div = document.getElementById('result');
  div.innerHTML = '<p>' + message + '</p>';
  div.innerHTML += '<p>If you are running the instrumented version of this program, you can click the "Summary" tab to view a coverage report.</p>';
}
@tntim96 tntim96 self-assigned this Sep 4, 2019
tntim96 added a commit that referenced this issue Sep 4, 2019
@tntim96
Copy link
Owner

tntim96 commented Sep 4, 2019

I think I've fixed this. You can either build from source, or if using maven, you can test the snapshot with:

<!--- Configure repository --->
<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
<!--- Configure snapshot --->
<dependency>
    <groupId>com.github.tntim96</groupId>
    <artifactId>JSCover</artifactId>
    <version>2.0.9-SNAPSHOT</version>
</dependency>

...or just download the latest build here.

@karottenreibe
Copy link
Author

Thank you, I can confirm that this version fixes the bug. Thanks for the very fast response :-)

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

No branches or pull requests

2 participants