| 1 |
/** |
| 2 |
* AudioWorkletProcessor intended for hosting a ShadowRealm and running a test |
| 3 |
* inside of that ShadowRealm. |
| 4 |
*/ |
| 5 |
globalThis.TestRunner = class TestRunner extends AudioWorkletProcessor { |
| 6 |
constructor() { |
| 7 |
super(); |
| 8 |
this.createShadowRealmAndStartTests(); |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Fetch adaptor function intended as a drop-in replacement for fetchAdaptor() |
| 13 |
* (see testharness-shadowrealm-outer.js), but it does not assume fetch() is |
| 14 |
* present in the realm. Instead, it relies on setupFakeFetchOverMessagePort() |
| 15 |
* having been called on the port on the other side of this.port's channel. |
| 16 |
*/ |
| 17 |
fetchOverPortExecutor(resource) { |
| 18 |
return (resolve, reject) => { |
| 19 |
const listener = (event) => { |
| 20 |
if (typeof event.data !== "string" || !event.data.startsWith("fetchResult::")) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
const result = event.data.slice("fetchResult::".length); |
| 25 |
if (result.startsWith("success::")) { |
| 26 |
resolve(result.slice("success::".length)); |
| 27 |
} else { |
| 28 |
reject(result.slice("fail::".length)); |
| 29 |
} |
| 30 |
|
| 31 |
this.port.removeEventListener("message", listener); |
| 32 |
} |
| 33 |
this.port.addEventListener("message", listener); |
| 34 |
this.port.start(); |
| 35 |
this.port.postMessage(`fetchRequest::${resource}`); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Async method, which is patched over in |
| 41 |
* (test).any.audioworklet-shadowrealm.js; see serve.py |
| 42 |
*/ |
| 43 |
async createShadowRealmAndStartTests() { |
| 44 |
throw new Error("Forgot to overwrite this method!"); |
| 45 |
} |
| 46 |
|
| 47 |
/** Overrides AudioWorkletProcessor.prototype.process() */ |
| 48 |
process() { |
| 49 |
return false; |
| 50 |
} |
| 51 |
}; |
| 52 |
registerProcessor("test-runner", TestRunner); |