@@ -17,11 +17,21 @@ void PromiseProxy::Init(v8::Local<v8::Context> context) {
17
17
18
18
let promise = new target(function(resolve, reject) {
19
19
origFunc(value => {
20
- CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, resolve.bind(this, value));
21
- CFRunLoopWakeUp(runloop);
20
+ const resolveCall = resolve.bind(this, value);
21
+ if (runloop === CFRunLoopGetCurrent()) {
22
+ resolveCall();
23
+ } else {
24
+ CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, resolveCall);
25
+ CFRunLoopWakeUp(runloop);
26
+ }
22
27
}, reason => {
23
- CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, reject.bind(this, reason));
24
- CFRunLoopWakeUp(runloop);
28
+ const rejectCall = reject.bind(this, reason);
29
+ if (runloop === CFRunLoopGetCurrent()) {
30
+ rejectCall();
31
+ } else {
32
+ CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, rejectCall);
33
+ CFRunLoopWakeUp(runloop);
34
+ }
25
35
});
26
36
});
27
37
@@ -32,6 +42,10 @@ void PromiseProxy::Init(v8::Local<v8::Context> context) {
32
42
return orig.bind(target);
33
43
}
34
44
return typeof orig === 'function' ? function(x) {
45
+ if (runloop === CFRunLoopGetCurrent()) {
46
+ orig.bind(target, x)();
47
+ return target;
48
+ }
35
49
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, orig.bind(target, x));
36
50
CFRunLoopWakeUp(runloop);
37
51
return target;
0 commit comments