feat(engine): implement Iterator.prototype.join proposal - #5503
Conversation
Test262 conformance changes
Fixed tests (18):Tested main commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5503 +/- ##
===========================================
+ Coverage 47.24% 62.94% +15.69%
===========================================
Files 476 536 +60
Lines 46892 60286 +13394
===========================================
+ Hits 22154 37945 +15791
+ Misses 24738 22341 -2397 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jedel1043
left a comment
There was a problem hiding this comment.
Thank you for the contribution! Implementation wise looks great, I just have a small suggestion to simplify a bit of code.
| // 6. Let R be the empty String. | ||
| // 7. Let first be true. | ||
| let mut r = Vec::new(); | ||
| let mut first = true; | ||
|
|
||
| // 8. Repeat, | ||
| while let Some(value) = iterated.step_value(context)? { | ||
| // a. Let value be ? IteratorStepValue(iterated). | ||
| // b. If value is done, return R. | ||
| // c. If first is true, set first to false. | ||
| // d. Else, set R to the string-concatenation of R and sep. | ||
| if first { | ||
| first = false; | ||
| } else { | ||
| r.push(sep.clone()); | ||
| } | ||
|
|
||
| // e. If value is neither undefined nor null, then | ||
| if !value.is_null_or_undefined() { | ||
| // i. Let S be Completion(ToString(value)). | ||
| // ii. ? IfAbruptCloseIterator(S, iterated). | ||
| // iii. Set R to the string-concatenation of R and S. | ||
| let s = value.to_string(context); | ||
| let s = if_abrupt_close_iterator!(s, iterated, context); | ||
| r.push(s); | ||
| } | ||
| } | ||
|
|
||
| // 9. Return R. | ||
| if r.is_empty() { | ||
| return Ok(js_string!().into()); | ||
| } | ||
|
|
||
| let strs: Vec<_> = r.iter().map(crate::JsString::as_str).collect(); |
There was a problem hiding this comment.
This might be a good place to start using our new CommonJsStringBuilder API, which is nice for building JsStrings in a nicer way.
There was a problem hiding this comment.
Thanks for the review @jedel1043! I've updated the implementation to use CommonJsStringBuilder as suggested.
This Pull Request implements the Stage 3 TC39 proposal
Iterator.prototype.join.It changes the following:
%IteratorPrototype%.join(separator)under theexperimentalfeature flag incore/engine/src/builtins/iterable/iterator_prototype.rs.TypeErrorotherwise).separatorto a String before accessing the iterator'snextmethod.IfAbruptCloseIteratorif separator coercion or element string conversion fails.nullandundefinedelements as empty strings.core/engine/src/builtins/iterable/tests.rs."Iterator.prototype.join"from the ignored list intest262_config.toml.test/built-ins/Iterator/prototype/join/now pass (100% Conformance).