| 1 |
|
| 2 |
// This code generates the test cases jit-test/tests/baseline/no-such-property-getprop.js |
| 3 |
// |
| 4 |
// In particular, it generates the testChain_<N>_<I>() and runChain_<N>_<I>() functions |
| 5 |
// at the tail of the file. |
| 6 |
|
| 7 |
var TEST_CASE_FUNCS = []; |
| 8 |
function runChain_NNNN_DDDD(obj) { |
| 9 |
var sum = 0; |
| 10 |
for (var i = 0; i < 100; i++) |
| 11 |
sum += obj.foo; |
| 12 |
return sum; |
| 13 |
} |
| 14 |
function testChain_NNNN_DDDD() { |
| 15 |
var obj = createTower(NNNN); |
| 16 |
assertEq(runChain_NNNN_DDDD(obj), NaN); |
| 17 |
updateChain(obj, DDDD, 'foo', 9); |
| 18 |
assertEq(runChain_NNNN_DDDD(obj), 900); |
| 19 |
} |
| 20 |
function generateTestCase(n, d) { |
| 21 |
var runFuncName = "runChain_" + n + "_" + d; |
| 22 |
var testFuncName = "testChain_" + n + "_" + d; |
| 23 |
TEST_CASE_FUNCS.push(testFuncName); |
| 24 |
|
| 25 |
print("//// Test chain of length " + n + " with late-property-addition at depth " + d); |
| 26 |
print(String(runChain_NNNN_DDDD).replace(/NNNN/g, ''+n).replace(/DDDD/g, ''+d)); |
| 27 |
print(String(testChain_NNNN_DDDD).replace(/NNNN/g, ''+n).replace(/DDDD/g, ''+d)); |
| 28 |
print(""); |
| 29 |
} |
| 30 |
|
| 31 |
// Helper function to create an object with a proto-chain of length N. |
| 32 |
function createTower(n) { |
| 33 |
var result = Object.create(null); |
| 34 |
for (var i = 0; i < n; i++) |
| 35 |
result = Object.create(result); |
| 36 |
return result; |
| 37 |
} |
| 38 |
|
| 39 |
function updateChain(obj, depth, prop, value) { |
| 40 |
// Walk down the proto chain |depth| iterations and set |prop| to |value|. |
| 41 |
var cur = obj; |
| 42 |
for (var i = 0; i < depth; i++) |
| 43 |
cur = Object.getPrototypeOf(cur); |
| 44 |
|
| 45 |
var desc = {value:value, writable:true, configurable:true, enumerable:true}; |
| 46 |
Object.defineProperty(cur, prop, desc); |
| 47 |
} |
| 48 |
|
| 49 |
print("/////////////////////////////////////////"); |
| 50 |
print("// This is a generated file!"); |
| 51 |
print("// See jit-tests/etc/generate-nosuchproperty-tests.js for the code"); |
| 52 |
print("// that generated this code!"); |
| 53 |
print("/////////////////////////////////////////"); |
| 54 |
print(""); |
| 55 |
print("/////////////////////////////////////////"); |
| 56 |
print("// PRELUDE //"); |
| 57 |
print("/////////////////////////////////////////"); |
| 58 |
print(""); |
| 59 |
print(createTower); |
| 60 |
print(updateChain); |
| 61 |
print(""); |
| 62 |
print("/////////////////////////////////////////"); |
| 63 |
print("// TEST CASES //"); |
| 64 |
print("/////////////////////////////////////////"); |
| 65 |
print(""); |
| 66 |
for (var n = 0; n <= 10; n++) { |
| 67 |
for (var d = 0; d <= n; d++) { |
| 68 |
generateTestCase(n, d); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
print(""); |
| 73 |
print("/////////////////////////////////////////"); |
| 74 |
print("// RUNNER //"); |
| 75 |
print("/////////////////////////////////////////"); |
| 76 |
print(""); |
| 77 |
for (var i = 0; i < TEST_CASE_FUNCS.length; i++) |
| 78 |
print(TEST_CASE_FUNCS[i] + "();"); |