Skip to content

Commit

Permalink
Number#{toFixed, toPrecision} thisNumberValue fails in old V8 ~ A…
Browse files Browse the repository at this point in the history
…ndroid 4.3-
  • Loading branch information
zloirock committed Feb 1, 2016
1 parent e79398e commit d49f103
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 32 deletions.
5 changes: 5 additions & 0 deletions library/modules/_a-number-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var cof = require('./_cof');
module.exports = function(it, msg){
if(typeof it != 'number' && cof(it) != 'Number')throw TypeError(msg);
return +it;
};
29 changes: 16 additions & 13 deletions library/modules/es6.number.to-fixed.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';
var $export = require('./_export')
, cof = require('./_cof')
, anInstance = require('./_an-instance')
, toInteger = require('./_to-integer')
, repeat = require('./_string-repeat')
, floor = Math.floor
, data = [0, 0, 0, 0, 0, 0]
, ERROR = 'Number.toFixed: incorrect invocation!'
, ZERO = '0';
var $export = require('./_export')
, anInstance = require('./_an-instance')
, toInteger = require('./_to-integer')
, aNumberValue = require('./_a-number-value')
, repeat = require('./_string-repeat')
, $toFixed = 1..toFixed
, floor = Math.floor
, data = [0, 0, 0, 0, 0, 0]
, ERROR = 'Number.toFixed: incorrect invocation!'
, ZERO = '0';

var multiply = function(n, c){
var i = -1
Expand Down Expand Up @@ -53,15 +54,17 @@ var log = function(x){
} return n;
};

$export($export.P + $export.F * (!!1..toFixed && (
$export($export.P + $export.F * (!!$toFixed && (
0.00008.toFixed(3) !== '0.000' ||
0.9.toFixed(0) !== '1' ||
1.255.toFixed(2) !== '1.25' ||
1000000000000000128..toFixed(0) !== '1000000000000000128'
)), 'Number', {
) || !require('./_fails')(function(){
// V8 ~ Android 4.3-
$toFixed.call({});
})), 'Number', {
toFixed: function toFixed(fractionDigits){
if(typeof this != 'number' && cof(this) != 'Number')throw TypeError(ERROR);
var x = +this
var x = aNumberValue(this, ERROR)
, f = toInteger(fractionDigits)
, s = ''
, m = ZERO
Expand Down
13 changes: 10 additions & 3 deletions library/modules/es6.number.to-precision.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
'use strict';
var $export = require('./_export')
, $fails = require('./_fails')
, aNumberValue = require('./_a-number-value')
, $toPrecision = 1..toPrecision;

$export($export.P + $export.F * require('./_fails')(function(){
$export($export.P + $export.F * ($fails(function(){
// IE7-
return $toPrecision.call(1, undefined) !== '1';
}), 'Number', {
}) || !$fails(function(){
// V8 ~ Android 4.3-
$toPrecision.call({});
})), 'Number', {
toPrecision: function toPrecision(precision){
return precision === undefined ? $toPrecision.call(this) : $toPrecision.call(this, precision);
var that = aNumberValue(this, 'Number#toPrecision: incorrect invocation!');
return precision === undefined ? $toPrecision.call(that) : $toPrecision.call(that, precision);
}
});
5 changes: 5 additions & 0 deletions modules/_a-number-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var cof = require('./_cof');
module.exports = function(it, msg){
if(typeof it != 'number' && cof(it) != 'Number')throw TypeError(msg);
return +it;
};
29 changes: 16 additions & 13 deletions modules/es6.number.to-fixed.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';
var $export = require('./_export')
, cof = require('./_cof')
, anInstance = require('./_an-instance')
, toInteger = require('./_to-integer')
, repeat = require('./_string-repeat')
, floor = Math.floor
, data = [0, 0, 0, 0, 0, 0]
, ERROR = 'Number.toFixed: incorrect invocation!'
, ZERO = '0';
var $export = require('./_export')
, anInstance = require('./_an-instance')
, toInteger = require('./_to-integer')
, aNumberValue = require('./_a-number-value')
, repeat = require('./_string-repeat')
, $toFixed = 1..toFixed
, floor = Math.floor
, data = [0, 0, 0, 0, 0, 0]
, ERROR = 'Number.toFixed: incorrect invocation!'
, ZERO = '0';

var multiply = function(n, c){
var i = -1
Expand Down Expand Up @@ -53,15 +54,17 @@ var log = function(x){
} return n;
};

$export($export.P + $export.F * (!!1..toFixed && (
$export($export.P + $export.F * (!!$toFixed && (
0.00008.toFixed(3) !== '0.000' ||
0.9.toFixed(0) !== '1' ||
1.255.toFixed(2) !== '1.25' ||
1000000000000000128..toFixed(0) !== '1000000000000000128'
)), 'Number', {
) || !require('./_fails')(function(){
// V8 ~ Android 4.3-
$toFixed.call({});
})), 'Number', {
toFixed: function toFixed(fractionDigits){
if(typeof this != 'number' && cof(this) != 'Number')throw TypeError(ERROR);
var x = +this
var x = aNumberValue(this, ERROR)
, f = toInteger(fractionDigits)
, s = ''
, m = ZERO
Expand Down
13 changes: 10 additions & 3 deletions modules/es6.number.to-precision.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
'use strict';
var $export = require('./_export')
, $fails = require('./_fails')
, aNumberValue = require('./_a-number-value')
, $toPrecision = 1..toPrecision;

$export($export.P + $export.F * require('./_fails')(function(){
$export($export.P + $export.F * ($fails(function(){
// IE7-
return $toPrecision.call(1, undefined) !== '1';
}), 'Number', {
}) || !$fails(function(){
// V8 ~ Android 4.3-
$toPrecision.call({});
})), 'Number', {
toPrecision: function toPrecision(precision){
return precision === undefined ? $toPrecision.call(this) : $toPrecision.call(this, precision);
var that = aNumberValue(this, 'Number#toPrecision: incorrect invocation!');
return precision === undefined ? $toPrecision.call(that) : $toPrecision.call(that, precision);
}
});

0 comments on commit d49f103

Please sign in to comment.