-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
String.prototype.substr()
support
#307
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
Conversation
src/js.rs
Outdated
/// the start index and a number of characters after it. | ||
/// | ||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr | ||
/// TODO: Add `NaN` and `undefined` support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added todo as we don't yet have that support(or at least not that I know of).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The NaN
behavior is on the JS engine implementation side, not our side, so we don't need to worry about it.
assert.equal(wasm.create_substr(aString, -1, 1), "a"); | ||
assert.equal(wasm.create_substr(aString, 1, -1), ""); | ||
// TODO: Uncomment and test these assertions, once we have support for optional parameters | ||
// assert.equal(wasm.create_substr(aString, -3), "lla"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did add those tests though(for the optional parameter) and do want to know what should be added as a todo if needed at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks :)
src/js.rs
Outdated
/// the start index and a number of characters after it. | ||
/// | ||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr | ||
/// TODO: Add `NaN` and `undefined` support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The NaN
behavior is on the JS engine implementation side, not our side, so we don't need to worry about it.
Should I remove the todos then? And how should we handle the Optional parameters - again with todos or you want another way of doing it? |
For optional parameters, it is often best to just require their presence. It is a judgement call on a case-to-case basis though. |
I removed the TODO, don't know if I should leave the |
I wanted to open this PR as well as ask some questions. Not sure how the whole binding works, but I do know some stuff currently are not supported as the optional parameters( as well as
NaN
support). But I also wanted to raise the question:What about all the special cases for specific handling?
, for example I can givesubstr
:How can these cases be handled as a whole and what should we do about them until we can actually handle them?