Comments (21)
The question is, can resolveElement2 synchronously call afterAll (since it is running in the PromisesTask handler, not from user code) or must it enqueue the call to afterAll?
You can never synchronously call a promise handler; they are always called via TriggerPromiseReactions which enqueues tasks to call them.
from native-promise-only.
Just to make that clear, you're saying that when resolveElement2
discovers that the the parent promise is resolvable and calls [[Resolve]]
, this will cause a call to afterAll to be enqueued, and the correct observed call sequence should be (afterOne
, afterTwo
, afterAll
)
And that this sequence is required by the spec.
(edited to add: I'm not trying to be pedantic, I just want to make sure I have the observables right, because my reasoning could be in error about the other things -- including whether a synchronous call is what causes this.)
from native-promise-only.
Yes. You can also check against the reference implementation, if that would help.
from native-promise-only.
Thanks.
I can see that the sequencing behavior of v8 faithfully reproduces the sequencing behavior of the reference implementation. Changed the tests to reflect expected sequencing behavior.
from native-promise-only.
So the conclusion is that NPO has a bug in Promise. all, correct?
from native-promise-only.
Yes, and also Promise.race.
I think it's actually the scheduler, but I haven't gone into the code yet.
from native-promise-only.
I'll jump on it.
from native-promise-only.
should be fixed now I think. I was being too aggressive with perf optimizations ☺
from native-promise-only.
That causes the Promise.all tests to pass, but not the Promise.race tests. I glanced at the NPO code and didn't see the problem, so my natural inclination is to blame the tests. Will do some more checking.
from native-promise-only.
The test I used for race(..)
was to take the test for all(..)
you provided and just swap in race(..)
. If that's not the same test, can you please let me know what's different and I can check it out to see?
from native-promise-only.
Hm.. what version of node are you running? I just noticed that for NPO the race(...)
tests succeed in 0.11.13 and fail in 0.10.29, which is not a happy result. I am only able to test v8 Promises using node 0.11.13.
This is the command I am using to run the race tests:
node test/cli.js test_adapter.js --grep "25.4.4.3 Promise.race with 2-element array"
And the result:
12 passing (86ms)
1 pending
2 failing
1) 25.4.4.3 Promise.race with 2-element array should fulfill immediately with first fulfilled promise in array:
Error: done() invoked with non-Error: 2
at /home/smikes/src/github/native-promise-only/node_modules/mocha/lib/runnable.js:198:38
at notifyIsolated (/home/smikes/src/github/native-promise-only/lib/npo.src.js:120:19)
at MakeDef.notify (/home/smikes/src/github/native-promise-only/lib/npo.src.js:106:4)
at schedule (/home/smikes/src/github/native-promise-only/lib/npo.src.js:72:7)
at MakeDef.reject (/home/smikes/src/github/native-promise-only/lib/npo.src.js:188:3)
at Object.publicReject [as reject] (/home/smikes/src/github/native-promise-only/lib/npo.src.js:277:13)
at notifyIsolated (/home/smikes/src/github/native-promise-only/lib/npo.src.js:116:11)
at MakeDef.notify (/home/smikes/src/github/native-promise-only/lib/npo.src.js:106:4)
at schedule (/home/smikes/src/github/native-promise-only/lib/npo.src.js:72:7)
at MakeDef.reject (/home/smikes/src/github/native-promise-only/lib/npo.src.js:188:3)
2) 25.4.4.3 Promise.race with 2-element array should reject immediately when second rejects:
Error: Unexpected resolve 1
at /home/smikes/src/github/native-promise-only/test/tests/race.js:151:10
at notifyIsolated (/home/smikes/src/github/native-promise-only/lib/npo.src.js:120:19)
at MakeDef.notify (/home/smikes/src/github/native-promise-only/lib/npo.src.js:106:4)
at Object.drain [as _onImmediate] (/home/smikes/src/github/native-promise-only/lib/npo.src.js:60:11)
at processImmediate [as _immediateCallback] (timers.js:336:15)
from native-promise-only.
NPO doesn't run in 0.11.13, because it's a polyfill, and in 0.11, Promise
already exists, so it just skips over itself. So I believe you're probably testing the native Promise
.
I am running 10.29, and my race(..)
test passes. I haven't looked at your branch yet. Can you past a minimal breaking test in 10.29 here so I can diagnose?
from native-promise-only.
Oh. Hahahaha. Of course.
I will create a small breaking test.
from native-promise-only.
Confirmed that node version doesn't matter by modifying the test_adapter to remove global.Promise before loading NPO. I am surprised that node 0.11 has global.Promise even if I don't pass --harmony on the command line.
Anyway, a failing test:
it("should reject immediately when second rejects", function(done) {
var resolveP1, rejectP2,
p1 = new Promise(function(resolve, reject) {
resolveP1 = resolve;
}),
p2 = new Promise(function(resolve, reject) {
rejectP2 = reject;
});
Promise.race([p1, p2]).then(function(resolved) {
throw new Error("Unexpected resolve " + resolved);
}, function(rejected) {
assert.equal(rejected, 2);
}).then(done).catch(done);
rejectP2(2);
resolveP1(1);
});
from native-promise-only.
And the other failing test:
it("should fulfill immediately with first fulfilled promise in array", function(done) {
var resolveP1, rejectP2,
p1 = new Promise(function(resolve, reject) {
resolveP1 = resolve;
}),
p2 = new Promise(function(resolve, reject) {
rejectP2 = reject;
});
rejectP2(2);
resolveP1(1);
Promise.race([p1, p2]).then(function(resolved) {
assert.equal(resolved, 1);
}).then(done).catch(done);
});
from native-promise-only.
See promises-aplus/promises-tests#61
Notice that I reduced the test cases to actually have nothing to do with all(..)
and race(..)
. It's actually about scheduling sequencing between different promises, which is a very interesting (and troubling) case indeed.
Based on my analysis, I believe your first test case is correct (which I've diagnosed in NPO and have a fix for), but I believe your second test case is incorrect.
If I'm correct, and your second test should be 2
instead of 1
, that means that this has actually found another bug in v8, because v8 results in 1
.
Moreover, that linked issue thread raises the question that these are bugs which should have tests in promises/a+, because I believe that spec (and its test suite) should handle and enforce implied inter-promise scheduling semantics, not just intra-promise semantics.
So, your all(..)
and race(..)
tests, which are _also_ checking sequencing semantics, may or may not be appropriate for this test suite, depending on whether or not promises/a+ adds tests to enforce inter-promise sequencing. OTOH, they may be useful only for testing all(..)
and race(..)
independently of any promise sequencing. Not really sure. My brain hurts now.
[update: my bad, see message below]
from native-promise-only.
My brain hurts now.
Neuralgia is a known side effect of open-source developmen
I will port your simplified tests to @domenic 's reference implementation and note the results.
from native-promise-only.
OK, so both @smikes' test cases were correct, and I was misunderstanding how to think about scheduling vs. resolution/rejection. I have corrected NPO in v0.7.0-a to use the correct scheduling behavior (at least, I believe), and it passes both tests as shown above.
from native-promise-only.
Ah, schneaky. The "race" was between scheduling the execution and subsequently adding a handler to the execution chain.
from native-promise-only.
I do think we should have tests of the sequencing (like my simplified versions) and tests with race(..)
and all(..)
(like your versions). It would trouble me if we made assumptions about one set covering the other or vice versa.
from native-promise-only.
Agreed. I can add those easily. They exercise the scheduler directly; while the race(...)
test depends on scheduling, formally what it's testing is the mechanism of single settlement on an aggregate promise.
from native-promise-only.
Related Issues (20)
- browsers support information HOT 7
- Cross-Browser Support & Tests HOT 3
- Support IE8 HOT 5
- What is correct execution sequence when attach multiple handlers to the same promise. HOT 8
- Better native support detection? HOT 3
- Create tag for v0.7.6-a HOT 1
- Android 4.0 issue HOT 17
- AMD? HOT 19
- handling uncaught exceptions HOT 5
- Promise.resolve(1) throws on Android 4.0 HOT 1
- `resolve(..)` should call a thenable's `then(..)` async, not sync. HOT 5
- Unhandled rejection detection HOT 9
- Suggestion: make Promise.prototype aliases of `then` and `catch` HOT 5
- Error when running through babel compiler HOT 5
- Module with unminified code should be exported by default
- on nodejs, exceptions are not shown. HOT 4
- Microtasks? HOT 1
- Ponyfill support? HOT 1
- Missing tag for version 0.7.8-a used by jQuery HOT 7
- Promise finally not supported HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from native-promise-only.