ErrorConstructor.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Jint.Native.Function;
  2. using Jint.Native.Object;
  3. using Jint.Runtime;
  4. namespace Jint.Native.Error
  5. {
  6. public sealed class ErrorConstructor : FunctionInstance, IConstructor
  7. {
  8. public ErrorConstructor(Engine engine) : base(engine, null, null, false)
  9. {
  10. }
  11. public static ErrorConstructor CreateErrorConstructor(Engine engine, string name)
  12. {
  13. var obj = new ErrorConstructor(engine);
  14. obj.Extensible = true;
  15. // The value of the [[Prototype]] internal property of the Error constructor is the Function prototype object
  16. obj.Prototype = engine.Function.PrototypeObject;
  17. obj.PrototypeObject = ErrorPrototype.CreatePrototypeObject(engine, obj, name);
  18. obj.FastAddProperty("length", 1, false, false, false);
  19. // The initial value of Date.prototype is the Boolean prototype object
  20. obj.FastAddProperty("prototype", obj.PrototypeObject, false, false, false);
  21. return obj;
  22. }
  23. public void Configure()
  24. {
  25. }
  26. public override object Call(object thisObject, object[] arguments)
  27. {
  28. return Construct(arguments);
  29. }
  30. public ObjectInstance Construct(object[] arguments)
  31. {
  32. var instance = new ErrorInstance(Engine, null);
  33. instance.Prototype = PrototypeObject;
  34. instance.Extensible = true;
  35. if (arguments.Length > 0 && arguments[0] != Undefined.Instance)
  36. {
  37. instance.Message = TypeConverter.ToString(arguments[0]);
  38. }
  39. return instance;
  40. }
  41. public ErrorPrototype PrototypeObject { get; private set; }
  42. }
  43. }