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
|
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --opt --noalways-opt
// Test that JSResolvePromise takes a proper stability dependency
// on the resolutions map if the infer receiver maps are unreliable
// (as is the case for HeapConstants).
(function() {
// We need an object literal which gets a stable map initially.
function makeObjectWithStableMap() {
return {a:1, b:1, c:1};
}
const a = makeObjectWithStableMap();
function foo() {
return Promise.resolve(a);
}
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), Promise);
assertInstanceof(foo(), Promise);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), Promise);
assertOptimized(foo);
// Now invalidate the stability of a's map.
const b = makeObjectWithStableMap();
b.d = 1;
if (%IsDictPropertyConstTrackingEnabled()) {
// TODO(v8:11457) In this mode we weren't able to inline the access, yet, so
// it stays optimized. See related TODO in
// JSNativeContextSpecialization::ReduceJSResolvePromise.
return;
}
// This should deoptimize foo.
assertUnoptimized(foo);
})();
// Same test with async functions.
(function() {
// We need an object literal which gets a stable map initially,
// it needs to be different from the above, otherwise the map
// is already not stable when we get here.
function makeObjectWithStableMap() {
return {x:1, y:1};
}
const a = makeObjectWithStableMap();
async function foo() {
return a;
}
%PrepareFunctionForOptimization(foo);
assertInstanceof(foo(), Promise);
assertInstanceof(foo(), Promise);
%OptimizeFunctionOnNextCall(foo);
assertInstanceof(foo(), Promise);
assertOptimized(foo);
// Now invalidate the stability of a's map.
const b = makeObjectWithStableMap();
b.z = 1;
if (%IsDictPropertyConstTrackingEnabled()) {
// TODO(v8:11457) In this mode we weren't able to inline the access, yet, so
// it stays optimized. See related TODO in
// JSNativeContextSpecialization::ReduceJSResolvePromise.
return;
}
// This should deoptimize foo.
assertUnoptimized(foo);
})();
|