@@ -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