JSCover icon indicating copy to clipboard operation
JSCover copied to clipboard

"this" is undefined in header.js

Open chtheis opened this issue 4 years ago • 2 comments

I'm trying to instrument an ES6 module (note I speak of client side JS, not Node.js). It looks like the initialization of an instrumented file throws an Exception in header.js line 38, because "this" is undefined here. Unlike plain JS modules seem to be very picky about this ... What is "this" supposed to be in this context?

In a fork I deleted "this." from header.js and with the new jar my test just ran fine.

It may be possible if you add "use strict"; to a file, but I haven't tried that.

chtheis avatar Aug 06 '20 18:08 chtheis

I created PR #294 with some more changes in the .js files but the integration tests fail. I could fix a few failures which were caused by my changes but not all. Currently it fails at "inMemory.js" but I can't find that file. Any help is appreciated.

chtheis avatar Aug 08 '20 08:08 chtheis

Finally I managed to run the integration tests with success ...

It might be better to declare _$jscoverage in header.js instead of touching a couple of places where it is first assigned a value but I don't understand the code good enough to make that decision.

chtheis avatar Aug 08 '20 10:08 chtheis

Hi @chtheis , sorry for not following up on this sooner. I believe this has been fixed in #311 , commit 0eca598. Can you confirm?

tntim96 avatar Oct 30 '22 04:10 tntim96

I've released it in the 2.0.16 SNAPSHOT if you'd like to test.

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

Or build the latest JAR yourself or download from here.

Let me know if that fixes your issue and I'll build a release.

tntim96 avatar Oct 30 '22 04:10 tntim96