Skip to content
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

Make document url mutable and implement location.replace() #13418

Merged
merged 5 commits into from Nov 20, 2016

Conversation

@stshine
Copy link
Contributor

stshine commented Sep 25, 2016


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #13413 (github issue number if applicable).
  • There are tests for these changes OR

This change is Reviewable

@highfive
Copy link

highfive commented Sep 25, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/webidls/Location.webidl, components/script/dom/location.rs
@highfive
Copy link

highfive commented Sep 25, 2016

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@stshine
Copy link
Contributor Author

stshine commented Sep 25, 2016

bors-servo added a commit that referenced this pull request Sep 25, 2016
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
Copy link
Contributor

bors-servo commented Sep 25, 2016

Trying commit 8103751 with merge 8a018c0...

@bors-servo
Copy link
Contributor

bors-servo commented Sep 25, 2016

💔 Test failed - linux-rel

@stshine
Copy link
Contributor Author

stshine commented Sep 25, 2016

@KiChjang
Copy link
Member

KiChjang commented Sep 26, 2016

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented Sep 26, 2016

Trying commit 8103751 with merge d0e866e...

bors-servo added a commit that referenced this pull request Sep 26, 2016
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 -->
@KiChjang
Copy link
Member

KiChjang commented Sep 26, 2016

r=me once you've updated the test expectations. If there are none, you'll need to write one.

@bors-servo delegate+

@bors-servo
Copy link
Contributor

bors-servo commented Sep 26, 2016

✌️ @stshine can now approve this pull request

@bors-servo
Copy link
Contributor

bors-servo commented Sep 26, 2016

💔 Test failed - linux-rel

@jdm
Copy link
Member

jdm commented Sep 26, 2016

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.

@jdm
Copy link
Member

jdm commented Sep 26, 2016

We should add a test to location_replace.html for the parse error exception; we can duplicate the one in location_assign.html for that purpose.

@stshine
Copy link
Contributor Author

stshine commented Sep 26, 2016

Some mysterious fails on local machines disappeared.
And Thank for point out the location of the right tests.

@stshine
Copy link
Contributor Author

stshine commented Sep 26, 2016

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 python3 -m http.server and visit it.
In firefox the output in console is

http://localhost:8000/new.html
http://localhost:8000/new.html#x

while in servo the output is :

http://localhost:8000/new.html
http://localhost:8000/new.html

Tried to dig into the code of load_url() and it look like for url that only different in fragment with the url of current document, servo eventually called into ScriptThread::check_and_scroll_fragment() in https://github.com/servo/servo/blob/master/components/script/script_thread.rs#L2023 , which only set target state on the target element and scroll to to the frame point.
How am I supposed to fix this?

@jdm
Copy link
Member

jdm commented Sep 26, 2016

I see what you mean. For the purposes of this PR, I propose we add an API to Document to set the document's URL and call it from load_url before returning when changing the fragment. I've filed #13437 about integrating this with session history, too.

@stshine
Copy link
Contributor Author

stshine commented Sep 27, 2016

So... wrap the url field in Cell? But the Url struct does not implement the Copy trait. And Copy can not be simply derived because it contains a String field.

@jdm
Copy link
Member

jdm commented Sep 27, 2016

DOMRefCell.

@stshine
Copy link
Contributor Author

stshine commented Sep 28, 2016

Finally managed to make document.url work as intented, but now I got a bunch of erros from wpt runner itself like this:

 ▶ ERROR [expected TIMEOUT] /html/browsers/browsing-the-web/scroll-to-fragid/005.html
  └   → Got results from /html/browsers/browsing-the-web/scroll-to-fragid/005.html#test, expected /html/browsers/browsing
-the-web/scroll-to-fragid/005.html                                                                                      
Traceback (most recent call last):
  File "/home/stshine/Programs/servo/tests/wpt/harness/wptrunner/executors/base.py", line 149, in run_test
    result = self.do_test(test)
  File "/home/stshine/Programs/servo/tests/wpt/harness/wptrunner/executors/executorservo.py", line 119, in do_test
    result = self.convert_result(test, self.result_data)
  File "/home/stshine/Programs/servo/tests/wpt/harness/wptrunner/executors/base.py", line 60, in __call__
    (result_url, test.url))
