-
-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update test262 test suite and fix issues (#1589)
* Array.group and Array.groupToMap are now Object.groupBy and Map.groupBy * add new feature flags to ignore until implementation
- Loading branch information
Showing
9 changed files
with
163 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Jint.Native.Array; | ||
using Jint.Native.Iterator; | ||
using Jint.Runtime; | ||
|
||
namespace Jint.Native; | ||
|
||
internal static class GroupByHelper | ||
{ | ||
internal static Dictionary<JsValue, JsArray> GroupBy( | ||
Engine engine, | ||
Realm realm, | ||
JsValue items, | ||
JsValue callbackfn, | ||
bool mapMode) | ||
{ | ||
var callable = callbackfn.GetCallable(realm); | ||
var groups = new Dictionary<JsValue, JsArray>(); | ||
var iteratorRecord = items.GetIterator(realm); | ||
new GroupByProtocol(engine, groups, iteratorRecord, callable, mapMode).Execute(); | ||
return groups; | ||
} | ||
|
||
private sealed class GroupByProtocol : IteratorProtocol | ||
{ | ||
private readonly Engine _engine; | ||
private readonly Dictionary<JsValue, JsArray> _result; | ||
private readonly ICallable _callable; | ||
private readonly bool _mapMode; | ||
private ulong _k; | ||
private readonly JsValue[] _callArgs = new JsValue[2]; | ||
|
||
public GroupByProtocol( | ||
Engine engine, | ||
Dictionary<JsValue, JsArray> result, | ||
IteratorInstance iterator, | ||
ICallable callable, | ||
bool mapMode) : base(engine, iterator, 0) | ||
{ | ||
_engine = engine; | ||
_result = result; | ||
_callable = callable; | ||
_mapMode = mapMode; | ||
} | ||
|
||
protected override void ProcessItem(JsValue[] args, JsValue currentValue) | ||
{ | ||
if (_k >= ArrayOperations.MaxArrayLength) | ||
{ | ||
ExceptionHelper.ThrowTypeError(_engine.Realm); | ||
} | ||
|
||
_callArgs[0] = currentValue; | ||
_callArgs[1] = _k; | ||
|
||
var value = _callable.Call(JsValue.Undefined, _callArgs); | ||
JsValue key; | ||
if (_mapMode) | ||
{ | ||
key = (value as JsNumber)?.IsNegativeZero() == true ? JsNumber.PositiveZero : value; | ||
} | ||
else | ||
{ | ||
key = TypeConverter.ToPropertyKey(value); | ||
} | ||
|
||
if (!_result.TryGetValue(key, out var list)) | ||
{ | ||
_result[key] = list = new JsArray(_engine); | ||
} | ||
|
||
list.Push(currentValue); | ||
_k++; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters