1
|
'use strict';
|
2
|
|
3
|
var GetIntrinsic = require('../GetIntrinsic');
|
4
|
|
5
|
var $Math = GetIntrinsic('%Math%');
|
6
|
|
7
|
var ToNumber = require('./ToNumber');
|
8
|
var $isNaN = require('../helpers/isNaN');
|
9
|
var $isFinite = require('../helpers/isFinite');
|
10
|
var $sign = require('../helpers/sign');
|
11
|
|
12
|
var $floor = $Math.floor;
|
13
|
var $abs = $Math.abs;
|
14
|
|
15
|
// http://www.ecma-international.org/ecma-262/5.1/#sec-9.4
|
16
|
|
17
|
module.exports = function ToInteger(value) {
|
18
|
var number = ToNumber(value);
|
19
|
if ($isNaN(number)) { return 0; }
|
20
|
if (number === 0 || !$isFinite(number)) { return number; }
|
21
|
return $sign(number) * $floor($abs(number));
|
22
|
};
|