@@ -301,6 +301,8 @@ class WPTRunner { |
301 | 301 | this.inProgress = new Set(); |
302 | 302 | this.workers = new Map(); |
303 | 303 | this.unexpectedFailures = []; |
| 304 | + |
| 305 | + this.scriptsModifier = null; |
304 | 306 | } |
305 | 307 |
|
306 | 308 | /** |
@@ -319,6 +321,14 @@ class WPTRunner { |
319 | 321 | this.initScript = script; |
320 | 322 | } |
321 | 323 |
|
| 324 | + /** |
| 325 | + * Set the scripts modifier for each script. |
| 326 | + * @param {(meta: { code: string, filename: string }) => void} |
| 327 | + */ |
| 328 | + setScriptModifier(modifier) { |
| 329 | + this.scriptsModifier = modifier; |
| 330 | + } |
| 331 | + |
322 | 332 | get fullInitScript() { |
323 | 333 | if (this.initScript === null && this.dummyGlobalThisScript === null) { |
324 | 334 | return null; |
@@ -330,7 +340,7 @@ class WPTRunner { |
330 | 340 | return this.initScript; |
331 | 341 | } |
332 | 342 |
|
333 | | - return `${this.fullInitScript}\n\n//===\n${this.initScript}`; |
| 343 | + return `${this.dummyGlobalThisScript}\n\n//===\n${this.initScript}`; |
334 | 344 | } |
335 | 345 |
|
336 | 346 | /** |
@@ -387,17 +397,21 @@ class WPTRunner { |
387 | 397 | // Scripts specified with the `// META: script=` header |
388 | 398 | if (meta.script) { |
389 | 399 | for (const script of meta.script) { |
390 | | - scriptsToRun.push({ |
| 400 | + const obj = { |
391 | 401 | filename: this.resource.toRealFilePath(relativePath, script), |
392 | 402 | code: this.resource.read(relativePath, script, false) |
393 | | - }); |
| 403 | + }; |
| 404 | + this.scriptsModifier?.(obj); |
| 405 | + scriptsToRun.push(obj); |
394 | 406 | } |
395 | 407 | } |
396 | 408 | // The actual test |
397 | | - scriptsToRun.push({ |
| 409 | + const obj = { |
398 | 410 | code: content, |
399 | 411 | filename: absolutePath |
400 | | - }); |
| 412 | + }; |
| 413 | + this.scriptsModifier?.(obj); |
| 414 | + scriptsToRun.push(obj); |
401 | 415 |
|
402 | 416 | const workerPath = path.join(__dirname, 'wpt/worker.js'); |
403 | 417 | const worker = new Worker(workerPath, { |
|