PluralRulesConstructor.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Jint.Native.Function;
  2. using Jint.Native.Object;
  3. using Jint.Runtime;
  4. using Jint.Runtime.Descriptors;
  5. namespace Jint.Native.Intl;
  6. /// <summary>
  7. /// https://tc39.es/ecma402/#sec-intl-pluralrules-constructor
  8. /// </summary>
  9. internal sealed class PluralRulesConstructor : Constructor
  10. {
  11. private static readonly JsString _functionName = new("PluralRules");
  12. public PluralRulesConstructor(
  13. Engine engine,
  14. Realm realm,
  15. FunctionPrototype functionPrototype,
  16. ObjectPrototype objectPrototype) : base(engine, realm, _functionName)
  17. {
  18. _prototype = functionPrototype;
  19. PrototypeObject = new PluralRulesPrototype(engine, realm, this, objectPrototype);
  20. _length = new PropertyDescriptor(JsNumber.PositiveZero, PropertyFlag.Configurable);
  21. _prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden);
  22. }
  23. public PluralRulesPrototype PrototypeObject { get; }
  24. public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget)
  25. {
  26. var locales = arguments.At(0);
  27. var options = arguments.At(1);
  28. if (newTarget.IsUndefined())
  29. {
  30. newTarget = this;
  31. }
  32. var pluralRules = OrdinaryCreateFromConstructor<JsObject, object>(
  33. newTarget,
  34. static intrinsics => intrinsics.PluralRules.PrototypeObject,
  35. static (engine, _, _) => new JsObject(engine));
  36. InitializePluralRules(pluralRules, locales, options);
  37. return pluralRules;
  38. }
  39. /// <summary>
  40. /// https://tc39.es/ecma402/#sec-initializepluralrules
  41. /// </summary>
  42. private static void InitializePluralRules(JsObject pluralRules, JsValue locales, JsValue options)
  43. {
  44. // TODO
  45. }
  46. }