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 #13021

Closed
jdm opened this issue Aug 24, 2016 · 19 comments
Closed

Make NodeList iterable #13021

jdm opened this issue Aug 24, 2016 · 19 comments

Comments

@jdm
Copy link
Member

@jdm jdm commented Aug 24, 2016

Blocked on #12819. We're missing iterable<Node?>; from NodeList.webidl. I believe that adding it should be all that's necessary to make iteration over NodeList values like the result of document.querySelectorAll.

Code: components/script/dom/webidls/NodeList.webidl, components/script/dom/nodelist.rs
Test: create a test in tests/wpt/web-platform-tests/dom/nodes that tests the properties of the iterating over a NodeList

@jdm jdm added this to the Taiwan Code Sprint milestone Aug 24, 2016
@hsinewu
Copy link
Contributor

@hsinewu hsinewu commented Aug 27, 2016

I would like to work on this.

@KiChjang
Copy link
Member

@KiChjang KiChjang commented Aug 27, 2016

Sure thing! Here are a couple of key things to look out for: dom::bindings::iterable::Iterable and its trait methods, get_iterable_length, get_value_at_index and get_key_at_index.

@jdm
Copy link
Member Author

@jdm jdm commented Aug 27, 2016

No, those are only used for pair iterables; the value iterables like this one are less complex.

@hsinewu
Copy link
Contributor

@hsinewu hsinewu commented Aug 27, 2016

No idea what webidl is doing there Orz

What does the question mark mean? nullable?
Looks like I could just uncomment that line (iterable), as it matches the spec definition.
But @jdm refer to it as iterable<Node?>, what's the difference?

The feeling of reading specs...

@jdm
Copy link
Member Author

@jdm jdm commented Aug 27, 2016

The ? does mean nullable, yes. I copied the line from Firefox's WebIDL, but we could see if the non-nullable one works.

@hsinewu
Copy link
Contributor

@hsinewu hsinewu commented Aug 27, 2016

Got
WebIDL.WebIDLError: error: Iterable type does not match indexed getter type
when using iterable<Node>,
while using iterable<Node?> can compile.

No idea what's going on, just do some recording.

@hsinewu
Copy link
Contributor

@hsinewu hsinewu commented Aug 27, 2016

How can I prove nodes to be iterable? for-loop? Any specific dom function to test out?
I don't know what is not working before this change.

@hsinewu
Copy link
Contributor

@hsinewu hsinewu commented Aug 27, 2016

Oh, querySelectorAll

@hsinewu hsinewu mentioned this issue Aug 27, 2016
4 of 4 tasks complete
@izgzhen
Copy link
Contributor

@izgzhen izgzhen commented Aug 27, 2016

You may take #12998 as a reference

@izgzhen
Copy link
Contributor

@izgzhen izgzhen commented Aug 27, 2016

And continue my last advice, the tests/wpt/metadata/fetch/api/headers/headers-structure.html might be a good example of testing iterable

@hsinewu
Copy link
Contributor

@hsinewu hsinewu commented Aug 27, 2016

@izgzhen I found no html files in that commit, it's some rust and .html.ini files, or do you mean those impl are the feature needed to be tested, and can served as hints to do corresponding test in javascript?

Also, I can't find headers-structure.html file you refer to, or is it buried in some other branch?

@hsinewu
Copy link
Contributor

@hsinewu hsinewu commented Aug 28, 2016

Oh, I was looking for it under metadata folder, it was my wrong :/

@izgzhen
Copy link
Contributor

@izgzhen izgzhen commented Aug 28, 2016

@jdm As far as I find, we don't codegen anything for value iterator? But looks like values and entries interfaces are specified in spec?

@jdm
Copy link
Member Author

@jdm jdm commented Aug 28, 2016

They are generated, but they're self-hosted JS code so no changes are necessary in the rust implementation.

@hsinewu
Copy link
Contributor

@hsinewu hsinewu commented Sep 1, 2016

@jdm I don't understand what you mean by 'self-hosted', would you clarify it for me?

I assume, by iterable it means it has forEach, vlalues, entries, keys methods, but there were not in my experiment, which means either

  1. Have to use dom::bindings::iterable::Iterable; and impls.
  2. Missing some use dom::bindings::codegen::Bindings::

Is this the right way to do it?

Also, would you take a look at #13081?

@jdm
Copy link
Member Author

@jdm jdm commented Sep 1, 2016

Here, 'self-hosted' means that a custom implementation of forEach, values, etc. for NodeList isn't necessary and we delegate to SpiderMonkey's default instead: https://github.com/servo/mozjs/blob/master/mozjs/js/src/builtin/Array.js#L228

@jdm
Copy link
Member Author

@jdm jdm commented Sep 1, 2016

@hsinewu I added the iterable<Node?> line to NodeList.webidl, recompiled, then loaded this HTML file:

<span>hi</span>
<script>
var o = document.querySelectorAll('span');
console.log('length' in o);
console.log('forEach' in o);
console.log('values' in o);
console.log('keys' in o);
console.log(Symbol.iterator in o);
</script>

Every line printed true for me, so I'm not sure why your NodeList isn't working...

@hsinewu
Copy link
Contributor

@hsinewu hsinewu commented Sep 2, 2016

@jdm Fail to reproduce the problem, I might have been messed up with the build.
It looks well now, thanks for your help :)

bors-servo added a commit that referenced this issue 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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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