1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/arrays/sort-getter-only.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,29 @@ 1.4 +// The property assignments in Array.prototype.sort are strict assignments. 1.5 + 1.6 +load(libdir + "asserts.js"); 1.7 + 1.8 +var a = ["A", , "B", "C", "D"]; 1.9 +var normalArrayElementDesc = Object.getOwnPropertyDescriptor(a, 0); 1.10 +var getterDesc = { 1.11 + configurable: false, 1.12 + enumerable: true, 1.13 + get: function () { return "F"; }, 1.14 + set: undefined 1.15 +}; 1.16 +Object.defineProperty(a, 1, getterDesc); 1.17 + 1.18 +// a.sort is permitted to try to delete a[1] or to try to assign a[1], but it 1.19 +// must try one or the other. Either one will fail, throwing a TypeError. 1.20 +assertThrowsInstanceOf(() => a.sort(), TypeError); 1.21 + 1.22 +// a.sort() is not permitted to delete the nonconfigurable property. 1.23 +assertDeepEq(Object.getOwnPropertyDescriptor(a, 1), getterDesc); 1.24 + 1.25 +// The values left in the other elements of a are unspecified; some or all may 1.26 +// have been deleted. 1.27 +for (var i = 0; i < a.length; i++) { 1.28 + if (i !== 1 && a.hasOwnProperty(i)) { 1.29 + normalArrayElementDesc.value = a[i]; 1.30 + assertDeepEq(Object.getOwnPropertyDescriptor(a, i), normalArrayElementDesc); 1.31 + } 1.32 +}