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

Use JsValue for webidl sequence. #1152

Merged
merged 1 commit into from
Jan 11, 2019

Conversation

derekdreery
Copy link
Contributor

No description provided.

@alexcrichton
Copy link
Contributor

Thanks for this! I'm not sure though if js_sys::Array is the right binding here, it looks like according to WebIDL it may suffice to take/return iterators as well? (I'm not super familiar with many of these APIs that take a sequence)

Do you know if other non-array types are accepted/returned?

@derekdreery
Copy link
Contributor Author

I wasn't sure exactly what the semantics are. It sounds like sequences should be valid, but all the examples use Arrays. Maybe some experimentation is required.

@alexcrichton
Copy link
Contributor

Ah yeah it's probably worth playing around with this a bit and some of the newly exposed API. One option is to just bind this as JsValue and let users interpret it though

@derekdreery
Copy link
Contributor Author

I've done some experimentation on browsers in #1038

@derekdreery derekdreery changed the title Use js_sys::Array for webidl sequence. Use JsValue for webidl sequence. Jan 9, 2019
@derekdreery
Copy link
Contributor Author

I've just set it to use JsValue for now.

@alexcrichton
Copy link
Contributor

Ok looks good to me! Want to add a small test as well exercising this?

Also mind taking a look @fitzgen as well and confirming you're good w/ this strategy?

@fitzgen
Copy link
Member

fitzgen commented Jan 10, 2019

Is there a reason not to use js_sys::Iterator instead of JsValue?

https://docs.rs/js-sys/0.3.8/js_sys/struct.Iterator.html

@alexcrichton
Copy link
Contributor

@fitzgen I think an Array couldn't be passed in because it's not a superclass, right?

@fitzgen
Copy link
Member

fitzgen commented Jan 10, 2019

@fitzgen I think an Array couldn't be passed in because it's not a superclass, right?

I'm not suggesting Array, only js_sys::Iterator which is a duck-typed thing for any JS object that implements the iterator protocol.

Maybe we are talking past each other here?

@alexcrichton
Copy link
Contributor

@fitzgen oh sorry what I mean is that if we have fn foo(x: &js_sys::Iterator) then you can't easily-ish pass in &js_sys::Array

@fitzgen
Copy link
Member

fitzgen commented Jan 11, 2019

Is this issue specifically for parameters?

I would expect js_sys::Iterator for iterable return values, and I guess &JsValue for parameters.

@Pauan
Copy link
Contributor

Pauan commented Jan 11, 2019

@alexcrichton Can't you just use foo(&x.values())? And we can provide a similar method on other iterable types. Maybe even backed by a trait.

@alexcrichton
Copy link
Contributor

@fitzgen ah yeah sorry I'm thinking about parameters, but I think we still need Array on return types as well because there's not a next method on the Array types in JS, right? Ideally we'd return like a IntoIterator of some form I think?

@Pauan it's true yeah .values() would work! I think we ideally, though, want to expose the capabilities of web engines which is to accept both iterators and arrays so conversions that aren't necessary don't pull in overhead by accident.

@fitzgen
Copy link
Member

fitzgen commented Jan 11, 2019

@fitzgen ah yeah sorry I'm thinking about parameters, but I think we still need Array on return types as well because there's not a next method on the Array types in JS, right? Ideally we'd return like a IntoIterator of some form I think?

D'oh. yeah. I don't think we can rely on sequences being arrays though. I guess the most correct thing would be something like -> impl IntoIterator<Item = JsValue> or something like that...

Edit: See comment below

@fitzgen
Copy link
Member

fitzgen commented Jan 11, 2019

https://heycam.github.io/webidl/#es-sequence

IDL sequence values are represented by ECMAScript Array values.

@fitzgen
Copy link
Member

fitzgen commented Jan 11, 2019

That is pretty definitive. Ignore my comment about "I don't think we can rely on..."

@alexcrichton
Copy link
Contributor

Ok I think we're probably good to go in this case with argument position as JsValue and return position as js_sys::Array. @derekdreery want to update the PR to return Array and it should be good to go then!

@derekdreery
Copy link
Contributor Author

Ok sounds good!

@derekdreery
Copy link
Contributor Author

Done. Also rebased and squashed.

@alexcrichton alexcrichton merged commit 1a10ecc into rustwasm:master Jan 11, 2019
@derekdreery derekdreery deleted the webidl_sequence branch January 11, 2019 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants