Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise.prototype.finally: add missing tests #1398

Merged
merged 1 commit into from
Jan 25, 2018

Conversation

ljharb
Copy link
Member

@ljharb ljharb commented Jan 25, 2018

Per:

Closes #866.

cc @gsathya, do you think these tests are correct? v8 fails 12 of them.

var p = Promise.reject().finally(() => FooPromise.reject());

assert.sameValue(p instanceof Promise, true);
assert.sameValue(p instanceof FooPromise, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be false because .then() in Step 7 of Promise.prototype.finally is called on the receiver of finally which is Promise.

}

FooPromise.reject().finally(() => {}).then($DONE).catch(() => {
assert.sameValue(6, count);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 7 -- the first 6 promises are created same as the below test and +1 for the extra .catch()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aha, thanks

var p = Promise.resolve().finally(() => FooPromise.resolve());

assert.sameValue(p instanceof Promise, true);
assert.sameValue(p instanceof FooPromise, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be false, same as above test

@ljharb
Copy link
Member Author

ljharb commented Jan 25, 2018

Thanks! With your feedback, the failures drop to 8 in latest node :-)

var oldThen = Promise.prototype.then;
Promise.prototype.then = () => { called = true; };
Promise.prototype.finally.call(p);
assertTrue(called);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be assert.sameValue(called, true);

@gsathya
Copy link
Member

gsathya commented Jan 25, 2018

the failures drop to 8 in latest node :-)

Can you list the failing tests? All the 5 new tests pass for me locally:

➜  v8 (31cde0ee36) ✗ tools/run-tests.py --gn test262/built-ins/Promise/prototype/finally/this-value-non-promise
>>> Latest GN build found: x64.optdebug
Build found: /Users/gunasekaran/code/v8/out.gn/x64.optdebug
>>> Running tests for x64.debug
>>> Running with test processors
>>> Running 1 base tests
[00:00|% 100|+   2|-   0]: Done
>>> 2 tests ran
➜  v8 (31cde0ee36) ✗ tools/run-tests.py --gn test262/built-ins/Promise/prototype/finally/subclass-species-constructor-reject-count
>>> Latest GN build found: x64.optdebug
Build found: /Users/gunasekaran/code/v8/out.gn/x64.optdebug
>>> Running tests for x64.debug
>>> Running with test processors
>>> Running 1 base tests
[00:00|% 100|+   2|-   0]: Done
>>> 2 tests ran
➜  v8 (31cde0ee36) ✗ tools/run-tests.py --gn test262/built-ins/Promise/prototype/finally/subclass-species-constructor-resolve-count
>>> Latest GN build found: x64.optdebug
Build found: /Users/gunasekaran/code/v8/out.gn/x64.optdebug
>>> Running tests for x64.debug
>>> Running with test processors
>>> Running 1 base tests
[00:00|% 100|+   2|-   0]: Done
>>> 2 tests ran
➜  v8 (31cde0ee36) ✗ tools/run-tests.py --gn test262/built-ins/Promise/prototype/finally/subclass-resolve-count
>>> Latest GN build found: x64.optdebug
Build found: /Users/gunasekaran/code/v8/out.gn/x64.optdebug
>>> Running tests for x64.debug
>>> Running with test processors
>>> Running 1 base tests
[00:00|% 100|+   2|-   0]: Done
>>> 2 tests ran
➜  v8 (31cde0ee36) ✗ tools/run-tests.py --gn test262/built-ins/Promise/prototype/finally/subclass-reject-count
>>> Latest GN build found: x64.optdebug
Build found: /Users/gunasekaran/code/v8/out.gn/x64.optdebug
>>> Running tests for x64.debug
>>> Running with test processors
>>> Running 1 base tests
[00:00|% 100|+   2|-   0]: Done
>>> 2 tests ran

@ljharb
Copy link
Member Author

ljharb commented Jan 25, 2018

Sure, with the latest update:

$ node --version
v9.4.0
$ npx test262-harness --hostType=node --hostPath=`which node` --hostArgs="--harmony-promise-finally" test/built-ins/Promise/prototype/finally/*
FAIL test/built-ins/Promise/prototype/finally/species-constructor.js
  Test did not run to completion

FAIL test/built-ins/Promise/prototype/finally/species-constructor.js
  Test did not run to completion

FAIL test/built-ins/Promise/prototype/finally/subclass-reject-count.js
  Test did not run to completion

FAIL test/built-ins/Promise/prototype/finally/subclass-reject-count.js
  Test did not run to completion

FAIL test/built-ins/Promise/prototype/finally/subclass-resolve-count.js
  Test did not run to completion

FAIL test/built-ins/Promise/prototype/finally/subclass-resolve-count.js
  Test did not run to completion

FAIL test/built-ins/Promise/prototype/finally/this-value-non-promise.js
  Expected no error, got TypeError: Method Promise.prototype.finally called on incompatible receiver [object Object]

FAIL test/built-ins/Promise/prototype/finally/this-value-non-promise.js
  Expected no error, got TypeError: Method Promise.prototype.finally called on incompatible receiver [object Object]

Ran 46 tests
38 passed
8 failed

@gsathya
Copy link
Member

gsathya commented Jan 25, 2018

FAIL test/built-ins/Promise/prototype/finally/this-value-non-promise.js
Expected no error, got TypeError: Method Promise.prototype.finally called on incompatible receiver [object Object]

FAIL test/built-ins/Promise/prototype/finally/this-value-non-promise.js
Expected no error, got TypeError: Method Promise.prototype.finally called on incompatible receiver [object Object]

I fixed this recently in V8 (~month ago) so may be node v9 doesn't have the fix.

I'm not sure about the rest. They all run to completion (and pass the test) in V8 for me locally. In fact, I have these tests checked in to V8 already here:
https://cs.chromium.org/chromium/src/v8/test/mjsunit/harmony/promise-prototype-finally.js?l=545

I wonder if it's something to do with the harness.

Copy link
Member

@gsathya gsathya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this in the earlier review

@@ -22,4 +22,4 @@ new FooPromise(r => r())
.then(() => {
assert.sameValue(count, 6, "6 new promises were created");
$DONE();
});
}, $DONE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be $ERROR because we shouldn't be catching anything

}
}

FooPromise.reject().finally(() => {}).then($DONE).catch(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The then callback should take $ERROR as resolving would pass the test silently

FooPromise.resolve().finally(() => {}).then(() => {
assert.sameValue(6, count);
$DONE();
}, $DONE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, the catch callback should be $ERROR

@gsathya
Copy link
Member

gsathya commented Jan 25, 2018

Thanks @ljharb 💯

@rwaldron
Copy link
Contributor

@ljharb these are awesome. Thanks @gsathya for working through the review!

@rwaldron rwaldron merged commit 7c5b5bf into tc39:master Jan 25, 2018
@ljharb ljharb deleted the finally_redux branch January 25, 2018 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants