ysmood / yaku

A lightweight promise library
https://tonicdev.com/ysmood/yaku
MIT License
291 stars 28 forks source link

Incorrect testcases #29

Closed hax closed 8 years ago

hax commented 8 years ago

See my comments in https://github.com/ysmood/yaku/commit/0383fa02e711eec363b85c299a45004986ecb249

ysmood commented 8 years ago

Don't worry about the Symbol, the comparison graph is based on Node v5.0+, and will always use the lastest version of Node.

ysmood commented 8 years ago

The readme is updated. You lib passed all tests. Thanks for your report.

hax commented 8 years ago

Test case "subclass PromiseCapability promise.then TypeError" is still incorrect. It should not throw error. To throw error you need to specify Symbol.species for fake constructor 😈

ysmood commented 8 years ago

But, I read the https://tc39.github.io/ecma262/#sec-newpromisecapability

If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception.

The newly created promiseCapability should have a resolve handler.

hax commented 8 years ago

The test case call promise.then(function () {}) with promise.constructor = function () {}.

See 25.4.5.3 Promise.prototype.then

3 . Let C be ? SpeciesConstructor(promise, %Promise%).

Step 3 passes promise with %Promise% (the original Promise constructor) as defaultConstructor

See 7.3.20 SpeciesConstructor

  1. Assert: Type(O) is Object.
  2. Let C be ? Get(O, "constructor").
  3. If C is undefined, return defaultConstructor.
  4. If Type(C) is not Object, throw a TypeError exception.
  5. Let S be ? Get(C, @@species).
  6. If S is either undefined or null, return defaultConstructor.
  7. If IsConstructor(S) is true, return S.
  8. Throw a TypeError exception.

Step 2: C = function () {} Step 5: S = undefined Step 6: return %Promise%

Then NewPromiseCapability is called with original Promise constructor.

ysmood commented 8 years ago

You are right, I added a global Symbol.species to make the test possible: https://github.com/ysmood/yaku/commit/ccd5a01646641625d53abac2950ea26c2c190c22#diff-e2686e2925145c11799d638b2f4706dcR8

But I don't know why my-promise still has 1 failure:

$ npm run no -- test-basic -s my-promise

junit cli > x basic - subclass (21ms)

  <<<<<<< actual
  [ 'subclass',
    undefined,
    'subclass',
    undefined,
    'subclass',
    true,
    true,
    5,
    6 ]
  =======
  [ 'subclass',
    'subclass',
    'subclass',
    'subclass',
    'subclass',
    true,
    true,
    5,
    6 ]
  >>>>>>> expected

  Error: Assertion
hax commented 8 years ago

I will check it later.