IntlInstance.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma warning disable CA1859 // Use concrete types when possible for improved performance -- most of prototype methods return JsValue
  2. using Jint.Collections;
  3. using Jint.Native.Object;
  4. using Jint.Native.Symbol;
  5. using Jint.Runtime;
  6. using Jint.Runtime.Descriptors;
  7. using Jint.Runtime.Interop;
  8. namespace Jint.Native.Intl;
  9. /// <summary>
  10. /// https://tc39.es/ecma402/#intl-object
  11. /// </summary>
  12. internal sealed class IntlInstance : ObjectInstance
  13. {
  14. private readonly Realm _realm;
  15. internal IntlInstance(
  16. Engine engine,
  17. Realm realm,
  18. ObjectPrototype objectPrototype) : base(engine)
  19. {
  20. _realm = realm;
  21. _prototype = objectPrototype;
  22. }
  23. protected override void Initialize()
  24. {
  25. // TODO check length
  26. var properties = new PropertyDictionary(10, checkExistingKeys: false)
  27. {
  28. ["Collator"] = new(_realm.Intrinsics.Collator, false, false, true),
  29. ["DateTimeFormat"] = new(_realm.Intrinsics.DateTimeFormat, false, false, true),
  30. ["DisplayNames"] = new(_realm.Intrinsics.DisplayNames, false, false, true),
  31. ["ListFormat"] = new(_realm.Intrinsics.ListFormat, false, false, true),
  32. ["Locale"] = new(_realm.Intrinsics.Locale, false, false, true),
  33. ["NumberFormat"] = new(_realm.Intrinsics.NumberFormat, false, false, true),
  34. ["PluralRules"] = new(_realm.Intrinsics.PluralRules, false, false, true),
  35. ["RelativeTimeFormat"] = new(_realm.Intrinsics.RelativeTimeFormat, false, false, true),
  36. ["Segmenter"] = new(_realm.Intrinsics.Segmenter, false, false, true),
  37. ["getCanonicalLocales "] = new(new ClrFunction(Engine, "getCanonicalLocales ", GetCanonicalLocales , 1, PropertyFlag.Configurable), true, false, true),
  38. };
  39. SetProperties(properties);
  40. var symbols = new SymbolDictionary(1)
  41. {
  42. [GlobalSymbolRegistry.ToStringTag] = new("Intl", PropertyFlag.Configurable)
  43. };
  44. SetSymbols(symbols);
  45. }
  46. private JsValue GetCanonicalLocales(JsValue thisObject, JsValue[] arguments)
  47. {
  48. return new JsArray(_engine);
  49. }
  50. }