Skip to content

Commit 21de81d

Browse files
authored
fix: resolve PromiseProxy context memory leak (#193)
1 parent 8dbc832 commit 21de81d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

NativeScript/runtime/PromiseProxy.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)