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 17:10:43 +02:00
|
|
|
esid: sec-parseint-string-radix
|
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:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
};
|
2020-09-18 18:06:50 +02:00
|
|
|
assert.sameValue(parseInt(object), NaN, 'parseInt({valueOf: function() {return 1}}) must return NaN');
|
2011-09-07 08:35:18 +02:00
|
|
|
|
|
|
|
//CHECK#2
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return 1
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
};
|
2020-09-18 18:06:50 +02:00
|
|
|
|
|
|
|
assert.sameValue(
|
|
|
|
parseInt(object),
|
|
|
|
0,
|
|
|
|
'parseInt({valueOf: function() {return 1}, toString: function() {return 0}}) must return 0'
|
|
|
|
);
|
2011-09-07 08:35:18 +02:00
|
|
|
|
|
|
|
//CHECK#3
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return 1
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
};
|
2020-09-18 18:06:50 +02:00
|
|
|
|
|
|
|
assert.sameValue(
|
|
|
|
parseInt(object),
|
|
|
|
1,
|
|
|
|
'parseInt({valueOf: function() {return 1}, toString: function() {return {}}}) must return 1'
|
|
|
|
);
|
2011-09-07 08:35:18 +02:00
|
|
|
|
|
|
|
//CHECK#4
|
|
|
|
try {
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
throw "error"
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
};
|
2020-09-18 18:06:50 +02:00
|
|
|
|
|
|
|
assert.sameValue(
|
|
|
|
parseInt(object),
|
|
|
|
1,
|
|
|
|
'parseInt({valueOf: function() {throw \\"error\\"}, toString: function() {return 1}}) must return 1'
|
|
|
|
);
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|
|
|
|
catch (e) {
|
2020-09-18 18:06:50 +02:00
|
|
|
assert.notSameValue(e, "error", 'The value of `e` is not "error"');
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//CHECK#5
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
toString: function() {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
};
|
2020-09-18 18:06:50 +02:00
|
|
|
assert.sameValue(parseInt(object), 1, 'parseInt({toString: function() {return 1}}) must return 1');
|
2011-09-07 08:35:18 +02:00
|
|
|
|
|
|
|
//CHECK#6
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return {}
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
2020-09-18 18:06:50 +02:00
|
|
|
|
|
|
|
assert.sameValue(
|
|
|
|
parseInt(object),
|
|
|
|
1,
|
|
|
|
'parseInt({valueOf: function() {return {}}, toString: function() {return 1}}) must return 1'
|
|
|
|
);
|
2011-09-07 08:35:18 +02:00
|
|
|
|
|
|
|
//CHECK#7
|
|
|
|
try {
|
2018-02-15 21:12:07 +01:00
|
|
|
var object = {
|
|
|
|
valueOf: function() {
|
|
|
|
return 1
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
|
|
throw "error"
|
|
|
|
}
|
|
|
|
};
|
2011-09-07 08:35:18 +02:00
|
|
|
parseInt(object);
|
2020-09-18 18:06:50 +02:00
|
|
|
Test262Error.thrower('#7.1: var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; parseInt(object) throw "error". Actual: ' + (parseInt(object)));
|
2017-06-29 17:10:43 +02:00
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
catch (e) {
|
2020-09-18 18:06:50 +02:00
|
|
|
assert.sameValue(e, "error", 'The value of `e` is "error"');
|
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(object);
|
2020-09-18 18:06:50 +02:00
|
|
|
Test262Error.thrower('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; parseInt(object) throw TypeError. Actual: ' + (parseInt(object)));
|
2017-06-29 17:10:43 +02:00
|
|
|
}
|
2011-09-07 08:35:18 +02:00
|
|
|
catch (e) {
|
2020-09-18 18:06:50 +02:00
|
|
|
assert.sameValue(e instanceof TypeError, true, 'The result of `(e instanceof TypeError)` is true');
|
2011-09-07 08:35:18 +02:00
|
|
|
}
|