| 1 |
// Assigning to a proxy with no set handler causes the proxy's |
| 2 |
// getOwnPropertyDescriptor handler to be called just before defineProperty |
| 3 |
// in some cases. (ES6 draft rev 28, 2014 Oct 14, 9.1.9 step 5.c.) |
| 4 |
|
| 5 |
var attrs = ["configurable", "enumerable", "writable", "value", "get", "set"]; |
| 6 |
|
| 7 |
function test(target, id, existingDesc, expectedDesc) { |
| 8 |
var log = ""; |
| 9 |
var p = new Proxy(target, { |
| 10 |
getOwnPropertyDescriptor(t, idarg) { |
| 11 |
assertEq(idarg, id); |
| 12 |
log += "g"; |
| 13 |
return existingDesc; |
| 14 |
}, |
| 15 |
defineProperty(t, idarg, desc) { |
| 16 |
assertEq(idarg, id); |
| 17 |
for (var attr of attrs) { |
| 18 |
var args = JSON.stringify([target, id, existingDesc]).slice(1, -1); |
| 19 |
assertEq(attr in desc, attr in expectedDesc, |
| 20 |
`test(${args}), checking existence of desc.${attr}`); |
| 21 |
assertEq(desc[attr], expectedDesc[attr], |
| 22 |
`test(${args}), checking value of desc.${attr}`); |
| 23 |
} |
| 24 |
log += "d"; |
| 25 |
return true; |
| 26 |
} |
| 27 |
}); |
| 28 |
p[id] = "pizza"; |
| 29 |
assertEq(log, "gd"); |
| 30 |
} |
| 31 |
|
| 32 |
var fullDesc = { |
| 33 |
configurable: true, |
| 34 |
enumerable: true, |
| 35 |
writable: true, |
| 36 |
value: "pizza" |
| 37 |
}; |
| 38 |
var valueOnlyDesc = { |
| 39 |
value: "pizza" |
| 40 |
}; |
| 41 |
var sealedDesc = { |
| 42 |
configurable: false, |
| 43 |
enumerable: true, |
| 44 |
writable: true, |
| 45 |
value: "pizza" |
| 46 |
}; |
| 47 |
|
| 48 |
test({}, "x", undefined, fullDesc); |
| 49 |
test({}, "x", fullDesc, valueOnlyDesc); |
| 50 |
test({x: 1}, "x", undefined, fullDesc); |
| 51 |
test({x: 1}, "x", fullDesc, valueOnlyDesc); |
| 52 |
test(Object.seal({x: 1}), "x", sealedDesc, valueOnlyDesc); |
| 53 |
test(Object.create({x: 1}), "x", undefined, fullDesc); |
| 54 |
test([0, 1, 2], "2", undefined, fullDesc); |
| 55 |
test([0, 1, 2], "2", fullDesc, valueOnlyDesc); |
| 56 |
test([0, 1, 2], "3", undefined, fullDesc); |
| 57 |
test([0, 1, 2], "3", fullDesc, valueOnlyDesc); |