forked from williamkapke/node-compat-table
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobsoleterhinotest.js
122 lines (102 loc) · 2.94 KB
/
obsoleterhinotest.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var testers = JSON.parse(readFile('./testers.json'));
// We'll need this for the tests
var global = {};
// This function is needed to run the tests and was extracted from:
// https://github.com/kangax/compat-table/blob/gh-pages/node.js
function __createIterableObject (arr, methods) {
methods = methods || {}
if (typeof Symbol !== 'function' || !Symbol.iterator) {
return {}
}
arr.length++
var iterator = {
next: function () {
return {
value: arr.shift(),
done: arr.length <= 0
}
},
'return': methods['return'],
'throw': methods['throw']
}
var iterable = {}
iterable[Symbol.iterator] = function () { return iterator }
return iterable
}
global.__createIterableObject = __createIterableObject;
var output = {
_version: 'UNKNOWN',
_engine: 'Rhino',
}
var versions = Object.keys(testers)
function next (ver) {
if (!ver) return write()
var completed = 0
var results = output[ver] = {
_successful: 0,
_count: Object.keys(testers[ver]).length,
_percent: 0
}
Object.keys(testers[ver]).forEach(function (name) {
var script = testers[ver][name].code
results[name] = false // make SURE it makes it to the output
run(name, script, function (result) {
// expected results: `e.message` or true/false
results[name] = typeof result === 'string' ? result : !!result
if (results[name] === true) results._successful++
if (++completed === results._count) {
results._percent = results._successful / results._count
// In the future this needs to become setTimeout
// so that we can support Promises
next(versions.pop());
}
})
})
}
next(versions.pop());
function run (name, script, cb) {
// The variable "supportVersion" should have been set in "rhinoall.sh" to tell us
// approximately what version of Rhino we're using. This is necessary because the
// tests below don't just fail, but cause Rhino to crash in older versions.
if (supportVersion <= 10 && /__define[GS]etter__.+ToObject/.test(name)) {
return cb(false);
}
if (supportVersion <= 7 && /trailing commas in function syntax/.test(name)) {
return cb(false);
}
if (supportVersion <= 7 && /incomplete patterns and quantifiers/.test(name)) {
return cb(false);
}
// kangax's Promise tests reply on a asyncTestPassed function.
var async = /asyncTestPassed/.test(script)
if (async) {
runAsync(script, function (result) {
return cb(result)
})
} else {
var result = runSync(script)
return cb(result)
}
}
function runAsync (script, cb) {
try {
var fn = new Function('asyncTestPassed', script)
fn(function () {
// TODO eventually do this async. We don't have that today.
cb(true);
})
} catch (e) {
cb(e.message)
}
}
function runSync (script) {
try {
var fn = new Function(script)
return fn() || false
} catch (e) {
return e.message
}
}
function write () {
print(JSON.stringify(output, null, 2));
}