Skip to content

Commit 05e2074

Browse files
committed
Enhance tests
1 parent 4420cee commit 05e2074

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/AudioWorklet.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class AudioWorkletNode extends AudioNode {
142142
} catch (e) {
143143
// Spec: constructor errors fire onprocessorerror
144144
queueMicrotask(() => {
145-
let ev = new (globalThis.ErrorEvent || Event)('processorerror', { error: e, message: e?.message })
145+
let ev = new (this.context._ErrorEvent || globalThis.ErrorEvent || Event)('processorerror', { error: e, message: e?.message })
146146

147147
this.dispatchEvent(ev)
148148
})
@@ -254,15 +254,15 @@ class AudioWorkletNode extends AudioNode {
254254
let processFn = this.#processor.process
255255
if (typeof processFn !== 'function') {
256256
let e = new TypeError('process is not a function')
257-
let ev = new (globalThis.ErrorEvent || Event)('processorerror', { error: e, message: e.message })
257+
let ev = new (this.context._ErrorEvent || globalThis.ErrorEvent || Event)('processorerror', { error: e, message: e.message })
258258
this.dispatchEvent(ev)
259259
this.#alive = false
260260
if (this.context._tailNodes) this.context._tailNodes.delete(this)
261261
return outBuf
262262
}
263263
keepAlive = processFn.call(this.#processor, inputs, outputs, parameters)
264264
} catch (e) {
265-
let ev = new (globalThis.ErrorEvent || Event)('processorerror', { error: e, message: e?.message })
265+
let ev = new (this.context._ErrorEvent || globalThis.ErrorEvent || Event)('processorerror', { error: e, message: e?.message })
266266

267267
this.dispatchEvent(ev)
268268
this.#alive = false

test/wpt-runner.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async function runTest(filePath) {
163163
for (let el of document.querySelectorAll('script'))
164164
Object.defineProperty(el, 'innerText', { get() { return this.textContent } })
165165

166-
let sandbox = Object.create(null)
166+
let sandbox = {}
167167
// Copy DOM globals from linkedom, but skip JS builtins that vm provides natively
168168
let vmBuiltins = new Set([
169169
'Object', 'Function', 'Array', 'Number', 'String', 'Boolean', 'Symbol', 'RegExp',
@@ -328,9 +328,6 @@ async function runTest(filePath) {
328328
CustomEvent: typeof CustomEvent !== 'undefined' ? CustomEvent : class CustomEvent extends Event {
329329
constructor(type, opts = {}) { super(type, opts); this.detail = opts.detail ?? null }
330330
},
331-
ErrorEvent: typeof ErrorEvent !== 'undefined' ? ErrorEvent : class ErrorEvent extends Event {
332-
constructor(type, opts = {}) { super(type, opts); this.message = opts.message ?? ''; this.filename = opts.filename ?? ''; this.lineno = opts.lineno ?? 0; this.colno = opts.colno ?? 0; this.error = opts.error ?? null }
333-
},
334331
Blob,
335332
URL: Object.assign(function WPTUrl(...a) { return new URL(...a) }, {
336333
createObjectURL(blob) {
@@ -559,6 +556,15 @@ async function runTest(filePath) {
559556
// which differ from outer-realm constructors set on the sandbox)
560557
sandbox.Array = vm.runInContext('[].constructor', ctx)
561558

559+
// Create ErrorEvent inside vm so instanceof checks work cross-realm
560+
let VMErrorEvent = vm.runInContext(`(class ErrorEvent extends Event {
561+
constructor(type, opts = {}) { super(type, opts); this.message = opts.message ?? ''; this.filename = opts.filename ?? ''; this.lineno = opts.lineno ?? 0; this.colno = opts.colno ?? 0; this.error = opts.error ?? null }
562+
})`, ctx)
563+
sandbox.ErrorEvent = VMErrorEvent
564+
// Pass to WPT contexts so AudioWorkletNode uses vm-realm ErrorEvent
565+
WPTAudioContext.prototype._ErrorEvent = VMErrorEvent
566+
WPTOfflineAudioContext.prototype._ErrorEvent = VMErrorEvent
567+
562568
try {
563569
// Run testharness.js, disable DOM output (we capture results via callbacks)
564570
vm.runInContext(testharnessCode, ctx, { filename: 'testharness.js' })

0 commit comments

Comments
 (0)