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