wpt icon indicating copy to clipboard operation
wpt copied to clipboard

GLOBAL.isWindow/isWorker is not working in .any.js + module workers

Open hiroshige-g opened this issue 3 years ago • 0 comments

ModuleWorkerHandler in third_party/wpt_tools/wpt/tools/serve/serve.py generates a worker script like:

self.GLOBAL = {
  isWindow: function() { return false; },
  isWorker: function() { return true; },
  isShadowRealm: function() { return false; },
};
import "/resources/testharness.js";
import "./test.any.js";

but because test.any.js is evaluated before self.GLOBAL (unlike classic script + importScripts()), GLOBAL.isWindow/isWorker can't be used in the .any.js when it is evaluated synchronously.

One possible fix would be to encode the GLOBAL initialization into a data: URL, like:

import "data:text/javascript,self.GLOBAL=...";
import "/resources/testharness.js";
import "./test.any.js";

hiroshige-g avatar Jul 19 '22 20:07 hiroshige-g