Skip to content

Commit

Permalink
fix new detection in Number constructor, close #89, babel/babel#1927
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jul 5, 2015
1 parent c7b2eac commit f047bbc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion library/modules/es6.number.constructor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
var $ = require('./$')
, cof = require('./$.cof')
, isObject = $.isObject
, isFunction = $.isFunction
, NUMBER = 'Number'
Expand All @@ -24,7 +25,7 @@ function toNumber(it){
}
if($.FW && !($Number('0o1') && $Number('0b1'))){
$Number = function Number(it){
return this instanceof $Number ? new Base(toNumber(it)) : toNumber(it);
return this instanceof $Number && cof(this) != NUMBER ? new Base(toNumber(it)) : toNumber(it);
};
$.each.call($.DESC ? $.getNames(Base) : (
// ES3:
Expand Down
3 changes: 2 additions & 1 deletion modules/es6.number.constructor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
var $ = require('./$')
, cof = require('./$.cof')
, isObject = $.isObject
, isFunction = $.isFunction
, NUMBER = 'Number'
Expand All @@ -24,7 +25,7 @@ function toNumber(it){
}
if($.FW && !($Number('0o1') && $Number('0b1'))){
$Number = function Number(it){
return this instanceof $Number ? new Base(toNumber(it)) : toNumber(it);
return this instanceof $Number && cof(this) != NUMBER ? new Base(toNumber(it)) : toNumber(it);
};
$.each.call($.DESC ? $.getNames(Base) : (
// ES3:
Expand Down
4 changes: 3 additions & 1 deletion tests/tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/tests/es6.number.constructor.ls
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ test 'Number constructor: regression' !->

for <[MAX_VALUE MIN_VALUE NaN NEGATIVE_INFINITY POSITIVE_INFINITY]>
ok .. of Number, "#{..} in Number"

n = new Number 42
eq typeof n@@(n), \number

test 'Number constructor: binary' !->
check \0b1, 1
Expand Down

0 comments on commit f047bbc

Please sign in to comment.