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

Implement Array.length binding #291

Merged
merged 1 commit into from
Jun 22, 2018
Merged

Conversation

robertDurst
Copy link
Contributor

Based on the example property in the Design section of the wasm_bindgen book, I reasoned that the Array.length property must be a method, getter, structural.

Also, I learned today that there is in fact a way to trigger an exception with Array.length.

var namelistA = new Array(4294967296); //2 to the 32nd power = 4294967296 
var namelistC = new Array(-100) //negative sign

console.log(namelistA.length); //RangeError: Invalid array length 
console.log(namelistC.length); //RangeError: Invalid array length 

Should I account for this?

I played around with catch however it said Result<u32, JsValue> in not implemented for IntoWasmAbi. Should I implement this? I began to but didn't want to go overboard or do anything too ambitious for my first pr 😅

@robertDurst
Copy link
Contributor Author

Hmmm... travis crashes.

I am able to replicate this rustup update crash:

$ rustup update                                                                                                                                                                                             ‹system›
info: syncing channel updates for 'stable-x86_64-apple-darwin'
info: syncing channel updates for 'nightly-x86_64-apple-darwin'
info: latest update on 2018-06-22, rust version 1.28.0-nightly (662c70a59 2018-06-21)
info: downloading component 'rustc'
error: failed to parse url: 1.28.0-nightly (662c70a59 2018-06-21)/2018-06-22/rustc-nightly-x86_64-apple-darwin.tar.xz
info: checking for self-updates

       stable-x86_64-apple-darwin unchanged - rustc 1.27.0 (3eda71b00 2018-06-19)
  nightly-x86_64-apple-darwin update failed - rustc 1.28.0-nightly (4a9c58c6b 2018-06-05)

@robertDurst
Copy link
Contributor Author

Yep this is an issue it looks like: rust-lang/rustup#1443

@jonathan-s
Copy link
Contributor

jonathan-s commented Jun 22, 2018 via email

@robertDurst
Copy link
Contributor Author

Here is the definition (you'll have to scroll down a bit) from the Design section from the wasm_bindgen book:

this [structural] is a flag to method annotations which indicates that the method being accessed (or property with getters/setters) should be accessed in a structural fashion. For example methods are not accessed through prototype and properties are accessed on the object directly rather than through Object.getOwnPropertyDescriptor

From my understanding, this is for properties that are directly on an object versus properties that are on the prototype.

@fitzgen
Copy link
Member

fitzgen commented Jun 22, 2018

From my understanding, this is for properties that are directly on an object versus properties that are on the prototype.

Yes, this is my understanding as well.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks :)

@fitzgen fitzgen merged commit a9ca64b into rustwasm:master Jun 22, 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