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 RegExp.prototype [ @@search ] ( string ) #1314

Merged
merged 6 commits into from
Jun 14, 2021

Conversation

raskad
Copy link
Member

@raskad raskad commented Jun 10, 2021

This Pull Request implements part of #1304 .

It changes the following:

  • implement RegExp.prototype [ @@search ] ( string )
  • implement String.prototype.search ( regexp )

ECMASCript Test262 test suite results:

Results:
Total tests: 78897
- Passed tests: 26797
+ Passed tests: 26833
Ignored tests: 15628
- Failed tests: 36472 (panics: 0)
+ Failed tests: 36436 (panics: 0)
- Conformance: 33.96%
+ Conformance: 34.01%

@Razican
Copy link
Member

Razican commented Jun 11, 2021

Test262 conformance changes:

Test result master count PR count difference
Total 78,897 78,897 0
Passed 26,801 26,857 +56
Ignored 15,628 15,628 0
Failed 36,468 36,412 -56
Panics 0 0 0
Conformance 33.97% 34.04% +0.07%
Fixed tests:
test/built-ins/Object/getOwnPropertyDescriptor/15.2.3.3-4-70.js [strict mode] (previously Failed)
test/built-ins/Object/getOwnPropertyDescriptor/15.2.3.3-4-70.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A6.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A6.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A3_T2.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A3_T2.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T7.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T7.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T5.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T5.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A10.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A10.js (previously Failed)
test/built-ins/String/prototype/search/this-value-not-obj-coercible.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/this-value-not-obj-coercible.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T1.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T1.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T6.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T6.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A8.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A8.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T3.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T3.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A9.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A9.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T4.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T4.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A3_T1.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A3_T1.js (previously Failed)
test/built-ins/String/prototype/search/name.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/name.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A11.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A11.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A1_T14.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A1_T14.js (previously Failed)
test/built-ins/String/prototype/search/cstm-search-get-err.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/cstm-search-get-err.js (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T2.js [strict mode] (previously Failed)
test/built-ins/String/prototype/search/S15.5.4.12_A2_T2.js (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/failure-return-val.js [strict mode] (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/failure-return-val.js (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/get-lastindex-err.js [strict mode] (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/get-lastindex-err.js (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/success-return-val.js [strict mode] (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/success-return-val.js (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/u-lastindex-advance.js [strict mode] (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/u-lastindex-advance.js (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/name.js [strict mode] (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/name.js (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/prop-desc.js [strict mode] (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/prop-desc.js (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/length.js [strict mode] (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/length.js (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/coerce-string-err.js [strict mode] (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/coerce-string-err.js (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/coerce-string.js [strict mode] (previously Failed)
test/built-ins/RegExp/prototype/Symbol.search/coerce-string.js (previously Failed)

Copy link
Contributor

@RageKnify RageKnify left a 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.

boa/src/builtins/regexp/mod.rs Show resolved Hide resolved
boa/src/builtins/regexp/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/string/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/string/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/regexp/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/string/mod.rs Outdated Show resolved Hide resolved
raskad added 2 commits June 12, 2021 02:10
* RegExp.prototype [ @@search ] ( string )
* String.prototype.search ( regexp )
* RegExp.prototype [ @@search ] ( string )
* String.prototype.search ( regexp )
@raskad
Copy link
Member Author

raskad commented Jun 12, 2021

@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?

@raskad raskad requested a review from RageKnify June 12, 2021 00:30
@Razican
Copy link
Member

Razican commented Jun 12, 2021

@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.

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() {
Copy link

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

Copy link
Member

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().

Copy link
Contributor

@RageKnify RageKnify left a 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.

boa/src/builtins/regexp/mod.rs Show resolved Hide resolved
boa/src/builtins/regexp/mod.rs Outdated Show resolved Hide resolved
@Razican Razican added this to the v0.13.0 milestone Jun 14, 2021
@Razican Razican added enhancement New feature or request builtins PRs and Issues related to builtins/intrinsics labels Jun 14, 2021
@raskad raskad requested a review from RageKnify June 14, 2021 15:07
@Razican
Copy link
Member

Razican commented Jun 14, 2021

It seems that this requires running cargo fmt, since the format tests are not passing.

* Add some more rust tests from the 262 suite
Copy link
Member

@Razican Razican left a 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!

@Razican Razican merged commit fc3fbe2 into boa-dev:master Jun 14, 2021
@raskad raskad deleted the regexp-search branch August 14, 2021 00:32
@raskad raskad mentioned this pull request Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants