| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <script src="../resources/js-test.js"></script> | |
| 3 <script src="resources/compatibility.js"></script> | |
| 4 <body> | |
| 5 <script> | |
| 6 description('Tests that a script processor node is not prematurely GCed'); | |
| 7 var jsTestIsAsync = true; | |
| 8 | |
| 9 if (!window.internals) { | |
| 10 testFailed('This test requires window.internals.'); | |
| 11 finishJSTest(); | |
| 12 } | |
| 13 | |
| 14 var wasCalled, wasCollectedPrematurely, savedNode, savedCallback; | |
| 15 | |
| 16 function test(saveReference, nextStep) { | |
| 17 debug('Testing ' + (saveReference ? 'with' : 'without') + ' explicitly ' + | |
| 18 'keeping a reference to the script processor node alive.'); | |
| 19 | |
| 20 // Create an audio context | |
| 21 var context = new OfflineAudioContext( | |
| 22 2, // channels | |
| 23 4096, // length (frames) | |
| 24 44100.0); // sample rate | |
| 25 | |
| 26 // Set up a source, reading from an empty buffer | |
| 27 var source = context.createBufferSource(); | |
| 28 source.buffer = context.createBuffer( | |
| 29 2, // source channels | |
| 30 4096, // length (frames) | |
| 31 44100.0); // sample rate | |
| 32 | |
| 33 // Set up a script processor node to generate something | |
| 34 var node = context.createScriptProcessor( | |
| 35 512, // buffer size | |
| 36 0, // input channels | |
| 37 2); // output channels | |
| 38 | |
| 39 // source -> script processor node -> destination | |
| 40 source.connect(node); | |
| 41 node.connect(context.destination); | |
| 42 | |
| 43 // Set up something which indicates whether we're called to | |
| 44 // generate anything | |
| 45 | |
| 46 wasCalled = false; | |
| 47 var callback = function () { wasCalled = true; }; | |
| 48 node.onaudioprocess = callback; | |
| 49 | |
| 50 if (saveReference) { | |
| 51 savedNode = node; | |
| 52 savedCallback = callback; | |
| 53 } | |
| 54 | |
| 55 // Watch the callback; if it dies, we're obviously not generating anything | |
| 56 | |
| 57 var observation = internals.observeGC(callback); | |
| 58 node = callback = null; | |
| 59 gc(); | |
| 60 wasCollectedPrematurely = observation.wasCollected; | |
| 61 | |
| 62 // Make some noise! | |
| 63 | |
| 64 source.start(0); | |
| 65 context.oncomplete = check(nextStep); | |
| 66 context.startRendering(); | |
| 67 } | |
| 68 | |
| 69 function check(nextStep) { | |
| 70 return function () { | |
| 71 shouldBeFalse('wasCollectedPrematurely'); | |
| 72 shouldBeTrue('wasCalled'); | |
| 73 nextStep(); | |
| 74 }; | |
| 75 } | |
| 76 | |
| 77 function step1() { | |
| 78 test(true, step2); | |
| 79 } | |
| 80 | |
| 81 function step2() { | |
| 82 test(false, finishJSTest); | |
| 83 } | |
| 84 | |
| 85 step1(); | |
| 86 | |
| 87 var successfullyParsed = true; | |
| 88 </script> | |
| OLD | NEW |