New issue
Advanced search Search tips

Issue 812550 link

Starred by 2 users

Issue metadata

Status: WontFix
Owner: ----
Closed: Feb 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug



Sign in to add a comment

Fetch breaks when Promise.prototype.then is monkeypatched.

Project Member Reported by yangguo@chromium.org, Feb 15 2018

Issue description

1) 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.
 
Cc: haraken@chromium.org domenic@chromium.org
I wonder what went wrong, and where we call the monkey-patched Promise.prototype.then.

This [0] doesn't seem to be it, because V8's v8::Promise::Then should be using the original builtin.

Kentaro or Domenic, could you help triage?

[0] https://cs.chromium.org/chromium/src/third_party/WebKit/Source/bindings/core/v8/ScriptPromise.cpp?l=238&rcl=71ccd71cf4cea51efacfdbe543e66ecff171fca2
Cc: yhirano@chromium.org
ScriptPromise::Then is not related. The behavior comes from v8::Promise defined in v8.h.
Cc: gsat...@chromium.org
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
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.
Argh. I'm being an idiot and totally overlooked that part. Thanks!
Status: Fixed (was: Available)
Status: WontFix (was: Fixed)

Sign in to add a comment