2 <script src=
"../resources/js-test.js"></script>
3 <script src=
"resources/compatibility.js"></script>
6 description('Tests that a script processor node is not prematurely GCed');
7 var jsTestIsAsync
= true;
9 if (!window
.internals
) {
10 testFailed('This test requires window.internals.');
14 var wasCalled
, wasCollectedPrematurely
, savedNode
, savedCallback
;
16 function test(saveReference
, nextStep
) {
17 debug('Testing ' + (saveReference
? 'with' : 'without') + ' explicitly ' +
18 'keeping a reference to the script processor node alive.');
20 // Create an audio context
21 var context
= new OfflineAudioContext(
23 4096, // length (frames)
24 44100.0); // sample rate
26 // Set up a source, reading from an empty buffer
27 var source
= context
.createBufferSource();
28 source
.buffer
= context
.createBuffer(
30 4096, // length (frames)
31 44100.0); // sample rate
33 // Set up a script processor node to generate something
34 var node
= context
.createScriptProcessor(
37 2); // output channels
39 // source -> script processor node -> destination
41 node
.connect(context
.destination
);
43 // Set up something which indicates whether we're called to
47 var callback = function () { wasCalled
= true; };
48 node
.onaudioprocess
= callback
;
52 savedCallback
= callback
;
55 // Watch the callback; if it dies, we're obviously not generating anything
57 var observation
= internals
.observeGC(callback
);
58 node
= callback
= null;
60 wasCollectedPrematurely
= observation
.wasCollected
;
65 context
.oncomplete
= check(nextStep
);
66 context
.startRendering();
69 function check(nextStep
) {
71 shouldBeFalse('wasCollectedPrematurely');
72 shouldBeTrue('wasCalled');
82 test(false, finishJSTest
);
87 var successfullyParsed
= true;