UNPKG

1.41 kBJavaScriptView Raw
1var v8 = {
2 statusTexts: [
3 "IsFunction",
4 "NeverOptimize",
5 "AlwaysOptimize",
6 "MaybeDeopted",
7 "Optimized",
8 "TurboFanned",
9 "Interpreted",
10 "MarkedForOptimization",
11 "MarkedForConcurrentOptimization",
12 "OptimizingConcurrently",
13 "IsExecuting",
14 "TopmostFrameIsTurboFanned",
15 "LiteMode",
16 "MarkedForDeoptimization"
17 ]
18}
19, assert = describe.assert
20
21/* globals describe */
22try {
23 // chrome --js-flags="--allow-natives-syntax" test.html
24 // node --allow-natives-syntax test.js
25 if (describe.conf.v8 !== false) [ "GetOptimizationStatus", "HasFastProperties", "OptimizeFunctionOnNextCall"].map(function(name) {
26 v8[name] = Function("fn", "return %" + name+ "(fn)")
27 })
28} catch(e) {}
29
30assert.isFast = v8.HasFastProperties ? function(obj) {
31 return this(v8.HasFastProperties(obj), "Should have fast properties")
32} : assert.skip
33
34assert.isNotFast = v8.HasFastProperties ? function(obj) {
35 return this(!v8.HasFastProperties(obj), "Should not have fast properties")
36} : assert.skip
37
38assert.isOptimized = v8.GetOptimizationStatus ? function(fn, args, scope) {
39 fn.apply(scope, args)
40 fn.apply(scope, args)
41 v8.OptimizeFunctionOnNextCall(fn)
42 fn.apply(scope, args)
43 var status = v8.GetOptimizationStatus(fn)
44 , statusText = v8.statusTexts.filter(function(val, i) {
45 return status & (1<<i)
46 }).join(", ")
47
48 return this(
49 status & (16|32),
50 "Status " + status + " = " + statusText
51 )
52} : assert.skip
53