-
Notifications
You must be signed in to change notification settings - Fork 183
polyfills:Implement streamable fetch in request/response, Make event.target refer to event.currentTarget. #706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Seemed CI failed, I'll try to find out the cause later. |
Can you please split the changes into 2 PRs, or at least 2 commits? |
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a quick first pass!
@@ -3,7 +3,7 @@ function isDataView(obj) { | |||
} | |||
|
|||
function consumed(body) { | |||
if (body._noBody) { | |||
if (body._bodySize===0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please run the linter? There are a number of style errors in the JS code.
src/js/polyfills/fetch/body.js
Outdated
} else if (isPrototypeOf(URLSearchParams.prototype, body)) { | ||
this._bodyText = body.toString(); | ||
const bodyBuffer=new TextEncoder().encode(body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a TextEncoder instance and use it for both.
} else { | ||
return this.blob().then(readBlobAsArrayBuffer); | ||
throw new Error('Unknown body type'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we throw earlier?
src/js/polyfills/fetch/fetch.js
Outdated
|
||
xhr.onprogress=function(){ | ||
if(controller!=null){ | ||
controller.enqueue(new Uint8Array(xhr.__tjsGetAndClearResponseBuffer())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this function hidden under some symbol rather than a __
name. Something like xhr[kXhrGetAndClearResponseBuffer]()
src/js/polyfills/fetch/fetch.js
Outdated
}) | ||
}else if(request._bodySize===-1){ | ||
const reader=request.body.getReader(); | ||
xhr.__ontjsstreamsenddata=function(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
src/js/polyfills/fetch/fetch.js
Outdated
xhr.__ontjsstreamsenddata=function(){ | ||
reader.read().then((next)=>{ | ||
if(next.done){ | ||
xhr.__tjsStreamSend(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
src/xhr.c
Outdated
@@ -23,7 +23,10 @@ | |||
*/ | |||
|
|||
#include "curl-utils.h" | |||
#include "curl/curl.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these includes should be covered by the existing ones, no need to add them explicitly.
@@ -147,7 +154,6 @@ static void maybe_emit_event(TJSXhr *x, int event, JSValue arg) { | |||
JS_FreeValue(ctx, arg); | |||
return; | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use make format
so clang-format takes care of the styling.
Please don't mix more commits on this PR. |
Ok, I'll learning how to split commit into individual PR later. |
#703 Fix event.target always null issue