-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v8.js
58 lines (52 loc) · 1.59 KB
/
v8.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
var v8 = {
statusTexts: [
"IsFunction",
"NeverOptimize",
"AlwaysOptimize",
"MaybeDeopted",
"Optimized",
"TurboFanned",
"Interpreted",
"MarkedForOptimization",
"MarkedForConcurrentOptimization",
"OptimizingConcurrently",
"IsExecuting",
"TopmostFrameIsTurboFanned",
"LiteMode",
"MarkedForDeoptimization"
]
}
, assert = describe.assert
/* globals describe */
try {
// chrome --js-flags="--allow-natives-syntax" test.html
// node --allow-natives-syntax test.js
if (describe.conf.v8 !== false) {
try {
require("v8").setFlagsFromString("--allow_natives_syntax")
} /* c8 ignore next */ catch(e) {}
;[ "GetOptimizationStatus", "HasFastProperties", "OptimizeFunctionOnNextCall"].forEach(function(name) {
v8[name] = Function("fn", "return %" + name+ "(fn)")
})
}
} /* c8 ignore next */ catch(e) {}
assert.isFast = v8.HasFastProperties ? function(obj) {
return this(v8.HasFastProperties(obj), "Should have fast properties")
} : assert.skip
assert.isNotFast = v8.HasFastProperties ? function(obj) {
return this(!v8.HasFastProperties(obj), "Should not have fast properties")
} : assert.skip
assert.isOptimized = v8.GetOptimizationStatus ? function(fn, args, scope) {
fn.apply(scope, args)
fn.apply(scope, args)
v8.OptimizeFunctionOnNextCall(fn)
for (var i = 0; i++ < 10000 && !(v8.GetOptimizationStatus(fn) & (16|32));) fn.apply(scope, args)
var status = v8.GetOptimizationStatus(fn)
, statusText = v8.statusTexts.filter(function(val, i) {
return status & (1<<i)
}).join(", ")
return this(
status & (16|32),
"Status " + status + " = " + statusText
)
} : assert.skip