|
@@ -5,80 +5,79 @@ using Jint.Runtime;
|
|
using Jint.Runtime.Descriptors;
|
|
using Jint.Runtime.Descriptors;
|
|
using Jint.Runtime.Interop;
|
|
using Jint.Runtime.Interop;
|
|
|
|
|
|
-namespace Jint.Native.WeakMap
|
|
|
|
|
|
+namespace Jint.Native.WeakMap;
|
|
|
|
+
|
|
|
|
+/// <summary>
|
|
|
|
+/// https://tc39.es/ecma262/#sec-weakmap-objects
|
|
|
|
+/// </summary>
|
|
|
|
+internal sealed class WeakMapPrototype : Prototype
|
|
{
|
|
{
|
|
- /// <summary>
|
|
|
|
- /// https://tc39.es/ecma262/#sec-weakmap-objects
|
|
|
|
- /// </summary>
|
|
|
|
- internal sealed class WeakMapPrototype : Prototype
|
|
|
|
|
|
+ private readonly WeakMapConstructor _constructor;
|
|
|
|
+
|
|
|
|
+ internal WeakMapPrototype(
|
|
|
|
+ Engine engine,
|
|
|
|
+ Realm realm,
|
|
|
|
+ WeakMapConstructor constructor,
|
|
|
|
+ ObjectPrototype prototype) : base(engine, realm)
|
|
{
|
|
{
|
|
- private readonly WeakMapConstructor _constructor;
|
|
|
|
|
|
+ _prototype = prototype;
|
|
|
|
+ _constructor = constructor;
|
|
|
|
+ }
|
|
|
|
|
|
- internal WeakMapPrototype(
|
|
|
|
- Engine engine,
|
|
|
|
- Realm realm,
|
|
|
|
- WeakMapConstructor constructor,
|
|
|
|
- ObjectPrototype prototype) : base(engine, realm)
|
|
|
|
|
|
+ protected override void Initialize()
|
|
|
|
+ {
|
|
|
|
+ const PropertyFlag propertyFlags = PropertyFlag.Configurable | PropertyFlag.Writable;
|
|
|
|
+ var properties = new PropertyDictionary(6, checkExistingKeys: false)
|
|
{
|
|
{
|
|
- _prototype = prototype;
|
|
|
|
- _constructor = constructor;
|
|
|
|
- }
|
|
|
|
|
|
+ ["length"] = new PropertyDescriptor(0, PropertyFlag.Configurable),
|
|
|
|
+ ["constructor"] = new PropertyDescriptor(_constructor, PropertyFlag.NonEnumerable),
|
|
|
|
+ ["delete"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "delete", Delete, 1, PropertyFlag.Configurable), propertyFlags),
|
|
|
|
+ ["get"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "get", Get, 1, PropertyFlag.Configurable), propertyFlags),
|
|
|
|
+ ["has"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "has", Has, 1, PropertyFlag.Configurable), propertyFlags),
|
|
|
|
+ ["set"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "set", Set, 2, PropertyFlag.Configurable), propertyFlags),
|
|
|
|
+ };
|
|
|
|
+ SetProperties(properties);
|
|
|
|
|
|
- protected override void Initialize()
|
|
|
|
|
|
+ var symbols = new SymbolDictionary(1)
|
|
{
|
|
{
|
|
- const PropertyFlag propertyFlags = PropertyFlag.Configurable | PropertyFlag.Writable;
|
|
|
|
- var properties = new PropertyDictionary(6, checkExistingKeys: false)
|
|
|
|
- {
|
|
|
|
- ["length"] = new PropertyDescriptor(0, PropertyFlag.Configurable),
|
|
|
|
- ["constructor"] = new PropertyDescriptor(_constructor, PropertyFlag.NonEnumerable),
|
|
|
|
- ["delete"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "delete", Delete, 1, PropertyFlag.Configurable), propertyFlags),
|
|
|
|
- ["get"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "get", Get, 1, PropertyFlag.Configurable), propertyFlags),
|
|
|
|
- ["has"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "has", Has, 1, PropertyFlag.Configurable), propertyFlags),
|
|
|
|
- ["set"] = new PropertyDescriptor(new ClrFunctionInstance(Engine, "set", Set, 2, PropertyFlag.Configurable), propertyFlags),
|
|
|
|
- };
|
|
|
|
- SetProperties(properties);
|
|
|
|
|
|
+ [GlobalSymbolRegistry.ToStringTag] = new PropertyDescriptor("WeakMap", false, false, true)
|
|
|
|
+ };
|
|
|
|
+ SetSymbols(symbols);
|
|
|
|
+ }
|
|
|
|
|
|
- var symbols = new SymbolDictionary(1)
|
|
|
|
- {
|
|
|
|
- [GlobalSymbolRegistry.ToStringTag] = new PropertyDescriptor("WeakMap", false, false, true)
|
|
|
|
- };
|
|
|
|
- SetSymbols(symbols);
|
|
|
|
- }
|
|
|
|
|
|
+ private JsValue Get(JsValue thisObj, JsValue[] arguments)
|
|
|
|
+ {
|
|
|
|
+ var map = AssertWeakMapInstance(thisObj);
|
|
|
|
+ return map.WeakMapGet(arguments.At(0));
|
|
|
|
+ }
|
|
|
|
|
|
- private JsValue Get(JsValue thisObj, JsValue[] arguments)
|
|
|
|
- {
|
|
|
|
- var map = AssertWeakMapInstance(thisObj);
|
|
|
|
- return map.WeakMapGet(arguments.At(0));
|
|
|
|
- }
|
|
|
|
|
|
+ private JsValue Delete(JsValue thisObj, JsValue[] arguments)
|
|
|
|
+ {
|
|
|
|
+ var map = AssertWeakMapInstance(thisObj);
|
|
|
|
+ return arguments.Length > 0 && map.WeakMapDelete(arguments.At(0)) ? JsBoolean.True : JsBoolean.False;
|
|
|
|
+ }
|
|
|
|
|
|
- private JsValue Delete(JsValue thisObj, JsValue[] arguments)
|
|
|
|
- {
|
|
|
|
- var map = AssertWeakMapInstance(thisObj);
|
|
|
|
- return (arguments.Length > 0 && map.WeakMapDelete(arguments.At(0))) ? JsBoolean.True : JsBoolean.False;
|
|
|
|
- }
|
|
|
|
|
|
+ private JsValue Set(JsValue thisObj, JsValue[] arguments)
|
|
|
|
+ {
|
|
|
|
+ var map = AssertWeakMapInstance(thisObj);
|
|
|
|
+ map.WeakMapSet(arguments.At(0), arguments.At(1));
|
|
|
|
+ return thisObj;
|
|
|
|
+ }
|
|
|
|
|
|
- private JsValue Set(JsValue thisObj, JsValue[] arguments)
|
|
|
|
- {
|
|
|
|
- var map = AssertWeakMapInstance(thisObj);
|
|
|
|
- map.WeakMapSet(arguments.At(0), arguments.At(1));
|
|
|
|
- return thisObj;
|
|
|
|
- }
|
|
|
|
|
|
+ private JsValue Has(JsValue thisObj, JsValue[] arguments)
|
|
|
|
+ {
|
|
|
|
+ var map = AssertWeakMapInstance(thisObj);
|
|
|
|
+ return map.WeakMapHas(arguments.At(0)) ? JsBoolean.True : JsBoolean.False;
|
|
|
|
+ }
|
|
|
|
|
|
- private JsValue Has(JsValue thisObj, JsValue[] arguments)
|
|
|
|
|
|
+ private WeakMapInstance AssertWeakMapInstance(JsValue thisObj)
|
|
|
|
+ {
|
|
|
|
+ var map = thisObj as WeakMapInstance;
|
|
|
|
+ if (map is null)
|
|
{
|
|
{
|
|
- var map = AssertWeakMapInstance(thisObj);
|
|
|
|
- return map.WeakMapHas(arguments.At(0)) ? JsBoolean.True : JsBoolean.False;
|
|
|
|
|
|
+ ExceptionHelper.ThrowTypeError(_realm, "object must be a WeakMap");
|
|
}
|
|
}
|
|
|
|
|
|
- private WeakMapInstance AssertWeakMapInstance(JsValue thisObj)
|
|
|
|
- {
|
|
|
|
- var map = thisObj as WeakMapInstance;
|
|
|
|
- if (map is null)
|
|
|
|
- {
|
|
|
|
- ExceptionHelper.ThrowTypeError(_realm, "object must be a WeakMap");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return map;
|
|
|
|
- }
|
|
|
|
|
|
+ return map;
|
|
}
|
|
}
|
|
}
|
|
}
|