Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMake document url mutable and implement location.replace() #13418
Conversation
highfive
commented
Sep 25, 2016
|
Heads up! This PR modifies the following files:
|
highfive
commented
Sep 25, 2016
|
@bors-servo try |
Implement Location.replace() <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #13413 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13418) <!-- Reviewable:end -->
|
|
|
@bors-servo try |
|
@bors-servo retry |
Implement Location.replace() <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #13413 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13418) <!-- Reviewable:end -->
|
r=me once you've updated the test expectations. If there are none, you'll need to write one. @bors-servo delegate+ |
|
|
|
|
|
I would be interested in knowing why https://dxr.mozilla.org/servo/source/tests/wpt/web-platform-tests/html/browsers/history/the-location-interface/location_replace.html still fails. Also, this isn't ready for merging yet - step 1 of https://html.spec.whatwg.org/multipage/browsers.html#dom-location-replace says that we should throw an exception if parsing fails, but that's not included in this PR. |
|
We should add a test to |
|
Some mysterious fails on local machines disappeared. |
|
Tried to construct a minimal test case: <!DOCTYPE html>
<html>
<head>
<style>
.blank {
height: 600px;
}
</style>
</head>
<body>
<p>Foo</p>
<div class="blank"></div>
<a id="x" href="#x">Bar</a>
<div class="blank"></div>
</body>
<script>
console.log(location.href);
location.replace("#x");
setTimeout("eval('console.log(location.href)')", 1000);
</script>
</html>Try to serve this file with
while in servo the output is :
Tried to dig into the code of |
|
I see what you mean. For the purposes of this PR, I propose we add an API to |
|
So... wrap the |
|
DOMRefCell. |
|
Finally managed to make
Maybe it is not a good idea to set |
|
Push my changes up for review. The way I appease borrow checker with RefCell feels quite awkward. |
| @@ -1195,7 +1195,7 @@ impl ScriptThread { | |||
|
|
|||
| if let Some(fragment) = doc.url().fragment() { | |||
| self.check_and_scroll_fragment(fragment, pipeline, doc); | |||
| } | |||
| }; | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
stshine
Sep 28, 2016
Author
Contributor
This is to appease borrow checker on RefCell in if let. See rust-lang/rust#22449
| @@ -1217,7 +1217,8 @@ impl ScriptThread { | |||
|
|
|||
| if let Some(root_context) = self.browsing_context.get() { | |||
| for it_context in root_context.iter() { | |||
| let current_url = it_context.active_document().url().to_string(); | |||
| let doc = it_context.active_document(); | |||
| let current_url = doc.url().to_string(); | |||
This comment has been minimized.
This comment has been minimized.
KiChjang
Sep 28, 2016
Member
This looks like a premature optimization - no code is using the doc variable at all, except for current_url, so we can just keep the previous code here (i.e. everything on 1 line).
This comment has been minimized.
This comment has been minimized.
stshine
Sep 28, 2016
•
Author
Contributor
This is also for appease the borrow checker, we hold the document in temp variable so the Ref from .url() will get out of scope before it. And you just can not place the Ref<T> in the return expression of the function. See rust-lang/rust#23338
| if &url[..Position::AfterQuery] == &nurl[..Position::AfterQuery] && | ||
| load_data.method == Method::Get { | ||
| self.check_and_scroll_fragment(fragment, parent_pipeline_id, document.r()); | ||
| document.set_url(nurl); |
This comment has been minimized.
This comment has been minimized.
KiChjang
Sep 28, 2016
Member
We need to leave a note here saying that this is wrong, and should be fixed appropriately via #13437.
This comment has been minimized.
This comment has been minimized.
stshine
Sep 28, 2016
Author
Contributor
Well, Eventually I think this commit needs to be reverted because a lot of test failed, and I push this commit mostly to notify what actually happened (and to sync between different computers). I hope to get some design suggestions on how the URL fragment should be stored for both the location API and for navigation management.
| let base_url = self.window.get_url(); | ||
| if let Ok(url) = base_url.join(&url.0) { | ||
| self.window.load_url(url, true, None); | ||
| } |
This comment has been minimized.
This comment has been minimized.
| AttrValue::from_url(document_from_node(self).url(), value.into()) | ||
| let doc = document_from_node(self); | ||
| let val = AttrValue::from_url(&*doc.url(), value.into()); | ||
| val |
This comment has been minimized.
This comment has been minimized.
KiChjang
Sep 28, 2016
Member
This creates 2 temporary stack variables for the sake of readability and sacrifices performance. Not a good thing here.
| } | ||
|
|
||
| pub fn set_url(&self, url: &Url) { | ||
| *self.url.borrow_mut() = url.clone(); |
This comment has been minimized.
This comment has been minimized.
KiChjang
Sep 28, 2016
•
Member
Why is a DOMRefCell necessary? Does returning a mutable reference to self.url not work?
Also, we need to leave a FIXME here pointing to #13437.
This comment has been minimized.
This comment has been minimized.
stshine
Sep 28, 2016
Author
Contributor
That would need to obtain the document as mutable, which I did not figure out how to do that.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| url.origin() == node.owner_doc().url().origin() | ||
| let doc = node.owner_doc(); | ||
| let result = url.origin() == doc.url().origin(); | ||
| result |
This comment has been minimized.
This comment has been minimized.
KiChjang
Sep 28, 2016
Member
This is adding 2 temporary stack variables here for no gain in readability and added verbosity. Revert.
This comment has been minimized.
This comment has been minimized.
Make document url mutable and implement location.replace() <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #13413 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13418) <!-- Reviewable:end -->
|
|
highfive
commented
Nov 19, 2016
|
|
@bors-servo r=KiChjang |
|
|
Make document url mutable and implement location.replace() <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #13413 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13418) <!-- Reviewable:end -->
|
|
|
@bors-servo retry |
Make document url mutable and implement location.replace() <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #13413 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13418) <!-- Reviewable:end -->
|
|
|
Thank you for being so persistent :) On Sun, Nov 20, 2016 at 04:04:52AM -0800, stshine wrote:
|
stshine commentedSep 25, 2016
•
edited by larsbergstrom
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is