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 nodeList iterable #13081

Merged
merged 1 commit into from Sep 5, 2016
Merged

make nodeList iterable #13081

merged 1 commit into from Sep 5, 2016

Conversation

@hsinewu
Copy link
Contributor

hsinewu commented Aug 27, 2016

Not sure what to test in the script.
Need some advice. o_O


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

This change is Reviewable

@highfive
Copy link

highfive commented Aug 27, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/webidls/NodeList.webidl
@highfive
Copy link

highfive commented Aug 27, 2016

warning Warning warning

  • These commits include an empty title element (<title></title>). Consider adding appropriate metadata.
@hsinewu
Copy link
Contributor Author

hsinewu commented Aug 27, 2016

Well...
I can comment out iterable<Node?>, rebuild, and still pass the test...
So looks like the test script is quite pointless.
What should I do?

"path": "dom/nodes/NodeList-Iterable.html",
"url": "/dom/nodes/NodeList-Iterable.html"
}
],

This comment has been minimized.

@izgzhen

izgzhen Aug 27, 2016

Contributor

Looks like you hand-write this? Try ./mach update-manifest for adding test files

This comment has been minimized.

@hsinewu

hsinewu Aug 27, 2016

Author Contributor

@izgzhen I'm not bold enough to modify manifest file :p
I was using ./mach create-wpt tests/.../foo.html, as recommended here
I'll check out your advice too.

This comment has been minimized.

@hsinewu

hsinewu Aug 27, 2016

Author Contributor

Oh, do you mean the inconsistency of the path?
I have no idea about that :)

This comment has been minimized.

@izgzhen

izgzhen Aug 27, 2016

Contributor

Never mind :) it passed the CI so it is good. I am just surprised that the new entry it the first one in items

@izgzhen
Copy link
Contributor

izgzhen commented Aug 27, 2016

BTW, consider adding a descriptive title to the testing HTML file like "NodeList Iterable Test".

Good luck!

@Ms2ger
Copy link
Contributor

Ms2ger commented Aug 27, 2016

You can test for the presence of the Symbol.iterator property and whether for/of loops work

@Ms2ger Ms2ger closed this Aug 27, 2016
@Ms2ger Ms2ger reopened this Aug 27, 2016
@Ms2ger
Copy link
Contributor

Ms2ger commented Aug 27, 2016

(sorry, fat fingers)

@hsinewu
Copy link
Contributor Author

hsinewu commented Aug 27, 2016

@Ms2ger I haven't heard of that Symbol.iterator thing, I'll study about it!

@hsinewu
Copy link
Contributor Author

hsinewu commented Aug 28, 2016

This test makes more sense to me.
But still, it passes even with webidl unchanged, and that's not what I expected.

@hsinewu
Copy link
Contributor Author

hsinewu commented Aug 28, 2016

I'm thinking of ways to create NodeList without using function like querySelectorAll, but looks like it always involves using some sort of dom function.

There is a NodeList constructor(I test it on firefox) but I can't construct it with new operator.
Any ideas?

test(function() {
for(var method of methods)
assert_true(method in nodes);
}, "NodeList has " /*+ methods.join()*/ + " methods.");

This comment has been minimized.

@hsinewu

hsinewu Aug 28, 2016

Author Contributor

for some reason when I invoke join method, the test always timeout, reporting find no tests.

@KiChjang
Copy link
Member

KiChjang commented Aug 28, 2016

It doesn't look like anything's changed in nodelist.rs, did you not commit changes in that file?

nothing = document.querySelectorAll('span');
})
testIterable(paragraphs);
testIterable(nothing);

This comment has been minimized.

@KiChjang

KiChjang Aug 28, 2016

Member

Also, this test is full of tabs, please change them into spaces instead.

This comment has been minimized.

@hsinewu

hsinewu Aug 28, 2016

Author Contributor

Sure!

@hsinewu
Copy link
Contributor Author

hsinewu commented Aug 28, 2016

@KiChjang So there should be a impl Iterable for NodeList{ ... } in nodelist.rs ?

@hsinewu
Copy link
Contributor Author

hsinewu commented Aug 28, 2016

I'm not sure, I thought @jdm means changing webidl and it woiuld be done, per the ticket.
Am I supposed to work on nodelist.rs?

@izgzhen
Copy link
Contributor

izgzhen commented Aug 28, 2016