AssertionError: Got results from /html/browsers/browsing-the-web/scroll-to-fragid/005.html#test, expected /html/browsers/
browsing-the-web/scroll-to-fragid/005.html                                                                              

Maybe it is not a good idea to set document.url ...

@stshine
Copy link
Contributor Author

stshine commented Sep 28, 2016

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.

@KiChjang

KiChjang Sep 28, 2016

Member

nit: Remove this extra ;.

This comment has been minimized.

@stshine

stshine Sep 28, 2016

Author Contributor

This is to appease borrow checker on RefCell in if let. See rust-lang/rust#22449

return;
}
}

This comment has been minimized.

@KiChjang

KiChjang Sep 28, 2016

Member

nit: Remove extra space after }.

@@ -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.

@KiChjang

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.

@stshine

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.

@KiChjang

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.

@stshine

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.

@KiChjang

KiChjang Sep 28, 2016

Member

This code is still not throwing any exceptions.

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.

@KiChjang

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.

@KiChjang

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.

@stshine

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.

@KiChjang

KiChjang Sep 28, 2016

Member
pub fn url_mut(&mut self) {
    &mut self.url
}

This comment has been minimized.

@Ms2ger

Ms2ger Sep 28, 2016

Contributor

No, no, NO. There are no &mut references to DOM objects.

This comment has been minimized.

@KiChjang

KiChjang Nov 12, 2016

Member

This could really take in a Url instead of a &Url.

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.

@KiChjang

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.

@KiChjang

KiChjang Nov 16, 2016

Member

Needs comment linking to rust-lang/rust#37785.

@bors-servo
Copy link
Contributor

bors-servo commented Nov 19, 2016

Testing commit dc4bc99 with merge b8cb92a...

bors-servo added a commit that referenced this pull request Nov 19, 2016
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
Copy link
Contributor

bors-servo commented Nov 19, 2016

💔 Test failed - linux-rel-wpt

@highfive
Copy link

highfive commented Nov 19, 2016

  ▶ FAIL [expected PASS] /_mozilla/css/incremental_trailing_whitespace_a.html
  └   → /_mozilla/css/incremental_t</span><span class="stdout">railing_whitespace_a.html da54041086f2975f8e3c776d2283ad6609e6862a
/_mozilla/css/incremental_trailing_whitespace_ref.html f5d0147c8bddbdc772a7e5e86c7c9e433fcd486b
Testing da54041086f2975f8e3c776d2283ad6609e6862a == f5d0147c8bddbdc772a7e5e86c7c9e433fcd486b
@stshine stshine force-pushed the stshine:location-replace branch from dc4bc99 to 5287e70 Nov 19, 2016
@stshine
Copy link
Contributor Author

stshine commented Nov 19, 2016

@bors-servo r=KiChjang
#10473
comment addressed.

@bors-servo
Copy link
Contributor

bors-servo commented Nov 19, 2016

📌 Commit 5287e70 has been approved by KiChjang

@bors-servo
Copy link
Contributor

bors-servo commented Nov 20, 2016

Testing commit 5287e70 with merge debad8a...

bors-servo added a commit that referenced this pull request Nov 20, 2016
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
Copy link
Contributor

bors-servo commented Nov 20, 2016

💔 Test failed - linux-rel-wpt

@KiChjang
Copy link
Member

KiChjang commented Nov 20, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Nov 20, 2016

Testing commit 5287e70 with merge 72e4c6d...

bors-servo added a commit that referenced this pull request Nov 20, 2016
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
Copy link
Contributor

bors-servo commented Nov 20, 2016

@bors-servo bors-servo merged commit 5287e70 into servo:master Nov 20, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@stshine
Copy link
Contributor Author

stshine commented Nov 20, 2016

Waaaaoh! Finally this PR got merged before it has 150 comments. Thanks @KiChjang and @jdm for review, please forgive my single-threaded head :)

@stshine stshine deleted the stshine:location-replace branch Nov 20, 2016
@emilio
Copy link
Member

emilio commented Nov 20, 2016

Thank you for being so persistent :)

On Sun, Nov 20, 2016 at 04:04:52AM -0800, stshine wrote:

Waaaaoh! Finally this PR got merged before it has 150 comments. Thanks @KiChjang and @jdm for review, please forgive my single-threaded head :)

You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#13418 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

9 participants
You can’t perform that action at this time.