Closed Bug 1910497 Opened 2 months ago Closed 2 months ago

Debugger.Source.text is reporting "[no source]" for worker modules loaded via ChromeUtils helpers

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
131 Branch
Tracking Status
firefox131 --- fixed

People

(Reporter: ochameau, Assigned: arai)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

Debugger's Source text attribute is returning "[no source]" for worker modules loaded via ChromeUtils.importESModule/defineESModuleGetters, at least when using { global: "current" } argument.
Note that it works fine when loading the modules via static imports.

I'll provide a mochitest.

Perhaps something to put on your backlog?

Blocks: js-debugger
Severity: -- → S3
Flags: needinfo?(bthrall)
Priority: -- → P3

I recall something like that being made on purpose, as we expected that none of Firefox functions should rely on the source, with no consideration for debugging. However I would have expected it to be the same independently of workers.

Arai, Yulia, Ted, any insight into what might be happening here?

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

I recall something like that being made on purpose, as we expected that none of Firefox functions should rely on the source, with no consideration for debugging. However I would have expected it to be the same independently of workers.

For system principal, we had been discarding the source, but it doesn't apply here.

What happening here is that the the source is marked "retrievable", but the runtime doesn't have the source hook:

https://searchfox.org/mozilla-central/rev/e637cd67f98ed4272d13a96db9a7674689122dcb/js/src/vm/JSScript.cpp#836,857-860

class ScriptSource::LoadSourceMatcher {
...
  template <typename Unit>
  bool operator()(const Retrievable<Unit>&) {
    if (!cx_->runtime()->sourceHook.ref()) {
      *loaded_ = false;

This is caused by setSourceIsLazy, which expects the runtime to have the XPCJSSourceHook, but the worker runtime doesn't have it.

https://searchfox.org/mozilla-central/rev/e637cd67f98ed4272d13a96db9a7674689122dcb/js/xpconnect/loader/mozJSModuleLoader.cpp#865-867,876-877

nsresult mozJSModuleLoader::LoadSingleModuleScriptOnWorker(
    SyncModuleLoader* aModuleLoader, JSContext* aCx,
    JS::loader::ModuleLoadRequest* aRequest, MutableHandleScript aScriptOut) {
...
  CompileOptions options(aCx);
  ScriptPreloader::FillCompileOptionsForCachedStencil(options);

https://searchfox.org/mozilla-central/rev/e637cd67f98ed4272d13a96db9a7674689122dcb/js/xpconnect/loader/ScriptPreloader.cpp#920-921,930

void ScriptPreloader::FillCompileOptionsForCachedStencil(
    JS::CompileOptions& options) {
...
  options.setSourceIsLazy(true);

https://searchfox.org/mozilla-central/rev/e637cd67f98ed4272d13a96db9a7674689122dcb/js/xpconnect/src/XPCJSRuntime.cpp#3005-3006

mozilla::UniquePtr<XPCJSSourceHook> hook(new XPCJSSourceHook);
js::SetSourceHook(cx, std::move(hook));

So the solution would be to skip the setSourceIsLazy for worker case.

Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Flags: needinfo?(bthrall)
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/b6440b259f94 Do not use lazy source in ChromeUtils.importESModule in worker. r=bthrall
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 131 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: