Re: [whatwg/streams] Use Promise.prototype.then brand check to detect real Promise (#730)

domenic commented on this pull request.



> @@ -1935,3 +1934,16 @@ function byteStreamControllerBrandCheckException(name) {
   return new TypeError(
     `ReadableByteStreamController.prototype.${name} can only be used on a ReadableByteStreamController`);
 }
+
+// Helper function for ReadableStream pipeThrough
+
+function hasPromiseIsHandledInternalSlot(promise) {
+  try {
+    // This relies on the brand-check that is enforced by Promise.prototype.then(). As with the rest of the reference
+    // implementation, it doesn't attempt to do the right thing if someone has modified the global environment.
+    Promise.prototype.then.call(promise, undefined, () => {});

Oh, I see, because it generates a new promise that is itself marked as unhandled, but that promise is never returned back for you to handle.

In that case IMO the best resolution is to rename this helper something like checkPromiseIsHandledInternalSlotAndSetItToTrueIfItExists, or something similar but less awkward, to make it clear it's effectively doing both.

-- 
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/730#discussion_r110808340

Received on Tuesday, 11 April 2017 03:22:26 UTC