From fa8bdb0348571a840947c07e1a80ed5d694ed3f4 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 2 Jan 2022 18:56:33 -0500 Subject: [PATCH] promises: Add a comment explaining a subtlety in `Gate` --- src/node/utils/promises.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/node/utils/promises.js b/src/node/utils/promises.js index 54b773d73..bc9f8c2dc 100644 --- a/src/node/utils/promises.js +++ b/src/node/utils/promises.js @@ -65,6 +65,9 @@ class Gate extends Promise { static get [Symbol.species]() { return Promise; } constructor() { + // `this` is assigned when `super()` returns, not when it is called, so it is not acceptable to + // do the following because it will throw a ReferenceError when it dereferences `this`: + // super((resolve, reject) => Object.assign(this, {resolve, reject})); let props; super((resolve, reject) => props = {resolve, reject}); Object.assign(this, props);