2011-09-07 08:35:18 +02:00
|
|
|
// Copyright 2009 the Sputnik authors. All rights reserved.
|
|
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
|
2014-07-22 01:09:02 +02:00
|
|
|
/*---
|
|
|
|
info: Operator use ToString
|
2017-06-29 19:45:45 +02:00
|
|
|
esid: sec-encodeuricomponent-uricomponent
|
2014-07-22 01:09:02 +02:00
|
|
|
description: If Type(value) is Object, evaluate ToPrimitive(value, String)
|
|
|
|
---*/
|
2011-09-07 08:35:18 +02:00
|
|
|
|
|
|
|
//CHECK#1
|
2018-02-15 21:50:18 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return "^"
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
if (encodeURIComponent(object) !== "%5Bobject%20Object%5D") {
|
2021-07-21 21:37:52 +02:00
|
|
|
throw new Test262Error('#1: var object = {valueOf: function() {return "^"}}; encodeURIComponent(object) === %5Bobject%20Object%5D. Actual: ' + (encodeURIComponent(object)));
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#2
|
2018-02-15 21:50:18 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return ""
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return "^"
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
if (encodeURIComponent(object) !== "%5E") {
|
2021-07-21 21:37:52 +02:00
|
|
|
throw new Test262Error('#2: var object = {valueOf: function() {return ""}, toString: function() {return "^"}}; encodeURIComponent(object) === "%5E". Actual: ' + (encodeURIComponent(object)));
|
2017-06-29 19:45:58 +02:00
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
|
|
|
|
//CHECK#3
|
2018-02-15 21:50:18 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return "^"
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
if (encodeURIComponent(object) !== "%5E") {
|
2021-07-21 21:37:52 +02:00
|
|
|
throw new Test262Error('#3: var object = {valueOf: function() {return "^"}, toString: function() {return {}}}; encodeURIComponent(object) === "%5E". Actual: ' + (encodeURIComponent(object)));
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#4
|
|
|
|
try {
|
2018-02-15 21:50:18 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
throw "error"
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return "^"
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
if (encodeURIComponent(object) !== "%5E") {
|
2021-07-21 21:37:52 +02:00
|
|
|
throw new Test262Error('#4.1: var object = {valueOf: function() {throw "error"}, toString: function() {return "^"}}; encodeURIComponent(object) === "%5E". Actual: ' + (encodeURIComponent(object)));
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
if (e === "error") {
|
2021-07-21 21:37:52 +02:00
|
|
|
throw new Test262Error('#4.2: var object = {valueOf: function() {throw "error"}, toString: function() {return "^"}}; encodeURIComponent(object) not throw "error"');
|
2011-09-07 08:35:18 +02:00
|
|
|
} else {
|
2021-07-21 21:37:52 +02:00
|
|
|
throw new Test262Error('#4.3: var object = {valueOf: function() {throw "error"}, toString: function() {return "^"}}; encodeURIComponent(object) not throw Error. Actual: ' + (e));
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#5
|
2018-02-15 21:50:18 +01:00
|
|
|
var object = {
|
|
|
|
toString: function() {
|
|
|
|
return "^"
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
if (encodeURIComponent(object) !== "%5E") {
|
2021-07-21 21:37:52 +02:00
|
|
|
throw new Test262Error('#5: var object = {toString: function() {return "^"}}; encodeURIComponent(object) === "%5E". Actual: ' + (encodeURIComponent(object)));
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#6
|
2018-02-15 21:50:18 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return {}
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return "^"
|
|
|
|
}
|
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
if (encodeURIComponent(object) !== "%5E") {
|
2021-07-21 21:37:52 +02:00
|
|
|
throw new Test262Error('#6: var object = {valueOf: function() {return {}}, toString: function() {return "^"}}; encodeURIComponent(object) === "%5E". Actual: ' + (encodeURIComponent(object)));
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#7
|
|
|
|
try {
|
2018-02-15 21:50:18 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return "^"
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
throw "error"
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
encodeURIComponent(object);
|
2021-07-21 21:37:52 +02:00
|
|
|
throw new Test262Error('#7.1: var object = {valueOf: function() {return "^"}, toString: function() {throw "error"}}; encodeURIComponent(object) throw "error". Actual: ' + (encodeURIComponent(object)));
|
2017-06-29 19:45:58 +02:00
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
catch (e) {
|
|
|
|
if (e !== "error") {
|
2021-07-21 21:37:52 +02:00
|
|
|
throw new Test262Error('#7.2: var object = {valueOf: function() {return "^"}, toString: function() {throw "error"}}; encodeURIComponent(object) throw "error". Actual: ' + (e));
|
2017-06-29 19:45:58 +02:00
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#8
|
|
|
|
try {
|
2018-02-15 21:50:18 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return {}
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
encodeURIComponent(object);
|
2021-07-21 21:37:52 +02:00
|
|
|
throw new Test262Error('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; encodeURIComponent(object) throw TypeError. Actual: ' + (encodeURIComponent(object)));
|
2017-06-29 19:45:58 +02:00
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
catch (e) {
|
|
|
|
if ((e instanceof TypeError) !== true) {
|
2021-07-21 21:37:52 +02:00
|
|
|
throw new Test262Error('#8.2: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; encodeURIComponent(object) throw TypeError. Actual: ' + (e));
|
2017-06-29 19:45:58 +02:00
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|