Re: [whatwg/streams] Add helpers to use initial values of Promise methods (#1010)

MattiasBuelens commented on this pull request.



> @@ -157,11 +157,38 @@ exports.MakeSizeAlgorithmFromSizeFunction = size => {
   return chunk => size(chunk);
 };
 
-exports.PerformPromiseThen = (promise, onFulfilled, onRejected) => {
+const originalPromise = Promise;
+const originalPromiseThen = Promise.prototype.then;
+const originalPromiseResolve = Promise.resolve;
+const originalPromiseReject = Promise.reject;
+
+function CreatePromise(executor) {
+  return new originalPromise(executor);
+}
+
+function PromiseResolve(value) {
+  return originalPromiseResolve.call(originalPromise, value);
+}
+
+function PromiseReject(reason) {

I wasn't sure what to name these functions, since there's no such thing as `PromiseReject` or `PerformPromiseCatch` in [the ECMAScript specification](https://tc39.es/ecma262/). I considered naming them after the phrases in the promise guide, but I found `PromiseRejectedWith(reason)` and `UponRejection(promise, onRejected)` a bit weird.

Feel free to suggest better names. 😉

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/1010#pullrequestreview-276831806

Received on Monday, 19 August 2019 21:45:00 UTC