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

Implement indexed access on select elements #13066

Merged
merged 1 commit into from Sep 22, 2016

Conversation

@mskrzypkows
Copy link

mskrzypkows commented Aug 26, 2016

Added methods for indexed access on select: SetLength, Length, Item, IndexedGetter


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

This change is Reviewable

@highfive
Copy link

highfive commented Aug 26, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/htmlselectelement.rs, components/script/dom/webidls/HTMLSelectElement.webidl
@jdm
Copy link
Member

jdm commented Aug 26, 2016

@highfive highfive assigned KiChjang and unassigned jdm Aug 26, 2016
}
}
} else if value > length { // add new blank option elements
let document = node.GetOwnerDocument();

This comment has been minimized.

Copy link
@KiChjang

KiChjang Aug 26, 2016

Member

document_from_node(self)

let appended = node.AppendChild(element.upcast());
match appended {
Ok(_) => {},
Err(e) => println!("error appending child of HTML Select: {:?}", e),

This comment has been minimized.

Copy link
@KiChjang

KiChjang Aug 26, 2016

Member
if let Err(e) = node.AppendChild(element.upcast()) {
    println!("error appending child of HTMLSelectElement: {:?}", e);
}
fn Item(&self, index: u32) -> Option<Root<Element>> {
let node = self.upcast::<Node>();
let item = node.traverse_preorder().filter_map(Root::downcast::<HTMLOptionElement>).nth(index as usize);
if item.is_some() {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Aug 26, 2016

Member

if let Some(item) = item {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Aug 26, 2016

Member

Actually, we can even do this:

item.map(|i| Root::from_ref(i.upcast()))

This comment has been minimized.

Copy link
@KiChjang

KiChjang Aug 27, 2016

Member

Or, if you don't mind chaining up functions:

self.upcast::<Node>()
    .traverse_preorder()
    .filter_map(Root::downcast::<HTMLOptionElement>)
    .nth(index as usize)
    .map(|item| Root::from_ref(item.upcast()))
let node = self.upcast::<Node>();
if value < length { // truncate the number of option elements
for _ in 0..(length - value) {
let lastChild = node.GetLastChild();

This comment has been minimized.

Copy link
@KiChjang

KiChjang Aug 27, 2016

Member

I think we can just use node.descending_last_children().take(length - value) here.

This comment has been minimized.

Copy link
@mskrzypkows

mskrzypkows Sep 10, 2016

Author

For some reason

for child in node.descending_last_children().take((length - value) as usize) {
    if let Err(e) = node.RemoveChild(&child) {
        println!("error removing child of HTML Select: {:?}", e);
    }
}

doesn't work. I'll check it and upload next commit.

This comment has been minimized.

Copy link
@KiChjang

KiChjang Sep 10, 2016

Member
let mut iter = node.descending_last_children().take((length - value) as usize);
while let Some(child) = iter.next() {
    if let Err(e) = node.RemoveChild(&child) {
        println!("Error removing child of HTMLSelectElement: {:?}", e);
    }
}

This comment has been minimized.

Copy link
@mskrzypkows

mskrzypkows Sep 16, 2016

Author

Still doesn't work, removing children test fails.

@Manishearth
Copy link
Member

Manishearth commented Sep 16, 2016

Any updates? If you need help, just ask! 😄

@mskrzypkows
Copy link
Author

mskrzypkows commented Sep 16, 2016

I'll update today, sorry for the delay, I was busy recently.

@Manishearth
Copy link
Member

Manishearth commented Sep 16, 2016

No problem :)

@mskrzypkows mskrzypkows force-pushed the mskrzypkows:htmlselect_index branch from 10138ca to a3134fc Sep 16, 2016
let node = self.upcast::<Node>();
if value < length { // truncate the number of option elements
for _ in 0..(length - value) {
if let Some(lastChild) = node.GetLastChild() {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Sep 16, 2016

Member

Looks like you ignored my review comments for this part.

This comment has been minimized.

Copy link
@mskrzypkows

mskrzypkows Sep 17, 2016

Author

I didn't ignore your comment, check my reply to your previous comment. It doesn't work as you mentioned children nodes aren't deleted.

This comment has been minimized.

Copy link
@KiChjang

KiChjang Sep 17, 2016

Member

Sorry, descending_last_children is incorrect. Use rev_children instead.

This comment has been minimized.

Copy link
@mskrzypkows

mskrzypkows Sep 19, 2016

Author

OK, thanks for hints.


// https://html.spec.whatwg.org/multipage/#dom-select-length
fn Length(&self) -> u32 {
let node = self.upcast::<Node>();

This comment has been minimized.

Copy link
@KiChjang

KiChjang Sep 16, 2016

Member

This can be melded into the following line without a let-binding to node.

let node = self.upcast::<Node>();
if value < length { // truncate the number of option elements
for _ in 0..(length - value) {
if let Some(lastChild) = node.GetLastChild() {

This comment has been minimized.

Copy link
@KiChjang

KiChjang Sep 17, 2016

Member

Sorry, descending_last_children is incorrect. Use rev_children instead.

@@ -1,18 +1,2 @@
[common-HTMLOptionsCollection.html]
type: testharness

This comment has been minimized.

Copy link
@KiChjang

KiChjang Sep 17, 2016

Member

This file can be deleted.

@mskrzypkows mskrzypkows force-pushed the mskrzypkows:htmlselect_index branch from a3134fc to e9d5615 Sep 19, 2016
@KiChjang
Copy link
Member

KiChjang commented Sep 21, 2016

Squash!

@mskrzypkows mskrzypkows force-pushed the mskrzypkows:htmlselect_index branch from e9d5615 to 920f42b Sep 21, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Sep 21, 2016

💔 Test failed - mac-rel-wpt

@jdm
Copy link
Member

jdm commented Sep 21, 2016

  ▶ Unexpected subtest result in /html/dom/interfaces.html:
  └ PASS [expected FAIL] HTMLSelectElement interface: attribute length

  ▶ Unexpected subtest result in /html/dom/interfaces.html:
  └ PASS [expected FAIL] HTMLSelectElement interface: operation item(unsigned long)

  ▶ Unexpected subtest result in /html/dom/interfaces.html:
  └ PASS [expected FAIL] HTMLSelectElement interface: document.createElement("select") must inherit property "length" with the proper type (10)

  ▶ Unexpected subtest result in /html/dom/interfaces.html:
  └ PASS [expected FAIL] HTMLSelectElement interface: document.createElement("select") must inherit property "item" with the proper type (11)

  ▶ Unexpected subtest result in /html/dom/interfaces.html:
  └ PASS [expected FAIL] HTMLSelectElement interface: calling item(unsigned long) on document.createElement("select") with too few arguments must throw TypeError
refs #11763
@mskrzypkows mskrzypkows force-pushed the mskrzypkows:htmlselect_index branch from 920f42b to 670693b Sep 22, 2016
@mskrzypkows
Copy link
Author

mskrzypkows commented Sep 22, 2016

Strange build error, it seems not related to my changes.

@KiChjang
Copy link
Member

KiChjang commented Sep 22, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Sep 22, 2016

📌 Commit 670693b has been approved by KiChjang

@bors-servo
Copy link
Contributor

bors-servo commented Sep 22, 2016

Testing commit 670693b with merge 96f6c1d...

bors-servo added a commit that referenced this pull request Sep 22, 2016
Implement indexed access on select elements

<!-- Please describe your changes on the following line: -->
Added methods for indexed access on select: SetLength, Length, Item, IndexedGetter

---
<!-- 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 #11763 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/13066)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Sep 22, 2016

💔 Test failed - mac-rel-wpt

@KiChjang
Copy link
Member

KiChjang commented Sep 22, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Sep 22, 2016

Testing commit 670693b with merge d74f6ad...

bors-servo added a commit that referenced this pull request Sep 22, 2016
Implement indexed access on select elements

<!-- Please describe your changes on the following line: -->
Added methods for indexed access on select: SetLength, Length, Item, IndexedGetter

---
<!-- 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 #11763 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/13066)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Sep 22, 2016

@bors-servo bors-servo merged commit 670693b into servo:master Sep 22, 2016
1 of 3 checks passed
1 of 3 checks passed
continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
continuous-integration/appveyor/pr AppVeyor build failed
Details
homu Test successful
Details
@notriddle notriddle modified the milestone: Taiwan Sprint Sep 23, 2016
@mskrzypkows mskrzypkows deleted the mskrzypkows:htmlselect_index branch Sep 23, 2016
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.

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