Skip to content

Commit 932b832

Browse files
author
Forbes Lindesay
committed
Use an extra layer of indirection on handle
This fixes problems with very nested promises without recreating the memory leak
1 parent 24521ef commit 932b832

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/core.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ function Promise(fn) {
2727
})
2828
}
2929
this.then[handleSymbol] = handle;
30-
3130
function handle(deferred) {
31+
return internalHandle(deferred);
32+
}
33+
function internalHandle(deferred) {
3234
if (state === null) {
3335
deferreds.push(deferred)
3436
return
@@ -61,10 +63,9 @@ function Promise(fn) {
6163
// to prevent a memory leak, we adopt the value of the other promise
6264
// allowing this promise to be garbage collected as soon as nobody
6365
// has a reference to it
64-
handle = (self[handleSymbol] = then[handleSymbol]);
65-
self.then = then;
66+
internalHandle = then[handleSymbol];
6667
deferreds.forEach(function (deferred) {
67-
handle(deferred);
68+
internalHandle(deferred);
6869
});
6970
} else {
7071
doResolve(then.bind(newValue), resolve, reject)

0 commit comments

Comments
 (0)