Wasm-bindgen: Remove `extends = Object` from `js_sys::{Number,JsString}`?

Created on 11 Apr 2019  路  5Comments  路  Source: rustwasm/wasm-bindgen

In https://github.com/rustwasm/wasm-bindgen/pull/1405 we seem to be leaning towards JsString both representing the native String class as well as the string primitive in JS. I suspect we'd want to do the same for Number too!

Currently, though, both these types inhereit from Object which means they Deref to Object. If we use native strings in JsString (which we actually already do) then this may not be quite right.

Should we remove the extends annotation from these types so they both deref to JsValue?

js-sys question

All 5 comments

cc @Pauan, you've likely got thoughts on this!

This is still fine, as they do inherit all the methods from Object.

For example, some_number.to_string() should indeed continue to work.

My thoughts on this are rather nuanced, so I'll need a bit of time to formulate a response, but @RReverser is correct that the Object methods should continue to work fine.

Ah ok intersting! I was unware of that :)

I'm gonna go ahead and close this, but @Pauan if you feel there's action that we need to take here a new issue/PR would be good!

Well, I had a detailed reply all written up, but after thinking about it, I like the current plan better: shift Number/Boolean/JsString to use primitives, but continue to have them extend from Object.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MarcAntoine-Arnaud picture MarcAntoine-Arnaud  路  3Comments

pauldorehill picture pauldorehill  路  3Comments

derekdreery picture derekdreery  路  3Comments

alexcrichton picture alexcrichton  路  3Comments

gitmko0 picture gitmko0  路  3Comments