Skip to content

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

Closed
wants to merge 4 commits into from

Conversation

partic2
Copy link

@partic2 partic2 commented May 9, 2025

#703 Fix event.target always null issue

@partic2
Copy link
Author

partic2 commented May 9, 2025

Seemed CI failed, I'll try to find out the cause later.

@partic2 partic2 changed the title polyfills:make event.target refer to event.currentTarget. polyfills:Implement streamable fetch in request/response, Make event.target refer to event.currentTarget. May 17, 2025
@saghul
Copy link
Owner

saghul commented May 17, 2025

Can you please split the changes into 2 PRs, or at least 2 commits?

@partic2
Copy link
Author

partic2 commented May 17, 2025

Can you please split the changes into 2 PRs, or at least 2 commits?

Done.
It's just a early version and not tested very well, feel free to test and modify it arbitrarily.

Copy link
Owner

@saghul saghul left a 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) {
Copy link
Owner

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.

} else if (isPrototypeOf(URLSearchParams.prototype, body)) {
this._bodyText = body.toString();
const bodyBuffer=new TextEncoder().encode(body);
Copy link
Owner

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');
Copy link
Owner

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?


xhr.onprogress=function(){
if(controller!=null){
controller.enqueue(new Uint8Array(xhr.__tjsGetAndClearResponseBuffer()));
Copy link
Owner

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]()

})
}else if(request._bodySize===-1){
const reader=request.body.getReader();
xhr.__ontjsstreamsenddata=function(){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

xhr.__ontjsstreamsenddata=function(){
reader.read().then((next)=>{
if(next.done){
xhr.__tjsStreamSend(null);
Copy link
Owner

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"
Copy link
Owner

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;
}

Copy link
Owner

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.

@saghul
Copy link
Owner

saghul commented May 20, 2025

Please don't mix more commits on this PR.

@partic2
Copy link
Author

partic2 commented May 20, 2025

Please don't mix more commits on this PR.

Ok, I'll learning how to split commit into individual PR later.

@partic2
Copy link
Author

partic2 commented May 20, 2025

Split into #708 #709 #710

@partic2 partic2 closed this May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants