OLD | NEW |
---|---|
(Empty) | |
1 <!doctype html> | |
2 <html> | |
3 <head> | |
4 <title>Test premature GC upon OscillatorNode and AudioBufferSourceNode</titl e> | |
5 <script src="../resources/js-test.js"></script> | |
6 </head> | |
7 | |
8 <body> | |
9 <script type="text/javascript"> | |
10 description("Test premature GC upon OscillatorNode and AudioBufferSourceNo de"); | |
11 window.jsTestIsAsync = true; | |
12 | |
13 var sampleRate = 44100; | |
14 var renderLength = 2 * sampleRate; | |
15 | |
16 var context = new OfflineAudioContext(1, renderLength, sampleRate); | |
17 | |
18 // Immediately execute this code inside of the closure. This way |osc| is | |
19 // contained in the scope and will be a possible target of GC. However, | |
20 // it will survive GC since it has a pending activity because it is | |
21 // scheduled. Thus |onended| will be fired eventually. | |
22 (function () { | |
23 var osc = context.createOscillator(); | |
24 osc.connect(context.destination); | |
25 osc.onended = function () { | |
26 testPassed('OscillatorNode survived GC and onended event fired.'); | |
27 }; | |
28 | |
29 // Play the oscillator for 1 second. | |
30 osc.start(); | |
31 osc.stop(1); | |
32 })(); | |
33 | |
34 // The below does the same thing, but with AudioBufferSourceNode. | |
35 (function () { | |
36 var source = context.createBufferSource(); | |
37 var dummy = context.createBuffer(1, 44100 * 1.5, 44100); | |
Raymond Toy
2016/02/22 17:43:51
The oscillator test runs for 1 sec. Any particula
hongchan
2016/02/23 18:01:33
None. I'll make it same.
| |
38 source.buffer = dummy; | |
39 | |
40 source.connect(context.destination); | |
41 | |
42 source.onended = function () { | |
43 testPassed('AudioBufferSourceNode survived GC and onended event fired. '); | |
44 }; | |
45 | |
46 var now = context.currentTime; | |
47 source.start(now); | |
48 })(); | |
49 | |
50 // Suspend the rendering at 0.1 second and perform GC. The reference to | |
51 // the oscillator and the buffer source should not be collected. | |
52 context.suspend(0.1).then(function () { | |
Raymond Toy
2016/02/22 17:43:51
Why perform a GC after 0.1 sec? Should you try a
hongchan
2016/02/23 18:01:33
0.1 is just an arbitrary time position after the s
| |
53 gc(); | |
54 context.resume(); | |
55 }); | |
56 | |
57 context.startRendering().then(function () { | |
58 finishJSTest(); | |
59 }); | |
60 | |
61 succesfullyParsed = true; | |
62 </script> | |
63 </body> | |
64 </html> | |
OLD | NEW |