Skip to content

Commit

Permalink
Uncomment most of the Number constructor [[Call]] tests.
Browse files Browse the repository at this point in the history
See #365.
  • Loading branch information
ljharb committed Oct 23, 2015
1 parent 1327dcc commit d29ccaa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
12 changes: 8 additions & 4 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1166,12 +1166,16 @@
primValue = parseInt(_strSlice(primValue, 2), 8);
}
}
if (this instanceof Number) {
return new OrigNumber(primValue);
}
var receiver = this;
/* jshint newcap: false */
return OrigNumber(primValue);
var prim = OrigNumber(primValue);
/* jshint newcap: true */
if (receiver instanceof Number && !valueOrFalseIfThrows(function () {
return Number.prototype.valueOf.call(receiver) !== prim;
})) {
return new OrigNumber(primValue);
}
return prim;
};
}());
wrapConstructor(OrigNumber, NumberShim, {});
Expand Down
22 changes: 17 additions & 5 deletions test/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,28 @@ describe('Number', function () {
expect(Number('1.1')).to.equal(+'1.1');
expect(Number('0xA')).to.equal(0xA);
});
});

describe('constructor', function () {
it('behaves like the builtin', function () {
expect((1).constructor).to.equal(Number);
});

xit('returns a primitive when called with a receiver', function () {
expect((1).constructor(2)).to.equal(2);
expect(Object(1).constructor(3)).to.equal(3);
expect(Object(1).constructor.apply(null, 4)).to.equal(4);
expect(Object(1).constructor.apply(Object(1).constructor, 5)).to.equal(5);
describe('when called with a receiver', function () {
it('returns a primitive when called with a primitive receiver', function () {
expect((1).constructor(2)).to.equal(2);
expect((1).constructor.call(null, 3)).to.equal(3);
expect(Object(1).constructor.call(null, 5)).to.equal(5);
});

it('returns a primitive when called with a different number as an object receiver', function () {
expect(Object(1).constructor(6)).to.equal(6);
expect(Object(1).constructor.call(Object(1), 7)).to.equal(7);
});

xit('returns a primitive when called with the same number as an object receiver', function () {
expect(Object(1).constructor.call(Object(8), 8)).to.equal(8);
});
});

it('works with boxed primitives', function () {
Expand Down

0 comments on commit d29ccaa

Please sign in to comment.