Fetch breaks when Promise.prototype.then is monkeypatched. |
|||||
Issue description1) Open news.ycombinator.com. 2) Open DevTools console. 3) Execute this code: fetch("y18.gif").then(r => console.log(r)) 4) Observe Promise being returned. 5) Now execute this code: Promise.prototype.then = ()=>{}; fetch("y18.gif").then(r => console.log(r)) 6) Observe that we now get undefined. I would expect that the internal implementation of fetch is not affected by the value of Promise.prototype.then that userland JavaScript can override.
,
Feb 15 2018
ScriptPromise::Then is not related. The behavior comes from v8::Promise defined in v8.h.
,
Feb 15 2018
I'll take a look when I'm in office tomorrow. I was under the impression that v8::Promise::Then [0] would use the untampered version of the builtin. https://cs.chromium.org/chromium/src/v8/src/api.cc?l=7453&rcl=1245787434f94365412645d9530ad60212128586
,
Feb 15 2018
I don't understand the issue here. Given this code:
Promise.prototype.then = ()=>{};
fetch("y18.gif").then(r => console.log(r))
line two's `.then(...)` calls the no-op function declared in line one. So yeah, definitely nothing will get output.
This seems completely working as intended. The internal implementation of fetch is working fine still. (You can also check the network tab to confirm that the resource is still fetched.) But the promise returned is still a Promise, that uses Promise.prototype, and thus calling `.then()` on it will do nothing if you've explicitly set `Promise.prototype.then` to a no-op.
,
Feb 16 2018
Argh. I'm being an idiot and totally overlooked that part. Thanks!
,
Feb 16 2018
,
Feb 16 2018
|
|||||
►
Sign in to add a comment |
|||||
Comment 1 by yangguo@chromium.org
, Feb 15 2018