Debian Codegraph @

rhino/testsrc/tests/js1_8/extensions/simple-tree.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 var gTestfile = 'simple-tree.js';
7 //-----------------------------------------------------------------------------
8
9 var summary = "Create a tree of threads";
10
11 var N = 50; // number of threads to create
12
13 printStatus (summary);
14
15 function range(start, stop) {
16 var a = [];
17 for (var i = start; i < stop; i++)
18 a.push(i);
19 return a;
20 }
21
22 function tree(start, stop) {
23 sleep(0.001);
24
25 if (start >= stop)
26 return [];
27 else if (start + 1 >= stop)
28 return [start];
29
30 sleep(0.001);
31
32 let mid = start + Math.floor((stop - start) / 2);
33 let halves = scatter([function () { return tree(start, mid); },
34 function () { return tree(mid, stop); }]);
35 sleep(0.001);
36 return Array.prototype.concat.apply([], halves);
37 }
38
39 var expect;
40 var actual;
41
42 if (typeof scatter == 'undefined' || typeof sleep == 'undefined') {
43 print('Test skipped. scatter or sleep not defined.');
44 expect = actual = 'Test skipped.';
45 } else {
46 expect = range(0, N).toSource();
47 actual = tree(0, N).toSource();
48 }
49
50 reportCompare(expect, actual, summary);