| 1 |
// Copyright 2009 the Sputnik authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-array-exotic-objects-defineownproperty-p-desc |
| 6 |
info: Set the value of property length of A to Uint32(length) |
| 7 |
es5id: 15.4.5.1_A1.3_T2 |
| 8 |
description: Uint32 use ToNumber and ToPrimitve |
| 9 |
---*/ |
| 10 |
|
| 11 |
//CHECK#1 |
| 12 |
var x = []; |
| 13 |
x.length = { |
| 14 |
valueOf: function() { |
| 15 |
return 2 |
| 16 |
} |
| 17 |
}; |
| 18 |
if (x.length !== 2) { |
| 19 |
$ERROR('#1: x = []; x.length = {valueOf: function() {return 2}}; x.length === 2. Actual: ' + (x.length)); |
| 20 |
} |
| 21 |
|
| 22 |
//CHECK#2 |
| 23 |
x = []; |
| 24 |
x.length = { |
| 25 |
valueOf: function() { |
| 26 |
return 2 |
| 27 |
}, |
| 28 |
toString: function() { |
| 29 |
return 1 |
| 30 |
} |
| 31 |
}; |
| 32 |
if (x.length !== 2) { |
| 33 |
$ERROR('#0: x = []; x.length = {valueOf: function() {return 2}, toString: function() {return 1}}; x.length === 2. Actual: ' + (x.length)); |
| 34 |
} |
| 35 |
|
| 36 |
//CHECK#3 |
| 37 |
x = []; |
| 38 |
x.length = { |
| 39 |
valueOf: function() { |
| 40 |
return 2 |
| 41 |
}, |
| 42 |
toString: function() { |
| 43 |
return {} |
| 44 |
} |
| 45 |
}; |
| 46 |
if (x.length !== 2) { |
| 47 |
$ERROR('#3: x = []; x.length = {valueOf: function() {return 2}, toString: function() {return {}}}; x.length === 2. Actual: ' + (x.length)); |
| 48 |
} |
| 49 |
|
| 50 |
//CHECK#4 |
| 51 |
try { |
| 52 |
x = []; |
| 53 |
x.length = { |
| 54 |
valueOf: function() { |
| 55 |
return 2 |
| 56 |
}, |
| 57 |
toString: function() { |
| 58 |
throw "error" |
| 59 |
} |
| 60 |
}; |
| 61 |
if (x.length !== 2) { |
| 62 |
$ERROR('#4.1: x = []; x.length = {valueOf: function() {return 2}, toString: function() {throw "error"}}; x.length === ",". Actual: ' + (x.length)); |
| 63 |
} |
| 64 |
} |
| 65 |
catch (e) { |
| 66 |
if (e === "error") { |
| 67 |
$ERROR('#4.2: x = []; x.length = {valueOf: function() {return 2}, toString: function() {throw "error"}}; x.length not throw "error"'); |
| 68 |
} else { |
| 69 |
$ERROR('#4.3: x = []; x.length = {valueOf: function() {return 2}, toString: function() {throw "error"}}; x.length not throw Error. Actual: ' + (e)); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
//CHECK#5 |
| 74 |
x = []; |
| 75 |
x.length = { |
| 76 |
toString: function() { |
| 77 |
return 1 |
| 78 |
} |
| 79 |
}; |
| 80 |
if (x.length !== 1) { |
| 81 |
$ERROR('#5: x = []; x.length = {toString: function() {return 1}}; x.length === 1. Actual: ' + (x.length)); |
| 82 |
} |
| 83 |
|
| 84 |
//CHECK#6 |
| 85 |
x = []; |
| 86 |
x.length = { |
| 87 |
valueOf: function() { |
| 88 |
return {} |
| 89 |
}, |
| 90 |
toString: function() { |
| 91 |
return 1 |
| 92 |
} |
| 93 |
} |
| 94 |
if (x.length !== 1) { |
| 95 |
$ERROR('#6: x = []; x.length = {valueOf: function() {return {}}, toString: function() {return 1}}; x.length === 1. Actual: ' + (x.length)); |
| 96 |
} |
| 97 |
|
| 98 |
//CHECK#7 |
| 99 |
try { |
| 100 |
x = []; |
| 101 |
x.length = { |
| 102 |
valueOf: function() { |
| 103 |
throw "error" |
| 104 |
}, |
| 105 |
toString: function() { |
| 106 |
return 1 |
| 107 |
} |
| 108 |
}; |
| 109 |
x.length; |
| 110 |
$ERROR('#7.1: x = []; x.length = {valueOf: function() {throw "error"}, toString: function() {return 1}}; x.length throw "error". Actual: ' + (x.length)); |
| 111 |
} |
| 112 |
catch (e) { |
| 113 |
if (e !== "error") { |
| 114 |
$ERROR('#7.2: x = []; x.length = {valueOf: function() {throw "error"}, toString: function() {return 1}}; x.length throw "error". Actual: ' + (e)); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
//CHECK#8 |
| 119 |
try { |
| 120 |
x = []; |
| 121 |
x.length = { |
| 122 |
valueOf: function() { |
| 123 |
return {} |
| 124 |
}, |
| 125 |
toString: function() { |
| 126 |
return {} |
| 127 |
} |
| 128 |
}; |
| 129 |
x.length; |
| 130 |
$ERROR('#8.1: x = []; x.length = {valueOf: function() {return {}}, toString: function() {return {}}} x.length throw TypeError. Actual: ' + (x.length)); |
| 131 |
} |
| 132 |
catch (e) { |
| 133 |
if ((e instanceof TypeError) !== true) { |
| 134 |
$ERROR('#8.2: x = []; x.length = {valueOf: function() {return {}}, toString: function() {return {}}} x.length throw TypeError. Actual: ' + (e)); |
| 135 |
} |
| 136 |
} |