IntlInstance.cs 2.1 KB

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