| 1 |
// Test for inlined getters for jsop_getelem accesses, where the getter is a |
| 2 |
// property on the prototype and a megamorphic IC is attached. |
| 3 |
|
| 4 |
function makeObjects(name) { |
| 5 |
class Base { |
| 6 |
constructor(v) { |
| 7 |
this._prop = v; |
| 8 |
} |
| 9 |
get [name]() { |
| 10 |
return this._prop; |
| 11 |
} |
| 12 |
} |
| 13 |
|
| 14 |
// When we hit |TYPE_FLAG_OBJECT_COUNT_LIMIT|, the objects are marked as |
| 15 |
// |TYPE_FLAG_ANYOBJECT|. That means less than |TYPE_FLAG_OBJECT_COUNT_LIMIT| |
| 16 |
// objects need to be created to have no unknown objects in the type set. |
| 17 |
const TYPE_FLAG_OBJECT_COUNT_LIMIT = 7; |
| 18 |
|
| 19 |
// |ICState::ICState::MaxOptimizedStubs| defines the maximum number of |
| 20 |
// optimized stubs, so as soon as we hit the maximum number, the megamorphic |
| 21 |
// state is entered. |
| 22 |
const ICState_MaxOptimizedStubs = 6; |
| 23 |
|
| 24 |
// Create enough classes to enter megamorphic state, but not too much to |
| 25 |
// have |TYPE_FLAG_ANYOBJECT| in the TypeSet. |
| 26 |
const OBJECT_COUNT = Math.min(ICState_MaxOptimizedStubs, TYPE_FLAG_OBJECT_COUNT_LIMIT); |
| 27 |
|
| 28 |
var objects = []; |
| 29 |
for (var i = 0; i < OBJECT_COUNT; ++i) { |
| 30 |
objects.push(new class extends Base {}(1)); |
| 31 |
} |
| 32 |
|
| 33 |
return objects; |
| 34 |
} |
| 35 |
|
| 36 |
// Defined outside of the test functions to ensure they're recognised as |
| 37 |
// constants in Ion. |
| 38 |
var atom = "prop"; |
| 39 |
var symbol = Symbol(); |
| 40 |
|
| 41 |
function testAtom() { |
| 42 |
var objects = makeObjects(atom); |
| 43 |
|
| 44 |
function f() { |
| 45 |
var actual = 0; |
| 46 |
var expected = 0; |
| 47 |
for (var i = 0; i < 1000; i++) { |
| 48 |
var obj = objects[i % objects.length]; |
| 49 |
actual += obj[atom]; |
| 50 |
expected += obj._prop; |
| 51 |
} |
| 52 |
assertEq(actual, expected); |
| 53 |
} |
| 54 |
|
| 55 |
for (var i = 0; i < 2; ++i) { |
| 56 |
f(); |
| 57 |
} |
| 58 |
} |
| 59 |
testAtom(); |
| 60 |
|
| 61 |
function testSymbol() { |
| 62 |
var objects = makeObjects(symbol); |
| 63 |
|
| 64 |
function f() { |
| 65 |
var actual = 0; |
| 66 |
var expected = 0; |
| 67 |
for (var i = 0; i < 1000; i++) { |
| 68 |
var obj = objects[i % objects.length]; |
| 69 |
actual += obj[symbol]; |
| 70 |
expected += obj._prop; |
| 71 |
} |
| 72 |
assertEq(actual, expected); |
| 73 |
} |
| 74 |
|
| 75 |
for (var i = 0; i < 2; ++i) { |
| 76 |
f(); |
| 77 |
} |
| 78 |
} |
| 79 |
testSymbol(); |