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