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 ToNumber
|
2014-07-25 00:41:42 +02:00
|
|
|
es5id: 15.1.2.2_A3.1_T7
|
2017-06-29 17:10:43 +02:00
|
|
|
es6id: 18.2.5
|
|
|
|
esid: sec-parseint-string-radix
|
2014-07-22 01:09:02 +02:00
|
|
|
description: If Type(value) is Object, evaluate ToPrimitive(value, Number)
|
|
|
|
---*/
|
2011-09-07 08:35:18 +02:00
|
|
|
|
|
|
|
//CHECK#1
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
if (parseInt("11", object) !== parseInt("11", 2)) {
|
|
|
|
$ERROR('#1: var object = {valueOf: function() {return 2}}; parseInt("11", object) === parseInt("11", 2). Actual: ' + (parseInt("11", object)));
|
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#2
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return 2
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
if (parseInt("11", object) !== parseInt("11", 2)) {
|
|
|
|
$ERROR('#2: var object = {valueOf: function() {return 2}, toString: function() {return 1}}; parseInt("11", object) === parseInt("11", 2). Actual: ' + (parseInt("11", object)));
|
2017-06-29 17:10:43 +02:00
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
|
|
|
|
//CHECK#3
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return 2
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
if (parseInt("11", object) !== parseInt("11", 2)) {
|
|
|
|
$ERROR('#3: var object = {valueOf: function() {return 2}, toString: function() {return {}}}; parseInt("11", object) === parseInt("11", 2). Actual: ' + (parseInt("11", object)));
|
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#4
|
|
|
|
try {
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return 2
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
throw "error"
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
if (parseInt("11", object) !== parseInt("11", 2)) {
|
|
|
|
$ERROR('#4.1: var object = {valueOf: function() {return 2}, toString: function() {throw "error"}}; parseInt("11", object) === parseInt("11", 2). Actual: ' + (parseInt("11", object)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
if (e === "error") {
|
|
|
|
$ERROR('#4.2: var object = {valueOf: function() {return 2}, toString: function() {throw "error"}}; parseInt("11", object) not throw "error"');
|
|
|
|
} else {
|
|
|
|
$ERROR('#4.3: var object = {valueOf: function() {return 2}, toString: function() {throw "error"}}; parseInt("11", object) not throw Error. Actual: ' + (e));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#5
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
toString: function() {
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
if (parseInt("11", object) !== parseInt("11", 2)) {
|
|
|
|
$ERROR('#5: var object = {toString: function() {return 2}}; parseInt("11", object) === parseInt("11", 2). Actual: ' + (parseInt("11", object)));
|
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#6
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return {}
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
if (parseInt("11", object) !== parseInt("11", 2)) {
|
|
|
|
$ERROR('#6: var object = {valueOf: function() {return {}}, toString: function() {return 2}}; parseInt("11", object) === parseInt("11", 2). Actual: ' + (parseInt("11", object)));
|
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#7
|
|
|
|
try {
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
throw "error"
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
parseInt("11", object);
|
|
|
|
$ERROR('#7.1: var object = {valueOf: function() {throw "error"}, toString: function() {return 2}}; parseInt("11", object) throw "error". Actual: ' + (parseInt("11", object)));
|
2017-06-29 17:10:43 +02:00
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
catch (e) {
|
|
|
|
if (e !== "error") {
|
|
|
|
$ERROR('#7.2: var object = {valueOf: function() {throw "error"}, toString: function() {return 2}}; parseInt("11", object) throw "error". Actual: ' + (e));
|
2017-06-29 17:10:43 +02:00
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#8
|
|
|
|
try {
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return {}
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
parseInt("11", object);
|
|
|
|
$ERROR('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; parseInt("11", object) throw TypeError. Actual: ' + (parseInt("11", object)));
|
2017-06-29 17:10:43 +02:00
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
catch (e) {
|
|
|
|
if ((e instanceof TypeError) !== true) {
|
|
|
|
$ERROR('#8.2: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; parseInt("11", object) throw TypeError. Actual: ' + (e));
|
2017-06-29 17:10:43 +02:00
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|