Implement Response.clone (#125)
This simple commit takes the existing Request.clone implementation and adapts it to work for Response.clone. This was done largely as a learning exercise.
I did have a question regarding the current Response class. It appears that a URL slot is missing from Response where it appears in Request. The spec shows a url attribute which would imply that this slot should be implemented.
Is this intentionally left out or something that just hasn't been added yet?
I have yet to get the WPT tests running properly on my machine, so this has not been tested against those. As such, I am leaving this as a draft until I can validate against those.
This is amazing, thank you for sharing. If you are able to get the tests running it would be great to get the WPT coverage working here.
In order to get the test coverage updated, we run the tests with WPT_FLAGS="--update-expectations". It does seem like some WPT cases have switched from passing to failing in the process as well - it seems like this is actually as a side effect of adding the feature rather than being an explicit regression, so assuming that is the case that should be okay, but it would be worth confirming this first.
With regards to your question, RequestOrResponse is the base class for both which has a URL slot, then the extended slots for Response pick up at this RequestOrResponse::Slots::count so URL is very much still on Response, implemented via its accessor (https://github.com/bytecodealliance/StarlingMonkey/blob/main/builtins/web/fetch/request-response.cpp#L2021).
Let me know if I can assist further at all with getting the WPT setup working for you.
The latest commits expose the URL slot to make Response consistent with Request, as well as make sure to copy the value as part of Response.clone. In addition, the code for cloning Response is greatly simplified, so long as constructing a RootedObject from RequestOrResponse::headers actually works as I am hoping it does. Testing the before and after does appear to work as expected.
I was able to get WPT running on my machine and it is reporting:
1: Running test fetch/api/response/response-clone.any.js
1: Sending request to http://127.0.0.1:7676/fetch/api/response/response-clone.any.js
1: wasmtime stderr: stderr [83] :: Warning: Using a DEBUG build. Expect things to be SLOW.
1: wasmtime stdout: stdout [83] :: Log: running test /fetch/api/response/response-clone.any.js
1: fetch/api/response/response-clone.any.js 6 / 21 ( +0, -0, ?0) passing in 0ms
This would imply that some amount of tests are failing, so I will dig into these further to see if I can aim for higher success rate in WPT.