-
-
Notifications
You must be signed in to change notification settings - Fork 407
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 RegExp.prototype [ @@search ] ( string ) #1314
Conversation
Test262 conformance changes:
Fixed tests:
|
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.
A few mistakes and a few details related to JS.
* RegExp.prototype [ @@search ] ( string ) * String.prototype.search ( regexp )
* RegExp.prototype [ @@search ] ( string ) * String.prototype.search ( regexp )
@RageKnify Thanks for the review and the great explanations! I fixed all the things you mentioned. I refactored the code to include the spec as comments. Please let me know if that is desired in this codebase. Further I added some very basic tests, but I'm not sure if this is required, as the full 262 test suite should cover everything? |
Test262 results look very good now! 54 fixed tests :) Using the spec as comments in the code is a good idea, that makes everything easier to follow. I think it's also good to have built-in tests. These will be executed faster, so it's easier to check for regressions. Having basic tests (or internal implementation tests) is good from my side. I will review the code during the weekend. |
boa/src/builtins/regexp/mod.rs
Outdated
pub(crate) fn search(this: &Value, args: &[Value], context: &mut Context) -> Result<Value> { | ||
// 1. Let rx be the this value. | ||
// 2. If Type(rx) is not Object, throw a TypeError exception. | ||
if let Some(object) = this.as_object() { |
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.
If you want to avoid indenting the rest of the function you can use match
to either unwrap or early return, something like this:
let object = match this.as_object() {
Some(object) => object,
None => return context.throw_type_error("RegExp.prototype.search method called on incompatible value"),
}
ref: https://doc.rust-lang.org/rust-by-example/error/result/early_returns.html
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.
You can also use if !this.is_object()
and then expect()
on the as_object()
.
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.
2 more touch-ups, if you want you can also change to a match
like @LinusU proposed.
It seems that this requires running |
* Add some more rust tests from the 262 suite
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 good to me :) thanks!
This Pull Request implements part of #1304 .
It changes the following:
ECMASCript Test262 test suite results: