summaryrefslogtreecommitdiffstats
path: root/browserTest/nodeUtil.js
blob: 9ccb6b9432efc86456b8e0ebb631910a76aa3e06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
browserUtil = {
  isNodeJS: true,
  
  pauseAndThen: function (cb) { cb(); },
  
  cpsIterate: function (f, start, end, pause, callback) {
    function go() {
      var called = false;
      if (start >= end) {
        callback && callback();
      } else {
        f(start, function () {
          if (!called) { called = true; start++; go(); }
        });
      }
    }
    go (start);
  },
  
  cpsMap: function (map, list, pause, callback) {
    browserUtil.cpsIterate(function (i, cb) { map(list[i], i, list.length, cb); },
                           0, list.length, pause, callback);
  },

  loadScripts: function(scriptNames, callback) {
    for (i=0; i<scriptNames.length; i++) {
      load(scriptNames[i]);
      callback && callback();
    }
  },
  
  write: function(type, message) {
    console.log(message);
    return { update: function (type2, message2) {
      if (type2 === 'pass') { console.log("  + " + message2); }
      else if (type2 === 'unimplemented') { console.log("  ? " + message2); }
      else { console.log("  - " + message2); }
    }};
  },
  
  writeNewline: function () { console.log(""); },
  
  status: function(message) {}
};