wpt
wpt copied to clipboard
GLOBAL.isWindow/isWorker is not working in .any.js + module workers
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";