Skip to content

Add Array.prototype.values binding #395

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

Merged
merged 1 commit into from
Jul 9, 2018

Conversation

brisad
Copy link
Contributor

@brisad brisad commented Jul 5, 2018

No description provided.

@brisad
Copy link
Contributor Author

brisad commented Jul 5, 2018

Hi, I wanted to add a binding for Array.prototype.values(). Looking at how other values() bindings were created I made the attempt found in this PR. But I cannot get it to work and hope someone could help me.

I get this error when I run the test:

(node:27264) ExperimentalWarning: The ESM module loader is experimental.
TypeError: Cannot read property 'call' of undefined
    at __wbg_f_values_values_Array (file:///home/michael/Devel/wasm-bindgen/target/generated-tests/test0/out.mjs:404:61)
    at wasm_bindgen::js::Array::values::ha2fdfb8076eca732 (wasm-function[24]:99)
    at test0::get_values::hd2b7ff6a2f1ecf5f (wasm-function[3]:38)
    at get_values (wasm-function[4]:171)
    at Module.get_values (file:///home/michael/Devel/wasm-bindgen/target/generated-tests/test0/out.mjs:66:32)
    at Module.test (file:///home/michael/Devel/wasm-bindgen/target/generated-tests/test0/test.mjs:7:41)
    at run (file:///home/michael/Devel/wasm-bindgen/target/generated-tests/test0/run.mjs:4:22)
    at Promise.all.then.then.result (file:///home/michael/Devel/wasm-bindgen/target/generated-tests/test0/run.mjs:24:37)

thread 'js_globals::ArrayIterator::values' panicked at 'assertion failed: output.status.success()', tests/all/project_builder.rs:765:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

@fitzgen
Copy link
Member

fitzgen commented Jul 5, 2018

@brisad does the version of Node you ahve installed have Array#values?

Also, I think we already have bindings for this method -- maybe we forgot to check it off.

@fitzgen
Copy link
Member

fitzgen commented Jul 5, 2018

Also, I think we already have bindings for this method -- maybe we forgot to check it off.

NVM, I misread.

@brisad
Copy link
Contributor Author

brisad commented Jul 5, 2018

@fitzgen Oh, good question. It seems like it doesnt:

$ node
> let a = [1,2,3];
undefined
> a.entries()
Object [Array Iterator] {}
> a.values()
TypeError: a.values is not a function

I also just upgraded from Node v8 to v10.

Travis CI seems to have the same problem, so it appears it is not just me.

@brisad
Copy link
Contributor Author

brisad commented Jul 5, 2018

And the Browser compatibility section of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values indeed states that Node.js does not have support for it.

@fitzgen
Copy link
Member

fitzgen commented Jul 5, 2018

@brisad you could polyfill Array.prototype.find in the test.js file -- want to try that?

@alexcrichton
Copy link
Contributor

Alternatively this could perhaps use .headless(true) to run it in a browser?

@brisad
Copy link
Contributor Author

brisad commented Jul 8, 2018

@fitzgen I tried assigning a values function to Array.prototype, if that is what you meant. I did it in the test.js file, both outside and inside the test function, but it does not seem to take. I get the same error every time.

@alexcrichton For some reason running any headless-tests I run locally seem to never finish. I tried pushing up to CI with an addition to this PR, but that also failed.

@alexcrichton
Copy link
Contributor

@brisad I've pushed a few commits to the master branch which should hopefully be helpful when debugging failing headless tests, want to try rebasing?

The headless tests are still a bit new for us so we're still trying to work out the kinks!

@brisad brisad force-pushed the array-values-binding-attempt branch from eed3655 to fc44a2f Compare July 9, 2018 16:13
@brisad
Copy link
Contributor Author

brisad commented Jul 9, 2018

@alexcrichton Sure! After looking more closely it turned out I didn't have webpack-dev-server installed for some reason. So after running yarn again I could run the test. Then I could see that I had made a mistake of adding square brackets in the call to new Array().

I updated the PR with the fixes so now everything should be set.

I realized that the dev server wasn't running when TcpStream::connect("127.0.0.1:8080") never succeeded. Perhaps we can add some "Connecting to dev server..." debug message, along with a "connected" confirmation, to aid debugging? I can add something in a PR if you want?

@brisad brisad changed the title Attempt to add Array.prototype.values binding [WIP] Add Array.prototype.values binding Jul 9, 2018
@alexcrichton
Copy link
Contributor

Ok great! Let's merge this once tests are green.

Oh dear that sounds like a nasty bug though! Let's do a separate PR for that? I think it'd be reasonable to place a cap on the number of times we connect to 8080 before printing an error and failing the test?

@alexcrichton alexcrichton merged commit bae324c into rustwasm:master Jul 9, 2018
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.

3 participants