Better currentScript fallback

The previous heuristic didn't work under all circumstances, so try
something more robust.
This commit is contained in:
Pierre Ossman 2018-07-13 14:20:52 +02:00
parent ae2e1ff7bd
commit d131633471
3 changed files with 1214 additions and 1141 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -140,9 +140,16 @@ var WorkerPool = function (script, size) {
var current = document.currentScript; var current = document.currentScript;
// IE doesn't support currentScript // IE doesn't support currentScript
if (!current) { if (!current) {
// We should be the last loaded script // Find an entry with out basename
var scripts = document.getElementsByTagName('script'); var scripts = document.getElementsByTagName('script');
current = scripts[scripts.length - 1]; for (var i = 0; i < scripts.length; i++) {
if (scripts[i].src.indexOf("browser-es-module-loader.js") !== -1) {
current = scripts[i];
break;
}
}
if (!current)
throw Error("Could not find own <script> element");
} }
script = current.src.substr(0, current.src.lastIndexOf("/")) + "/" + script; script = current.src.substr(0, current.src.lastIndexOf("/")) + "/" + script;
this._workers = new Array(size); this._workers = new Array(size);