Skip to content

Commit

Permalink
Add a skipped test for a Number caveat when [[Call]]ed with a `Nu…
Browse files Browse the repository at this point in the history
…mber` instance as the receiver.

Closes #365.
  • Loading branch information
ljharb committed Oct 22, 2015
1 parent 238c77a commit 1327dcc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,14 @@ Promise.resolve(5).then(function (value) {
## Caveats
- `Object.setPrototypeOf` / `Reflect.setPrototypeOf`
- `Object.setPrototypeOf` / `Reflect.setPrototypeOf`
- Note that null objects (`Object.create(null)`, eg, an object with `null` as its `[[Prototype]]`) can not have their `[[Prototype]]` changed except via a native `Object.setPrototypeOf`.
- `Number`:
- In order to support binary literals (`Number('0b1')`) and octal literals (`Number('0o7')`), the global `Number` constructor is wrapped in a shim. However, this can cause issues in the exceedingly unlikely event that you ever call `Number` as a function with a receiver (a “this” value) that is itself a number. Some problematic examples:
```js
assert(typeof Number.call(2, 3) === 'number'); // will fail when `Number` is wrapped, is "object"
assert(typeof (1).constructor(2) === 'number'); // will fail when `Number` is wrapped, is "object"
```
## [License][license-url]
Expand Down
9 changes: 8 additions & 1 deletion test/number.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global describe, it, expect, require */
/* global describe, it, xit, expect, require */

describe('Number', function () {
var functionsHaveNames = (function foo() {}).name === 'foo';
Expand Down Expand Up @@ -338,6 +338,13 @@ describe('Number', 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);
});

it('works with boxed primitives', function () {
expect(1 instanceof Number).to.equal(false);
expect(Object(1) instanceof Number).to.equal(true);
Expand Down

0 comments on commit 1327dcc

Please sign in to comment.