File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -16,21 +16,40 @@ void PromiseProxy::Init(v8::Local<v8::Context> context) {
1616 let runloop = CFRunLoopGetCurrent();
1717
1818 let promise = new target(function(resolve, reject) {
19+ function isFulfilled() {
20+ return !resolve;
21+ }
22+ function markFulfilled() {
23+ runloop = null;
24+ origFunc = null;
25+ resolve = null;
26+ reject = null;
27+ }
1928 origFunc(value => {
29+ if (isFulfilled()) {
30+ return;
31+ }
2032 const resolveCall = resolve.bind(this, value);
2133 if (runloop === CFRunLoopGetCurrent()) {
34+ markFulfilled();
2235 resolveCall();
2336 } else {
2437 CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, resolveCall);
2538 CFRunLoopWakeUp(runloop);
39+ markFulfilled();
2640 }
2741 }, reason => {
42+ if (isFulfilled()) {
43+ return;
44+ }
2845 const rejectCall = reject.bind(this, reason);
2946 if (runloop === CFRunLoopGetCurrent()) {
47+ markFulfilled();
3048 rejectCall();
3149 } else {
3250 CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, rejectCall);
3351 CFRunLoopWakeUp(runloop);
52+ markFulfilled();
3453 }
3554 });
3655 });
You can’t perform that action at this time.
0 commit comments