ErrorInstance.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Jint.Native.Object;
  2. using Jint.Runtime;
  3. using Jint.Runtime.Descriptors;
  4. namespace Jint.Native.Error
  5. {
  6. public class ErrorInstance : ObjectInstance
  7. {
  8. private readonly JsString _name;
  9. private PropertyDescriptor _descriptor;
  10. internal ErrorInstance(
  11. Engine engine,
  12. JsString name,
  13. ObjectClass objectClass = ObjectClass.Error)
  14. : base(engine, objectClass)
  15. {
  16. _name = name;
  17. }
  18. public override PropertyDescriptor GetOwnProperty(JsValue property)
  19. {
  20. if (property == CommonProperties.Name)
  21. {
  22. return _descriptor ??= new PropertyDescriptor(_name, PropertyFlag.Configurable | PropertyFlag.Writable);
  23. };
  24. return base.GetOwnProperty(property);
  25. }
  26. public override string ToString()
  27. {
  28. return Engine.Realm.Intrinsics.Error.PrototypeObject.ToString(this, Arguments.Empty).ToObject().ToString();
  29. }
  30. }
  31. }