diff --git a/builtins/web/fetch/request-response.cpp b/builtins/web/fetch/request-response.cpp index a2b852b4..de7b90fe 100644 --- a/builtins/web/fetch/request-response.cpp +++ b/builtins/web/fetch/request-response.cpp @@ -25,6 +25,13 @@ #include "js/experimental/TypedData.h" #pragma clang diagnostic pop +#define LOG(...) \ + { \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); \ + fflush(stderr); \ + } + namespace builtins::web::streams { JSObject *NativeStreamSource::stream(JSObject *self) { @@ -86,10 +93,13 @@ class BodyFutureTask final : public api::AsyncTask { auto &chunk = read_res.unwrap(); if (chunk.done) { + LOG("chunk done"); RootedValue r(cx); return Call(cx, controller, "close", HandleValueArray::empty(), &r); } + LOG("chunk not done"); + // We don't release control of chunk's data until after we've checked that // the array buffer allocation has been successful, as that ensures that the // return path frees chunk automatically when necessary. diff --git a/tests/integration/fetch/fetch.js b/tests/integration/fetch/fetch.js index 33acfcf1..6d3e3ce1 100644 --- a/tests/integration/fetch/fetch.js +++ b/tests/integration/fetch/fetch.js @@ -51,15 +51,18 @@ function asyncToSync(promise) { done = true; }); - // NOTE: in golem the loop is needed - // while (!done) { - runEventLoopUntilInterest(); - // } + + let i = 0; + while (!done && i < 100) { + console.log("runEventLoop"); + i += 1; + runEventLoop(); + } if (!done) { - let error = new Error("asyncToSync: illegal state: not done") + let error = new Error("asyncToSync: illegal state: not done"); console.error(error); - throw error + throw error; } if (!success) {