Closed Bug 1654696 Opened 4 years ago Closed 4 years ago

js::GetCodeCoverageSummary always hits release assert

Categories

(Core :: JavaScript Engine, enhancement, P5)

78 Branch
enhancement

Tracking

()

RESOLVED FIXED
81 Branch
Tracking Status
firefox-esr78 --- fixed
firefox81 --- fixed

People

(Reporter: ptomato, Assigned: ewlsh)

Details

Attachments

(2 files)

For js::GetCodeCoverageSummary() to work, code coverage has to have been enabled before the first JSRuntime is created, or you hit a release assert. However, using only the embedder API there is no way to enable it other than an environment variable, so you can end up in a situation where calling js::GetCodeCoverageSummary() will always crash.

The JS shell has access to js::coverage::EnableLCov() which fixes this problem, but other embedders do not.

I propose adding a js::EnableCodeCoverage() in jsfriendapi.h next to js::GetCodeCoverageSummary() which calls js::coverage::EnableLCov() in its implementation.

This seems like a suitable API to put in js/public/experimental in a new CodeCoverage.h header. The sort of thing that can be public, but might change in its exact operation or interface over time. All the code-coverage APIs could move there, even.

(In reply to Philip Chimento [:ptomato] from comment #0)

For js::GetCodeCoverageSummary() to work, code coverage has to have been enabled before the first JSRuntime is created, or you hit a release assert.

This sounds like a bug, knowing that this code coverage was meant to be enabled by the dev-tools later on at runtime.
Have you tried using the Debugger API? See Debugger.collectCoverageInfo and Debugger.Script.getOffsetsCoverage().

I propose adding a js::EnableCodeCoverage() […]

This sounds good to me.

Severity: -- → N/A
Type: defect → enhancement
Priority: -- → P5

(In reply to Nicolas B. Pierron [:nbp] from comment #2)

Have you tried using the Debugger API? See Debugger.collectCoverageInfo and Debugger.Script.getOffsetsCoverage().

Yes, but js::GetCodeCoverageSummary() is much more compelling because it returns a string already in the format I need :-)

Assignee: nobody → contact
Status: NEW → ASSIGNED
Pushed by abutkovits@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1283143e3d55 Implement code coverage JSAPI. r=nbp,jwalden
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 81 Branch

Comment on attachment 9167791 [details]
Bug 1654696 - Implement code coverage JSAPI. r=nbp,ptomato,jwalden

ESR Uplift Approval Request

  • If this is not a sec:{high,crit} bug, please state case for ESR consideration: Without this patch, the js::GetCodeCoverageSummary API is unreliable for SpiderMonkey embedders, and will hit a release assert in many cases, because code coverage now requires a flag to have been set that is not available as a public API for embedders. This patch adds a public API that embedders can use to set that flag.
  • User impact if declined: Embedders must either lose code-coverage functionality or rely on an environment variable always being defined. In practice, this means that Linux distributions will need to carry this patch themselves.
  • Fix Landed on Version: 81
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): The change is trivial, only wrapping an internal API inside a public one, so it doesn't seem risky. However, the patch adds a new header file. If necessary, we can upload a separate version of the patch that only adds the embedder API in an existing header file instead of adding a new one.
  • String or UUID changes made by this patch: None
Attachment #9167791 - Flags: approval-mozilla-esr78?

Backporting something tagged as experimental makes me a bit uneasy, but I guess this doesn't affect browser behavior and probably isn't a huge deal in the grand scheme of things? Am I understanding that correctly, Waldo?

Flags: needinfo?(jwalden)

[Approval Request Comment]
If this is not a sec:{high,crit} bug, please state case for ESR consideration:
User impact if declined: Embedders are currently unable to use the JSAPI coverage APIs in mozjs78 because they assert when coverage is not enabled. The API to enable to coverage is currently internal, this patch exposes that API.
Fix Landed on Version: 81
Risk to taking this patch (and alternatives if risky): None, does not impact browser code and only exposed any existing internal API.

See https://wiki.mozilla.org/Release_Management/ESR_Landing_Process for more info.

Attachment #9169227 - Flags: approval-mozilla-esr78?

I wouldn't recommend landing the patch directly because it relocates existing JSAPI calls per Waldo's earlier comments. I've uploaded a patch which only exposes js::EnableCodeCoverage and does not relocate the existing calls. It should also apply cleanly to the latest esr78 head.

I believe this is marked experimental because it is exposing an experimental API? The functionality already exists, embedders just don't have access to it in mozjs78 (they previously did).

Flags: needinfo?(jwalden)
Attachment #9167791 - Flags: approval-mozilla-esr78?

Comment on attachment 9169227 [details] [diff] [review]
0001-Bug-1654696-Implement-code-coverage-JSAPI.-r-nbp-pto.patch

Nicholas, can you please give this a quick review and confirm that this looks good for ESR uplift?

Flags: needinfo?(nicolas.b.pierron)
Attachment #9169227 - Flags: review?(nicolas.b.pierron)
Comment on attachment 9169227 [details] [diff] [review] 0001-Bug-1654696-Implement-code-coverage-JSAPI.-r-nbp-pto.patch Review of attachment 9169227 [details] [diff] [review]: ----------------------------------------------------------------- Stealing review. This is OK for ESR78.
Attachment #9169227 - Flags: review?(nicolas.b.pierron) → review+

Comment on attachment 9169227 [details] [diff] [review]
0001-Bug-1654696-Implement-code-coverage-JSAPI.-r-nbp-pto.patch

Thanks, Jason. Approved for 78.2esr.

Flags: needinfo?(nicolas.b.pierron)
Attachment #9169227 - Flags: approval-mozilla-esr78? → approval-mozilla-esr78+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: