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

No match.index or match.input for RegExp::exec() result #1831

Open
hfiguiere opened this issue Oct 23, 2019 · 3 comments
Open

No match.index or match.input for RegExp::exec() result #1831

hfiguiere opened this issue Oct 23, 2019 · 3 comments
Labels
breaking-change Tracking breaking changes for the next major version bump (if ever) js-sys Issues related to the `js-sys` crate

Comments

@hfiguiere
Copy link

hfiguiere commented Oct 23, 2019

Describe the Bug

RegExp.exec() in JavaScript return an array with TWO extra properties set: input and index.
The Rust js_sys::RegExp::exec() just return an Array.

Steps to Reproduce

n/a. It's missing in the API.

Expected Behavior

js_sys::RegExp::exec() returns a Match struct that allow accessing input and index as per the JS API.

Actual Behavior

The returned value as a js_sys::Array that don't have index nor input properties.

Additional Context

There don't even seem to be an obvious way to the properties out of the underlying JS object.

@hfiguiere hfiguiere added the bug Something isn't working label Oct 23, 2019
@hfiguiere hfiguiere changed the title No match.index and match.input for RegExp::exec() result No match.index or match.input for RegExp::exec() result Oct 23, 2019
@alexcrichton
Copy link
Contributor

Thanks for the report! For now you can probably get by with Reflect to access extra properties, but this is a good thing to keep in mind! We should probably return a subclass of an array or something like that to fix this issue. For now though I'm going to tag this as a breaking change so we can be sure to get around to it with the next round of breaking changes.

@alexcrichton alexcrichton added breaking-change Tracking breaking changes for the next major version bump (if ever) js-sys Issues related to the `js-sys` crate and removed bug Something isn't working labels Oct 28, 2019
@Pauan
Copy link
Contributor

Pauan commented Oct 29, 2019

(You would do that by using Reflect::get(&array, &JsValue::from("input")).unwrap_throw(), this works on any JS object)

@hfiguiere
Copy link
Author

I figured that out. It is missing some documentation though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Tracking breaking changes for the next major version bump (if ever) js-sys Issues related to the `js-sys` crate
Projects
None yet
Development

No branches or pull requests

3 participants