|
@@ -11,7 +11,7 @@ using Jint.Runtime.Interop;
|
|
|
|
|
|
namespace Jint.Native.Map;
|
|
|
|
|
|
-internal sealed class MapConstructor : Constructor
|
|
|
+public sealed class MapConstructor : Constructor
|
|
|
{
|
|
|
private static readonly JsString _functionName = new("Map");
|
|
|
|
|
@@ -33,28 +33,34 @@ internal sealed class MapConstructor : Constructor
|
|
|
protected override void Initialize()
|
|
|
{
|
|
|
const PropertyFlag PropertyFlags = PropertyFlag.Writable | PropertyFlag.Configurable;
|
|
|
- var properties = new PropertyDictionary(1, checkExistingKeys: false)
|
|
|
- {
|
|
|
- ["groupBy"] = new(new ClrFunction(Engine, "groupBy", GroupBy, 2, PropertyFlag.Configurable), PropertyFlags),
|
|
|
- };
|
|
|
+ var properties = new PropertyDictionary(1, checkExistingKeys: false) { ["groupBy"] = new(new ClrFunction(Engine, "groupBy", GroupBy, 2, PropertyFlag.Configurable), PropertyFlags), };
|
|
|
SetProperties(properties);
|
|
|
|
|
|
- var symbols = new SymbolDictionary(1)
|
|
|
- {
|
|
|
- [GlobalSymbolRegistry.Species] = new GetSetPropertyDescriptor(get: new ClrFunction(_engine, "get [Symbol.species]", Species, 0, PropertyFlag.Configurable), set: Undefined, PropertyFlag.Configurable)
|
|
|
- };
|
|
|
+ var symbols = new SymbolDictionary(1) { [GlobalSymbolRegistry.Species] = new GetSetPropertyDescriptor(get: new ClrFunction(_engine, "get [Symbol.species]", Species, 0, PropertyFlag.Configurable), set: Undefined, PropertyFlag.Configurable) };
|
|
|
SetSymbols(symbols);
|
|
|
}
|
|
|
|
|
|
- private static JsValue Species(JsValue thisObject, JsValue[] arguments)
|
|
|
- {
|
|
|
- return thisObject;
|
|
|
- }
|
|
|
+ public JsMap Construct() => ConstructMap(this);
|
|
|
|
|
|
/// <summary>
|
|
|
/// https://tc39.es/ecma262/#sec-map-iterable
|
|
|
/// </summary>
|
|
|
public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget)
|
|
|
+ {
|
|
|
+ var map = ConstructMap(newTarget);
|
|
|
+
|
|
|
+ if (arguments.Length > 0 && !arguments[0].IsNullOrUndefined())
|
|
|
+ {
|
|
|
+ var adder = ((ObjectInstance) map).Get("set");
|
|
|
+ var iterator = arguments.At(0).GetIterator(_realm);
|
|
|
+
|
|
|
+ IteratorProtocol.AddEntriesFromIterable(map, iterator, adder);
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JsMap ConstructMap(JsValue newTarget)
|
|
|
{
|
|
|
if (newTarget.IsUndefined())
|
|
|
{
|
|
@@ -66,14 +72,6 @@ internal sealed class MapConstructor : Constructor
|
|
|
static intrinsics => intrinsics.Map.PrototypeObject,
|
|
|
static (Engine engine, Realm realm, object? _) => new JsMap(engine, realm));
|
|
|
|
|
|
- if (arguments.Length > 0 && !arguments[0].IsNullOrUndefined())
|
|
|
- {
|
|
|
- var adder = map.Get("set");
|
|
|
- var iterator = arguments.At(0).GetIterator(_realm);
|
|
|
-
|
|
|
- IteratorProtocol.AddEntriesFromIterable(map, iterator, adder);
|
|
|
- }
|
|
|
-
|
|
|
return map;
|
|
|
}
|
|
|
|
|
@@ -89,9 +87,14 @@ internal sealed class MapConstructor : Constructor
|
|
|
var map = (JsMap) Construct(_realm.Intrinsics.Map);
|
|
|
foreach (var pair in grouping)
|
|
|
{
|
|
|
- map.MapSet(pair.Key, pair.Value);
|
|
|
+ map.Set(pair.Key, pair.Value);
|
|
|
}
|
|
|
|
|
|
return map;
|
|
|
}
|
|
|
+
|
|
|
+ private static JsValue Species(JsValue thisObject, JsValue[] arguments)
|
|
|
+ {
|
|
|
+ return thisObject;
|
|
|
+ }
|
|
|
}
|