Okay ... looks like the basic indexing is implemented before, but except for Symbol.iterator (which is automatically generated if you uncomment the line in WebIDL, I guess), you may want to test the existence of forEach method, entries property and values property. You can check the below links for more information:

As I tested locally, these forEach etc. are not supported now, and nodelist.rs must implement Iterable to support it. Note that the headers example I gave previously is a pair iterator, but NodeList will be a value iterator.

@izgzhen
Copy link
Contributor

izgzhen commented Aug 28, 2016

No, don't care about forEach etc. ... Looks like I get it wrong (from WebIDL.py):

        # We only need to add entries/keys/values here if we're a pair iterator.
        # Value iterators just copy these from %ArrayPrototype% instead.
        if not self.isPairIterator():
            return

But looks like even if I didn't uncomment this line (on my local version), the querySelectorAll still works.

@hsinewu
Copy link
Contributor Author

hsinewu commented Aug 29, 2016

@izgzhen Yes, there is no forEach, entries, values methods associated with it.
Unfortunately, Symbol.iterator IS defined in the build without iterable<Node?>.
Maybe this is how things supposed to be?

@hsinewu
Copy link
Contributor Author

hsinewu commented Aug 29, 2016

I just realize I could have look it up elsewhere.
Refer to this test, they use this block of code to test the behavior of childNodes, which is of type NodeList.

... (scroll to end of the page)
  assert_equals(list[Symbol.iterator], Array.prototype[Symbol.iterator]);
  assert_equals(list.keys, Array.prototype.keys);
  assert_equals(list.values, Array.prototype.values);
  assert_equals(list.entries, Array.prototype.entries);
  assert_equals(list.forEach, Array.prototype.forEach);
}, "Iterator behavior of Node.childNodes");

Is this test script applicable in our case?

@izgzhen
Copy link
Contributor

izgzhen commented Aug 29, 2016

I think you are right. Only Symbol.iterator is "built-in", and other four need to be generated automagically through uncommenting out the line in IDL.

@hsinewu
Copy link
Contributor Author

hsinewu commented Aug 29, 2016

But they are NOT there with that line uncommented, in my experiment?
I'm confused.
What is the missing piece? The iterable implementation?

Actually, I have no idea how declaration in IDL affect the build.

@bors-servo
Copy link
Contributor

bors-servo commented Aug 30, 2016

The latest upstream changes (presumably #13126) made this pull request unmergeable. Please resolve the merge conflicts.

@hsinewu
Copy link
Contributor Author

hsinewu commented Sep 3, 2016

@KiChjang need reviewing :3

@KiChjang KiChjang removed the S-needs-rebase label Sep 3, 2016
<script>
var paragraphs;
setup(function() {
paragraphs = document.querySelectorAll('p');

This comment has been minimized.

@KiChjang

KiChjang Sep 3, 2016

Member

I don't think querySelectorAll is implemented on the document, and I'm not sure whether there's work going towards implementing CSS Selectors DOM interface.

Pinging @SimonSapin to see if we'd want to work on that.

This comment has been minimized.

@KiChjang

KiChjang Sep 3, 2016

Member

However, getElementsByName is implemented, so instead of depending on querySelectorsAll, you may want to use the former instead.

This comment has been minimized.

This comment has been minimized.

@KiChjang

KiChjang Sep 3, 2016

Member

Weird, I wasn't able to find it in the WebIDL file...

@KiChjang
Copy link
Member

KiChjang commented Sep 4, 2016

The test doesn't look like it properly tests for the iterable properties of a NodeList - it only tests for the presence of methods to call in NodeList. As @Ms2ger had described, testing for the existence of the Symbol.iterator property and using a for/of iterator would properly verify that NodeList does have iterable elements.

@Ms2ger
Copy link
Contributor

Ms2ger commented Sep 5, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Sep 5, 2016

📌 Commit b4ac513 has been approved by Ms2ger

@highfive highfive assigned Ms2ger and unassigned KiChjang Sep 5, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Sep 5, 2016

Testing commit b4ac513 with merge 1901a21...

bors-servo added a commit that referenced this pull request Sep 5, 2016
make nodeList iterable

<!-- Please describe your changes on the following line: -->
Not sure what to test in the script.
Need some advice. o_O

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

<!-- Either: -->
- [X] There are tests for these changes

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

bors-servo commented Sep 5, 2016

@bors-servo bors-servo merged commit b4ac513 into servo:master Sep 5, 2016
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
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.