| 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 |
info: Operator use ToString |
| 6 |
es5id: 15.1.3.2_A6_T1 |
| 7 |
es6id: 18.2.6.3 |
| 8 |
esid: sec-decodeuricomponent-encodeduricomponent |
| 9 |
description: If Type(value) is Object, evaluate ToPrimitive(value, String) |
| 10 |
---*/ |
| 11 |
|
| 12 |
//CHECK#1 |
| 13 |
var object = { |
| 14 |
valueOf: function() { |
| 15 |
return "%5E" |
| 16 |
} |
| 17 |
}; |
| 18 |
if (decodeURIComponent(object) !== "[object Object]") { |
| 19 |
$ERROR('#1: var object = {valueOf: function() {return "%5E"}}; decodeURIComponent(object) === [object Object]. Actual: ' + (decodeURIComponent(object))); |
| 20 |
} |
| 21 |
|
| 22 |
//CHECK#2 |
| 23 |
var object = { |
| 24 |
valueOf: function() { |
| 25 |
return "" |
| 26 |
}, |
| 27 |
toString: function() { |
| 28 |
return "%5E" |
| 29 |
} |
| 30 |
}; |
| 31 |
if (decodeURIComponent(object) !== "^") { |
| 32 |
$ERROR('#2: var object = {valueOf: function() {return ""}, toString: function() {return "%5E"}}; decodeURIComponent(object) === "^". Actual: ' + (decodeURIComponent(object))); |
| 33 |
} |
| 34 |
|
| 35 |
//CHECK#3 |
| 36 |
var object = { |
| 37 |
valueOf: function() { |
| 38 |
return "%5E" |
| 39 |
}, |
| 40 |
toString: function() { |
| 41 |
return {} |
| 42 |
} |
| 43 |
}; |
| 44 |
if (decodeURIComponent(object) !== "^") { |
| 45 |
$ERROR('#3: var object = {valueOf: function() {return "%5E"}, toString: function() {return {}}}; decodeURIComponent(object) === "^". Actual: ' + (decodeURIComponent(object))); |
| 46 |
} |
| 47 |
|
| 48 |
//CHECK#4 |
| 49 |
try { |
| 50 |
var object = { |
| 51 |
valueOf: function() { |
| 52 |
throw "error" |
| 53 |
}, |
| 54 |
toString: function() { |
| 55 |
return "%5E" |
| 56 |
} |
| 57 |
}; |
| 58 |
if (decodeURIComponent(object) !== "^") { |
| 59 |
$ERROR('#4.1: var object = {valueOf: function() {throw "error"}, toString: function() {return "%5E"}}; decodeURIComponent(object) === "^". Actual: ' + (decodeURIComponent(object))); |
| 60 |
} |
| 61 |
} |
| 62 |
catch (e) { |
| 63 |
if (e === "error") { |
| 64 |
$ERROR('#4.2: var object = {valueOf: function() {throw "error"}, toString: function() {return "%5E"}}; decodeURIComponent(object) not throw "error"'); |
| 65 |
} else { |
| 66 |
$ERROR('#4.3: var object = {valueOf: function() {throw "error"}, toString: function() {return "%5E"}}; decodeURIComponent(object) not throw Error. Actual: ' + (e)); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
//CHECK#5 |
| 71 |
var object = { |
| 72 |
toString: function() { |
| 73 |
return "%5E" |
| 74 |
} |
| 75 |
}; |
| 76 |
if (decodeURIComponent(object) !== "^") { |
| 77 |
$ERROR('#5: var object = {toString: function() {return "%5E"}}; decodeURIComponent(object) === "^". Actual: ' + (decodeURIComponent(object))); |
| 78 |
} |
| 79 |
|
| 80 |
//CHECK#6 |
| 81 |
var object = { |
| 82 |
valueOf: function() { |
| 83 |
return {} |
| 84 |
}, |
| 85 |
toString: function() { |
| 86 |
return "%5E" |
| 87 |
} |
| 88 |
} |
| 89 |
if (decodeURIComponent(object) !== "^") { |
| 90 |
$ERROR('#6: var object = {valueOf: function() {return {}}, toString: function() {return "%5E"}}; decodeURIComponent(object) === "^". Actual: ' + (decodeURIComponent(object))); |
| 91 |
} |
| 92 |
|
| 93 |
//CHECK#7 |
| 94 |
try { |
| 95 |
var object = { |
| 96 |
valueOf: function() { |
| 97 |
return "%5E" |
| 98 |
}, |
| 99 |
toString: function() { |
| 100 |
throw "error" |
| 101 |
} |
| 102 |
}; |
| 103 |
decodeURIComponent(object); |
| 104 |
$ERROR('#7.1: var object = {valueOf: function() {return "%5E"}, toString: function() {throw "error"}}; decodeURIComponent(object) throw "error". Actual: ' + (decodeURIComponent(object))); |
| 105 |
} |
| 106 |
catch (e) { |
| 107 |
if (e !== "error") { |
| 108 |
$ERROR('#7.2: var object = {valueOf: function() {return "%5E"}, toString: function() {throw "error"}}; decodeURIComponent(object) throw "error". Actual: ' + (e)); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
//CHECK#8 |
| 113 |
try { |
| 114 |
var object = { |
| 115 |
valueOf: function() { |
| 116 |
return {} |
| 117 |
}, |
| 118 |
toString: function() { |
| 119 |
return {} |
| 120 |
} |
| 121 |
}; |
| 122 |
decodeURIComponent(object); |
| 123 |
$ERROR('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; decodeURIComponent(object) throw TypeError. Actual: ' + (decodeURIComponent(object))); |
| 124 |
} |
| 125 |
catch (e) { |
| 126 |
if ((e instanceof TypeError) !== true) { |
| 127 |
$ERROR('#8.2: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; decodeURIComponent(object) throw TypeError. Actual: ' + (e)); |
| 128 |
} |
| 129 |
} |